Update CPU statistics on a dedicated thread.

This commit is contained in:
levlam 2023-09-03 01:03:53 +03:00
parent 1cab23c1f1
commit 18b5f287f7
2 changed files with 9 additions and 2 deletions

View File

@ -93,9 +93,14 @@ struct SharedData {
return 10; return 10;
} }
static td::int32 get_thread_count() { static td::int32 get_statistics_thread_id() {
// the thread for CPU usage updating
return 11; return 11;
} }
static td::int32 get_thread_count() {
return 12;
}
}; };
struct ClientParameters { struct ClientParameters {

View File

@ -556,7 +556,9 @@ int main(int argc, char *argv[]) {
next_cron_time = now; next_cron_time = now;
} }
next_cron_time += 1.0; next_cron_time += 1.0;
ServerCpuStat::update(now); auto guard = sched.get_main_guard();
td::Scheduler::instance()->run_on_scheduler(SharedData::get_statistics_thread_id(),
[](td::Unit) { ServerCpuStat::update(td::Time::now()); });
} }
if (now >= start_time + 600) { if (now >= start_time + 600) {