diff --git a/spark_client.sln b/spark_client.sln new file mode 100644 index 000000000..196f9f673 --- /dev/null +++ b/spark_client.sln @@ -0,0 +1,134 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.10 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api", "src\client\spark_api\spark_api.csproj", "{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spark_lib", "build\src\lib\spark_lib.vcxproj", "{9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark", "src\client\spark\Spark.csproj", "{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sparkcmd", "src\client\sparkcmd\sparkcmd.csproj", "{387566C6-C6F6-412C-A30C-9855BBCB4816}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_core", "src\client\spark_core\spark_core.csproj", "{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + MinSizeRel|Any CPU = MinSizeRel|Any CPU + MinSizeRel|x64 = MinSizeRel|x64 + MinSizeRel|x86 = MinSizeRel|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + RelWithDebInfo|Any CPU = RelWithDebInfo|Any CPU + RelWithDebInfo|x64 = RelWithDebInfo|x64 + RelWithDebInfo|x86 = RelWithDebInfo|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|Any CPU.ActiveCfg = Debug|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.ActiveCfg = Debug|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.Build.0 = Debug|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x86.ActiveCfg = Debug|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|Any CPU.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|Any CPU.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x86.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x86.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|Any CPU.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x86.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.Build.0 = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x86.ActiveCfg = Release|x64 + {DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x86.Build.0 = Release|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|Any CPU.ActiveCfg = Debug|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x64.ActiveCfg = Debug|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x64.Build.0 = Debug|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Debug|x86.ActiveCfg = Debug|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|Any CPU.ActiveCfg = Release|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x64.ActiveCfg = Release|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x64.Build.0 = Release|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.Release|x86.ActiveCfg = Release|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {9186D3A8-1C5C-372A-A4EE-E1045BCCB0C7}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|Any CPU.ActiveCfg = Debug|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.ActiveCfg = Debug|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.Build.0 = Debug|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x86.ActiveCfg = Debug|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|Any CPU.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|Any CPU.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x86.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x86.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|Any CPU.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x86.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.Build.0 = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x86.ActiveCfg = Release|x64 + {9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x86.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|Any CPU.ActiveCfg = Debug|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.ActiveCfg = Debug|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.Build.0 = Debug|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x86.ActiveCfg = Debug|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|Any CPU.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|Any CPU.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x86.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x86.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|Any CPU.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x86.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.Build.0 = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x86.ActiveCfg = Release|x64 + {387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x86.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.ActiveCfg = Debug|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.Build.0 = Debug|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x86.ActiveCfg = Debug|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|Any CPU.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|Any CPU.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x86.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x86.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|Any CPU.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x86.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.Build.0 = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x86.ActiveCfg = Release|x64 + {6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x86.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {422D1620-0166-4C26-9A81-CA8A2EB1AB58} + EndGlobalSection +EndGlobal diff --git a/src/client/spark_api/spark_api.csproj b/src/client/spark_api/spark_api.csproj index 34cc96467..bc9dc5ea1 100644 --- a/src/client/spark_api/spark_api.csproj +++ b/src/client/spark_api/spark_api.csproj @@ -21,6 +21,7 @@ + diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index b28532f2f..9139cddda 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -36,6 +36,7 @@ set (Service_Protos api/services/MarketDataService.proto api/services/PersistenceService.proto api/services/UserService.proto + api/services/MarketDataRelay.proto ) include(${CMAKE_SOURCE_DIR}/tools/Protobuf.cmake) diff --git a/src/lib/api/service_compiler/templates/cpp/client.pb.cc b/src/lib/api/service_compiler/templates/cpp/client.pb.cc index 54ea943f1..eb2775557 100644 --- a/src/lib/api/service_compiler/templates/cpp/client.pb.cc +++ b/src/lib/api/service_compiler/templates/cpp/client.pb.cc @@ -44,15 +44,15 @@ using namespace rxcpp::operators; {{else}} - void {{../name}}::{{name}}(const {{input_type}}& input, std::function)> callback, uint32_t timeout_ms) { + void {{../name}}::{{name}}(const {{input_type}}& input, std::function)> callback, uint32_t timeout_ms) { _pchannel->send({{@index}}, input, callback); } - Result<{{output_type}}> {{../name}}::{{name}}(const {{input_type}}& input, uint32_t timeout_ms) { + bts::api::Result<{{output_type}}> {{../name}}::{{name}}(const {{input_type}}& input, uint32_t timeout_ms) { if (_pchannel->is_sync_call_ok()) { - std::promise> p; + std::promise> p; auto future = p.get_future(); - {{name}}(input, [&](Result<{{output_type}}> res) { + {{name}}(input, [&](bts::api::Result<{{output_type}}> res) { p.set_value(res); }, timeout_ms); future.wait(); diff --git a/src/lib/api/service_compiler/templates/cpp/server.pb.cc b/src/lib/api/service_compiler/templates/cpp/server.pb.cc index 0aedfdd8e..2064f9e7c 100644 --- a/src/lib/api/service_compiler/templates/cpp/server.pb.cc +++ b/src/lib/api/service_compiler/templates/cpp/server.pb.cc @@ -47,7 +47,7 @@ void {{name}}Base::dispatch(const bts::api::RequestHeader& header, google::proto default: { bts::api::ResponseHeader response; response.set_request_id(header.request_id()); - response.set_code(ApiError::MISSING_METHOD); + response.set_code(bts::api::ApiError::MISSING_METHOD); uint8_t buffer[64]; int header_size = response.ByteSize() + 1; serialize(header_size, response, buffer); diff --git a/src/lib/api/services/MarketDataRelay.proto b/src/lib/api/services/MarketDataRelay.proto new file mode 100644 index 000000000..49b596f16 --- /dev/null +++ b/src/lib/api/services/MarketDataRelay.proto @@ -0,0 +1,9 @@ +syntax="proto3"; +package bts.co2; +import "lib/api/apioptions.proto"; +import "lib/md/protos/co2.proto"; + +service MarketDataRelay { + option (bts.api.service_description)="Poll the market data service for updates"; + rpc requestmd(bts.co2.MDRequest) returns (bts.co2.MDReply); +} \ No newline at end of file diff --git a/src/lib/api/services/MarketDataService.proto b/src/lib/api/services/MarketDataService.proto index 32650799c..4fb2dd96e 100644 --- a/src/lib/api/services/MarketDataService.proto +++ b/src/lib/api/services/MarketDataService.proto @@ -104,4 +104,4 @@ message SecurityRequest { } service MarketDataService { rpc securities(SecurityRequest) returns (stream Security); -} \ No newline at end of file +} diff --git a/src/lib/md/MDConsumerInterop.cpp b/src/lib/md/MDConsumerInterop.cpp index e760873c5..540039400 100644 --- a/src/lib/md/MDConsumerInterop.cpp +++ b/src/lib/md/MDConsumerInterop.cpp @@ -162,11 +162,11 @@ CAPI void add_relay_symbol(md::RelayControl* prelay, BlitUserSymbol& symbol, uin get_system_md_symbols(channel.exchange(), channel.type(), system_symbols); for (const auto& sym : system_symbols) { channel.set_symbol(sym.symbol()); - md::add_relay_symbol(prelay, channel); + //md::add_relay_symbol(prelay, channel); } } else { - md::add_relay_symbol(prelay, channel); + //md::add_relay_symbol(prelay, channel); } } diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index 46e32360a..e30487fc3 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -12,8 +12,11 @@ #include "lib/config/protos/system.pb.h" #include "lib/md/protos/co2.pb.h" +#include "lib/api/services/MarketDataRelay.server.pb.h" +#include "lib/api/public/ServiceContext.h" #include +#include #include #include #include @@ -172,8 +175,8 @@ void copy_misc(MiscData misc, co2::MiscMessage* pmisc) { } // Handles market data queries and responds -struct QueryServer : public IQueryServer { - QueryServer(const std::set& symbols) : +struct QueryServerImpl : public IQueryServer { + QueryServerImpl(const std::set& symbols) : groups(form_groups(symbols)) { } @@ -322,61 +325,75 @@ private: Map groups; }; -/// In the future this might be replaced by a Service -// struct PubSubRpcServer : public pubsub::RPCHandler -// { -// const QueryServer& _db; -// utils::Dispatcher& _threadpool; -// PubSubRpcServer(const QueryServer& db, pubsub::PubsubHub& hub, utils::Dispatcher& threadpool) : -// pubsub::RPCHandler(hub, "/md/rpc"), -// _db(db), -// _threadpool(threadpool) -// { } -// -// // Inherited via RPCHandler -// virtual void handle(pubsub::msgs::Request const & request_id, MDRequest const & request) override { -// _threadpool.post([=]() { -// google::protobuf::Arena arena; -// MDReply* preply = google::protobuf::Arena::CreateMessage(&arena); -// TimeStamp start = TimeStamp::now(); -// _db.query(request, preply); -// auto elapsed = (TimeStamp::now() - start); -// LOG(Diag, MarketData) << "Request for: " << request.host() << " took " << (elapsed.microseconds()) << "us and returned " << preply->ByteSize() << " bytes before compression"; -// reply(request_id, *preply); -// }); -// } -// }; +struct MDRelayServer : bts::co2::MarketDataRelayBase { + const QueryServerImpl& _db; + utils::Dispatcher& _threadpool; + MDRelayServer(const QueryServerImpl& db, utils::Dispatcher& threadpool, bts::api::ServiceContext ctx) : + bts::co2::MarketDataRelayBase(ctx), + _db(db), _threadpool(threadpool) + { } + + virtual void requestmd(const MDRequest & request, std::function reply) override { + _threadpool.post([=]() { + google::protobuf::Arena arena; + MDReply* preply = google::protobuf::Arena::CreateMessage(&arena); + TimeStamp start = TimeStamp::now(); + _db.query(request, preply); + auto elapsed = (TimeStamp::now() - start); + LOG(MarketData, Diag, + "Request for: {} took {}us and returned {} bytes before compression", + request.host(), + elapsed.microseconds(), + preply->ByteSize()); + reply(*preply); + }); + } +}; + +struct QueryServer { + QueryServer(std::set symbols, utils::Dispatcher& threadpool, const bts::api::ServiceContext& ctx): + db(symbols), + relay(db, threadpool, ctx), + security_timer(), + health_timer() + { } + QueryServerImpl db; + MDRelayServer relay; + std::unique_ptr security_timer; + std::unique_ptr health_timer; +}; -// void run_query_server() { -// pubsub::PubsubHub hub( -// config::get().host(), -// config::get().edge_md_pubsub_port()); -// std::set all_symbols; -// get_system_md_symbols(config::get().exchange(), config::get().type(), all_symbols); -// QueryServer db(all_symbols); -// utils::Dispatcher& dispatcher = utils::Dispatcher::current(); -// PubSubRpcServer server(db, hub, dispatcher); -// server.start(); -// -// // Scan for new securities every half second -// utils::DispatcherTimer security_timer(dispatcher, config::get().security_scan_interval(), [&db]() { -// db.scan_securities(); -// }); -// security_timer.start(); -// -// // Scan for dead producers every 30 seconds -// utils::DispatcherTimer health_timer(dispatcher, config::get().recovery_interval(), [&db]() { -// db.check_heartbeats(utils::Dispatcher::current()); -// }); -// health_timer.start(); -// -// utils::Dispatcher::current().run(std::min(4,os::num_cores())); -// } +QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx) { + auto& threadpool = utils::Dispatcher::get_named("MDQuery"); + std::set all_symbols; + get_system_md_symbols(config::get().exchange(), config::get().type(), all_symbols); + QueryServerPtr container = std::make_shared(all_symbols, threadpool, ctx); + auto& db = container->db; -// std::unique_ptr create_query_server(const std::set& symbols) { -// return utils::make_unique(symbols); -// } + // Scan for new securities every half second + container->security_timer = std::make_unique(threadpool, config::get().security_scan_interval(), [&db]() { + db.scan_securities(); + }); + container->security_timer->start(); + + // Scan for dead producers every 30 seconds + container->health_timer = std::make_unique(threadpool, config::get().recovery_interval(), [&db, &threadpool]() { + db.check_heartbeats(threadpool); + }); + container->health_timer->start(); + + // Add a few threads to keep md latency low + for (int x = 1; x < std::min(4, os::num_cores()); ++x) { + threadpool.add_thread(); + } + + return container; +} + +std::unique_ptr create_query_server(const std::set& symbols) { + return std::make_unique(symbols); +} }}//namespace #endif diff --git a/src/lib/md/relay/QueryServer.h b/src/lib/md/relay/QueryServer.h index 2a7742d3d..3ad2362b5 100644 --- a/src/lib/md/relay/QueryServer.h +++ b/src/lib/md/relay/QueryServer.h @@ -9,6 +9,7 @@ #include "lib/md/protos/co2.pb.h" namespace bts { + namespace api { class ServiceContext; } namespace md { struct IQueryServer { @@ -18,7 +19,9 @@ struct IQueryServer { }; std::unique_ptr create_query_server(const std::set& symbols); -BTS_EXPORT void run_query_server(); +struct QueryServer; +typedef std::shared_ptr QueryServerPtr; +BTS_EXPORT QueryServerPtr run_query_server(const bts::api::ServiceContext&); }}//namespace diff --git a/src/lib/utils/Dispatcher.cpp b/src/lib/utils/Dispatcher.cpp index bb9c30f5f..ade6a1a48 100755 --- a/src/lib/utils/Dispatcher.cpp +++ b/src/lib/utils/Dispatcher.cpp @@ -262,6 +262,9 @@ DispatcherTimer::DispatcherTimer(Dispatcher& dispatcher, int64_t time_ms, Action { } +DispatcherTimer::DispatcherTimer(DispatcherTimer&& other) : _me(std::move(other._me)) {} + + DispatcherTimer::~DispatcherTimer() { } void DispatcherTimer::start() diff --git a/src/lib/utils/Dispatcher.h b/src/lib/utils/Dispatcher.h index cf0f74fc5..cb4b5402f 100755 --- a/src/lib/utils/Dispatcher.h +++ b/src/lib/utils/Dispatcher.h @@ -97,6 +97,7 @@ class BTS_EXPORT DispatcherTimer { public: DispatcherTimer(Dispatcher& dispatcher, int64_t time_ms, Action cb); + DispatcherTimer(DispatcherTimer&& other); ~DispatcherTimer(); void start(); void stop(); diff --git a/src/server/sparkd/setup/ServiceHostActor.cpp b/src/server/sparkd/setup/ServiceHostActor.cpp index 56c0a010d..2c692d9de 100644 --- a/src/server/sparkd/setup/ServiceHostActor.cpp +++ b/src/server/sparkd/setup/ServiceHostActor.cpp @@ -9,6 +9,7 @@ #include "server/sparkd/persistence/PersistenceServiceServer.h" #include "server/sparkd/user/UserServiceServer.h" +#include "lib/md/relay/QueryServer.h" namespace bts { namespace setup { @@ -25,14 +26,17 @@ struct ServiceHostActor::PImpl PImpl() : quickbus(make_cfg(),qbus::Quickbus::ThreadOptions::outside_thread), service_context(&quickbus), settings_saver(service_context,"settings"), - login_server(service_context) - {} + login_server(service_context), + md_query_server(md::run_query_server(service_context)) + { + } qbus::Quickbus quickbus; api::ServiceContext service_context; // hosted services persistence::PersistenceServiceServer settings_saver; user::UserServiceServer login_server; + md::QueryServerPtr md_query_server; }; ServiceHostActor::ServiceHostActor () : me (new PImpl()) {} diff --git a/tools/setup_builds.bat b/tools/setup_builds.bat index ec3c35555..49f927867 100644 --- a/tools/setup_builds.bat +++ b/tools/setup_builds.bat @@ -1,3 +1,4 @@ -mkdir build -cd build -cmake -G "Visual Studio 15 2017 Win64" .. +@setlocal +mkdir build +cd build +cmake -G "Visual Studio 15 2017 Win64" .. diff --git a/tools/setup_builds.sh b/tools/setup_builds.sh index 5bd723c0b..b51824973 100755 --- a/tools/setup_builds.sh +++ b/tools/setup_builds.sh @@ -1,5 +1,6 @@ #/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +mkdir -p $DIR/../build/ cd $DIR/../build/ rm -rf gcc_debug