Skip to content

Commit

Permalink
update stand alone daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
heroicNeZha committed Dec 28, 2021
1 parent ffab7f9 commit 153d115
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions src/daemons/StandAloneDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "daemons/SetupLogging.h"
#include "folly/ScopeGuard.h"
#include "graph/service/GraphFlags.h"
#include "graph/service/GraphServer.h"
#include "graph/service/GraphService.h"
#include "graph/stats/GraphStats.h"
#include "meta/MetaServiceHandler.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ extern Status setupBreakpad();
#endif

std::unique_ptr<nebula::storage::StorageServer> gStorageServer;
static std::unique_ptr<apache::thrift::ThriftServer> gServer;
static std::unique_ptr<nebula::graph::GraphServer> gServer;
static std::unique_ptr<apache::thrift::ThriftServer> gMetaServer;
static std::unique_ptr<nebula::kvstore::KVStore> gMetaKVStore;
std::mutex gServerGuard;
Expand Down Expand Up @@ -311,34 +312,13 @@ int main(int argc, char *argv[]) {
auto threadFactory = std::make_shared<folly::NamedThreadFactory>("graph-netio");
auto ioThreadPool = std::make_shared<folly::IOThreadPoolExecutor>(FLAGS_num_netio_threads,
std::move(threadFactory));
gServer = std::make_unique<apache::thrift::ThriftServer>();
gServer->setIOThreadPool(ioThreadPool);

auto interface = std::make_shared<GraphService>();
status = interface->init(ioThreadPool, localhost);
if (!status.ok()) {
LOG(ERROR) << status;
gServer = std::make_unique<nebula::graph::GraphServer>(localhost);
if (!gServer->start()) {
LOG(ERROR) << "The graph server start failed";
return;
}

gServer->setPort(localhost.port);
gServer->setInterface(std::move(interface));
gServer->setReusePort(FLAGS_reuse_port);
gServer->setIdleTimeout(std::chrono::seconds(FLAGS_client_idle_timeout_secs));
gServer->setNumAcceptThreads(FLAGS_num_accept_threads);
gServer->setListenBacklog(FLAGS_listen_backlog);
if (FLAGS_enable_ssl || FLAGS_enable_graph_ssl) {
gServer->setSSLConfig(nebula::sslContextConfig());
}
setupThreadManager();
// Modify two blocking service
FLOG_INFO("Starting nebula-graphd on %s:%d\n", localhost.host.c_str(), localhost.port);
try {
gServer->serve(); // Blocking wait until shut down via gServer->stop()
} catch (const std::exception &e) {
FLOG_ERROR("Exception thrown while starting the RPC server: %s", e.what());
return;
}
gServer->waitUntilStop();
FLOG_INFO("nebula-graphd on %s:%d has been stopped", localhost.host.c_str(), localhost.port);
graphRet = EXIT_SUCCESS;
return;
Expand Down Expand Up @@ -398,7 +378,7 @@ Status setupSignalHandler() {
void stopAllDaemon() {
std::lock_guard<std::mutex> guard(gServerGuard);
if (gServer) {
gServer->stop();
gServer->notifyStop();
gServer.reset();
}
if (gStorageServer) {
Expand Down Expand Up @@ -436,13 +416,3 @@ void signalHandler(int sig) {
void printHelp(const char *prog) {
fprintf(stderr, "%s --flagfile <config_file>\n", prog);
}

void setupThreadManager() {
int numThreads =
FLAGS_num_worker_threads > 0 ? FLAGS_num_worker_threads : gServer->getNumIOWorkerThreads();
std::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager(
PriorityThreadManager::newPriorityThreadManager(numThreads));
threadManager->setNamePrefix("executor");
threadManager->start();
gServer->setThreadManager(threadManager);
}

0 comments on commit 153d115

Please sign in to comment.