summaryrefslogtreecommitdiffstats
path: root/src/schedule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/schedule.cpp')
-rw-r--r--src/schedule.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/schedule.cpp b/src/schedule.cpp
index 8073cf1..ef10337 100644
--- a/src/schedule.cpp
+++ b/src/schedule.cpp
@@ -1,24 +1,37 @@
+#include <iostream>
+
#include "ocelot.h"
#include "config.h"
#include "db.h"
#include "worker.h"
-#include "events.h"
#include "schedule.h"
-
-schedule::schedule(connection_mother * mother_obj, worker* worker_obj, config* conf_obj, mysql * db_obj, site_comm * sc_obj) : mother(mother_obj), work(worker_obj), conf(conf_obj), db(db_obj), sc(sc_obj) {
+schedule::schedule(config * conf, worker * worker_obj, mysql * db_obj, site_comm * sc_obj) : work(worker_obj), db(db_obj), sc(sc_obj) {
+ load_config(conf);
counter = 0;
last_opened_connections = 0;
+ last_request_count = 0;
+ next_reap_peers = reap_peers_interval;
+}
+
+void schedule::load_config(config * conf) {
+ reap_peers_interval = conf->get_uint("reap_peers_interval");
+ schedule_interval = conf->get_uint("schedule_interval");
+}
- next_reap_peers = time(NULL) + conf->reap_peers_interval + 40;
+void schedule::reload_config(config * conf) {
+ load_config(conf);
}
+
//---------- Schedule - gets called every schedule_interval seconds
void schedule::handle(ev::timer &watcher, int events_flags) {
- stats.connection_rate = (stats.opened_connections - last_opened_connections) / conf->schedule_interval;
+ unsigned int cur_schedule_interval = watcher.repeat;
+ stats.connection_rate = (stats.opened_connections - last_opened_connections) / cur_schedule_interval;
+ stats.request_rate = (stats.requests - last_request_count) / cur_schedule_interval;
if (counter % 20 == 0) {
- std::cout << "Schedule run #" << counter << " - open: " << stats.open_connections << ", opened: "
- << stats.opened_connections << ", speed: "
- << stats.connection_rate << "/s" << std::endl;
+ std::cout << stats.open_connections << " open, "
+ << stats.opened_connections << " connections (" << stats.connection_rate << "/s), "
+ << stats.requests << " requests (" << stats.request_rate << "/s)" << std::endl;
}
if (work->get_status() == CLOSING && db->all_clear() && sc->all_clear()) {
@@ -27,16 +40,19 @@ void schedule::handle(ev::timer &watcher, int events_flags) {
}
last_opened_connections = stats.opened_connections;
+ last_request_count = stats.requests;
db->flush();
sc->flush_tokens();
- time_t cur_time = time(NULL);
-
- if (cur_time > next_reap_peers) {
+ next_reap_peers -= cur_schedule_interval;
+ if (next_reap_peers <= 0) {
work->start_reaper();
- next_reap_peers = cur_time + conf->reap_peers_interval;
+ next_reap_peers = reap_peers_interval;
}
counter++;
+ if (schedule_interval != cur_schedule_interval) {
+ watcher.set(schedule_interval, schedule_interval);
+ }
}