Skip to content
Snippets Groups Projects
Commit c10c4251 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

proxy server: print stats to stdout once in a while

parent 8b90c473
Branches
No related tags found
No related merge requests found
...@@ -230,6 +230,8 @@ private: ...@@ -230,6 +230,8 @@ private:
Scheduler scheduler_; Scheduler scheduler_;
std::thread schedulerThread_; std::thread schedulerThread_;
Sp<Scheduler::Job> printStatsJob_;
// Handle client quit for listen. // Handle client quit for listen.
// NOTE: can be simplified when we will supports restbed 5.0 // NOTE: can be simplified when we will supports restbed 5.0
std::thread listenThread_; std::thread listenThread_;
......
...@@ -45,6 +45,7 @@ struct DhtProxyServer::SearchPuts { ...@@ -45,6 +45,7 @@ struct DhtProxyServer::SearchPuts {
std::map<dht::Value::Id, PermanentPut> puts; std::map<dht::Value::Id, PermanentPut> puts;
}; };
constexpr const std::chrono::minutes PRINT_STATS_PERIOD {2};
DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port , const std::string& pushServer) DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port , const std::string& pushServer)
: dht_(dht) , pushServer_(pushServer) : dht_(dht) , pushServer_(pushServer)
...@@ -122,6 +123,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port , ...@@ -122,6 +123,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port ,
while (not service_->is_up() and not stopListeners) { while (not service_->is_up() and not stopListeners) {
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
} }
printStatsJob_ = scheduler_.add(scheduler_.time() + PRINT_STATS_PERIOD, [this]{
if (service_->is_up() and not stopListeners) {
std::cout << getStats().toString() << std::endl;
scheduler_.edit(printStatsJob_, scheduler_.time() + PRINT_STATS_PERIOD);
}
});
while (service_->is_up() and not stopListeners) { while (service_->is_up() and not stopListeners) {
std::unique_lock<std::mutex> lock(schedulerLock_); std::unique_lock<std::mutex> lock(schedulerLock_);
auto next = scheduler_.run(); auto next = scheduler_.run();
...@@ -143,6 +150,7 @@ DhtProxyServer::~DhtProxyServer() ...@@ -143,6 +150,7 @@ DhtProxyServer::~DhtProxyServer()
void void
DhtProxyServer::stop() DhtProxyServer::stop()
{ {
printStatsJob_->cancel();
service_->stop(); service_->stop();
{ {
std::lock_guard<std::mutex> lock(lockListener_); std::lock_guard<std::mutex> lock(lockListener_);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment