forked from faasm/faabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asio+Beast-based endpoint server (faasm#274)
* Update dependency versions * boost::beast and asio-based asynchronous endpoint implementation * Address review comments * Remove Pistache as it is no longer used * Fix TSan-detected data races in distributed tests * Turn off MPI all-to-all disttests, see <faasm#275> * Run clang-format-13
- Loading branch information
1 parent
be18960
commit d686b8e
Showing
18 changed files
with
653 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,66 @@ | ||
#pragma once | ||
|
||
#include <pistache/endpoint.h> | ||
#include <pistache/http.h> | ||
#include <functional> | ||
#include <memory> | ||
|
||
#include <faabric/proto/faabric.pb.h> | ||
#include <faabric/util/asio.h> | ||
#include <faabric/util/config.h> | ||
|
||
namespace faabric::endpoint { | ||
|
||
enum EndpointMode | ||
enum class EndpointMode | ||
{ | ||
SIGNAL, | ||
BG_THREAD | ||
}; | ||
|
||
namespace detail { | ||
struct EndpointState; | ||
} | ||
|
||
struct HttpRequestContext | ||
{ | ||
asio::io_context& ioc; | ||
asio::any_io_executor executor; | ||
std::function<void(faabric::util::BeastHttpResponse&&)> sendFunction; | ||
}; | ||
|
||
class HttpRequestHandler | ||
{ | ||
public: | ||
virtual void onRequest(HttpRequestContext&& ctx, | ||
faabric::util::BeastHttpRequest&& request) = 0; | ||
}; | ||
|
||
class FaabricEndpoint | ||
{ | ||
public: | ||
FaabricEndpoint(); | ||
|
||
FaabricEndpoint(int portIn, int threadCountIn); | ||
FaabricEndpoint( | ||
int port, | ||
int threadCount, | ||
std::shared_ptr<HttpRequestHandler> requestHandlerIn = nullptr); | ||
|
||
void start(EndpointMode mode); | ||
FaabricEndpoint(const FaabricEndpoint&) = delete; | ||
|
||
void stop(); | ||
FaabricEndpoint(FaabricEndpoint&&) = delete; | ||
|
||
private: | ||
int port = faabric::util::getSystemConfig().endpointPort; | ||
int threadCount = faabric::util::getSystemConfig().endpointNumThreads; | ||
FaabricEndpoint& operator=(const FaabricEndpoint&) = delete; | ||
|
||
FaabricEndpoint& operator=(FaabricEndpoint&&) = delete; | ||
|
||
Pistache::Http::Endpoint httpEndpoint; | ||
virtual ~FaabricEndpoint(); | ||
|
||
std::mutex mx; | ||
void start(EndpointMode mode = EndpointMode::SIGNAL); | ||
|
||
void runEndpoint(); | ||
void stop(); | ||
|
||
private: | ||
int port; | ||
int threadCount; | ||
std::unique_ptr<detail::EndpointState> state; | ||
std::shared_ptr<HttpRequestHandler> requestHandler; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
#pragma once | ||
|
||
#include <faabric/endpoint/FaabricEndpoint.h> | ||
#include <faabric/proto/faabric.pb.h> | ||
#include <pistache/http.h> | ||
|
||
namespace faabric::endpoint { | ||
class FaabricEndpointHandler : public Pistache::Http::Handler | ||
class FaabricEndpointHandler final | ||
: public HttpRequestHandler | ||
, public std::enable_shared_from_this<FaabricEndpointHandler> | ||
{ | ||
public: | ||
HTTP_PROTOTYPE(FaabricEndpointHandler) | ||
|
||
void onTimeout(const Pistache::Http::Request& request, | ||
Pistache::Http::ResponseWriter writer) override; | ||
|
||
void onRequest(const Pistache::Http::Request& request, | ||
Pistache::Http::ResponseWriter response) override; | ||
|
||
std::pair<int, std::string> handleFunction(const std::string& requestStr); | ||
void onRequest(HttpRequestContext&& ctx, | ||
faabric::util::BeastHttpRequest&& request) override; | ||
|
||
private: | ||
std::pair<int, std::string> executeFunction(faabric::Message& msg); | ||
void executeFunction(HttpRequestContext&& ctx, | ||
faabric::util::BeastHttpResponse&& partialResponse, | ||
std::shared_ptr<faabric::BatchExecuteRequest> ber, | ||
size_t messageIndex); | ||
|
||
void onFunctionResult(HttpRequestContext&& ctx, | ||
faabric::util::BeastHttpResponse&& partialResponse, | ||
faabric::Message& msg); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <boost/asio.hpp> | ||
#include <boost/beast/core.hpp> | ||
#include <boost/beast/http.hpp> | ||
#include <boost/beast/version.hpp> | ||
|
||
namespace asio = boost::asio; | ||
namespace beast = boost::beast; | ||
|
||
namespace faabric::util { | ||
using BeastHttpRequest = beast::http::request<beast::http::string_body>; | ||
using BeastHttpResponse = beast::http::response<beast::http::string_body>; | ||
} |
Oops, something went wrong.