mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
task: export load tracking statistics
Provide an interface so that programs can monitor the Task load average calculations. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
46a38fe016
commit
a85ada3a49
@ -93,6 +93,17 @@ namespace crucible {
|
|||||||
/// Gets the current number of active workers
|
/// Gets the current number of active workers
|
||||||
static size_t get_thread_count();
|
static size_t get_thread_count();
|
||||||
|
|
||||||
|
/// Gets the current load tracking statistics
|
||||||
|
struct LoadStats {
|
||||||
|
/// Current load extracted from last two 5-second load average samples
|
||||||
|
double current_load;
|
||||||
|
/// Target thread count computed from previous thread count and current load
|
||||||
|
double thread_target;
|
||||||
|
/// Load average for last 60 seconds
|
||||||
|
double loadavg;
|
||||||
|
};
|
||||||
|
static LoadStats get_current_load();
|
||||||
|
|
||||||
/// Drop the current queue and discard new Tasks without
|
/// Drop the current queue and discard new Tasks without
|
||||||
/// running them. Currently executing tasks are not
|
/// running them. Currently executing tasks are not
|
||||||
/// affected (use set_thread_count(0) to wait for those
|
/// affected (use set_thread_count(0) to wait for those
|
||||||
|
18
lib/task.cc
18
lib/task.cc
@ -139,6 +139,7 @@ namespace crucible {
|
|||||||
double m_thread_target;
|
double m_thread_target;
|
||||||
bool m_cancelled = false;
|
bool m_cancelled = false;
|
||||||
bool m_paused = false;
|
bool m_paused = false;
|
||||||
|
TaskMaster::LoadStats m_load_stats;
|
||||||
|
|
||||||
friend class TaskConsumer;
|
friend class TaskConsumer;
|
||||||
friend class TaskMaster;
|
friend class TaskMaster;
|
||||||
@ -165,6 +166,7 @@ namespace crucible {
|
|||||||
static void push_front(TaskQueue &queue);
|
static void push_front(TaskQueue &queue);
|
||||||
size_t get_queue_count();
|
size_t get_queue_count();
|
||||||
size_t get_thread_count();
|
size_t get_thread_count();
|
||||||
|
static TaskMaster::LoadStats get_current_load();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TaskConsumer : public enable_shared_from_this<TaskConsumer> {
|
class TaskConsumer : public enable_shared_from_this<TaskConsumer> {
|
||||||
@ -348,7 +350,8 @@ namespace crucible {
|
|||||||
TaskMasterState::TaskMasterState(size_t thread_max) :
|
TaskMasterState::TaskMasterState(size_t thread_max) :
|
||||||
m_thread_max(thread_max),
|
m_thread_max(thread_max),
|
||||||
m_configured_thread_max(thread_max),
|
m_configured_thread_max(thread_max),
|
||||||
m_thread_target(thread_max)
|
m_thread_target(thread_max),
|
||||||
|
m_load_stats(TaskMaster::LoadStats { 0 })
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,6 +425,13 @@ namespace crucible {
|
|||||||
return s_tms->m_threads.size();
|
return s_tms->m_threads.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskMaster::LoadStats
|
||||||
|
TaskMaster::get_current_load()
|
||||||
|
{
|
||||||
|
unique_lock<mutex> lock(s_tms->m_mutex);
|
||||||
|
return s_tms->m_load_stats;
|
||||||
|
}
|
||||||
|
|
||||||
ostream &
|
ostream &
|
||||||
TaskMaster::print_queue(ostream &os)
|
TaskMaster::print_queue(ostream &os)
|
||||||
{
|
{
|
||||||
@ -502,6 +512,12 @@ namespace crucible {
|
|||||||
m_thread_target += m_load_target - current_load;
|
m_thread_target += m_load_target - current_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_load_stats = TaskMaster::LoadStats {
|
||||||
|
.current_load = current_load,
|
||||||
|
.thread_target = m_thread_target,
|
||||||
|
.loadavg = loadavg,
|
||||||
|
};
|
||||||
|
|
||||||
// Cannot exceed configured maximum thread count or less than zero
|
// Cannot exceed configured maximum thread count or less than zero
|
||||||
m_thread_target = min(max(0.0, m_thread_target), double(m_configured_thread_max));
|
m_thread_target = min(max(0.0, m_thread_target), double(m_configured_thread_max));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user