Skip to content

Commit

Permalink
[control-plane] Support process resource definitions in FaaS invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Oct 21, 2024
1 parent 68a8ec1 commit 8189776
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion control-plane/include/praas/control-plane/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ namespace praas::control_plane::worker {
void handle_invocation(
HttpServer::request_t request, HttpServer::callback_t&& callback, const std::string& app_id,
std::string function_name, std::chrono::high_resolution_clock::time_point start,
std::optional<std::string> process_name
std::optional<std::string> process_name,
std::optional<std::string> vcpus,
std::optional<std::string> memory
);

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions control-plane/src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ namespace praas::control_plane::backend {
req.SetNetworkInterfaceIds({eni_interface});

_ec2_client->DescribeNetworkInterfacesAsync(
req,
[this](auto* ptr, auto res, auto outcome, auto& context) mutable {
_callback_describe_eni(ptr, res, outcome, context);
},
nullptr,
req
nullptr
);
}

Expand Down
2 changes: 1 addition & 1 deletion control-plane/src/downscaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace praas::control_plane::downscaler {

auto lock = ptr->read_lock();
auto name = ptr->name();
_process_list[name] = ProcessStats{std::move(ptr), now_timestamp};
_process_list[name] = ProcessStats{std::move(ptr), static_cast<uint64_t>(now_timestamp)};

} else {
auto lock = ptr->read_lock();
Expand Down
9 changes: 7 additions & 2 deletions control-plane/src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,17 @@ namespace praas::control_plane {
)
{
std::string pid = request->getParameter("process_name");
std::string vcpus_str = request->getParameter("vcpus");
std::string memory_str = request->getParameter("memory");

_logger->info("Push new invocation request of {}", function_name);
_logger->info("Push new invocation request of {}, vcpus {}, memory {}", function_name, vcpus_str, memory_str);
auto start = std::chrono::high_resolution_clock::now();
_workers.add_task(
&worker::Workers::handle_invocation, request, std::move(callback), app_name, function_name,
start, !pid.empty() ? std::make_optional<std::string>(pid) : std::nullopt
start,
!pid.empty() ? std::make_optional<std::string>(pid) : std::nullopt,
!vcpus_str.empty() ? std::make_optional<std::string>(vcpus_str) : std::nullopt,
!memory_str.empty() ? std::make_optional<std::string>(memory_str) : std::nullopt
);
}

Expand Down
11 changes: 9 additions & 2 deletions control-plane/src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace praas::control_plane::worker {
void Workers::handle_invocation(
HttpServer::request_t request, HttpServer::callback_t&& callback, const std::string& app_id,
std::string function_name, std::chrono::high_resolution_clock::time_point start,
std::optional<std::string> process_name
std::optional<std::string> process_name,
std::optional<std::string> vcpus,
std::optional<std::string> memory
)
{
Resources::RWAccessor acc;
Expand Down Expand Up @@ -91,7 +93,12 @@ namespace praas::control_plane::worker {
// Get a process or allocate one.
// FIXME: make resources configurable
acc.get()->get_controlplane_process(
_backend, *_server, process::Resources{"1", "2048", ""},
_backend, *_server,
process::Resources{
!vcpus.has_value() ? "1024" : vcpus.value(),
!memory.has_value() ? "2048" : memory.value(),
""
},
[start, function_name, request = std::move(request), callback = std::move(callback)](
process::ProcessPtr proc_ptr, const std::optional<std::string>& error_msg
) mutable {
Expand Down

0 comments on commit 8189776

Please sign in to comment.