Enable increasing/decreasing compute threads.

This commit is contained in:
Xie Han
2024-05-28 17:32:51 +08:00
parent 30a78d30b3
commit 16686bab71
4 changed files with 26 additions and 8 deletions

View File

@@ -52,12 +52,6 @@ void ExecQueue::deinit()
int Executor::init(size_t nthreads)
{
if (nthreads == 0)
{
errno = EINVAL;
return -1;
}
this->thrdpool = thrdpool_create(nthreads, 0);
if (this->thrdpool)
return 0;
@@ -152,3 +146,13 @@ int Executor::request(ExecSession *session, ExecQueue *queue)
return -!entry;
}
int Executor::increase_thread()
{
return thrdpool_increase(this->thrdpool);
}
int Executor::decrease_thread()
{
return thrdpool_decrease(this->thrdpool);
}

View File

@@ -67,6 +67,10 @@ public:
int request(ExecSession *session, ExecQueue *queue);
public:
int increase_thread();
int decrease_thread();
private:
struct __thrdpool *thrdpool;

View File

@@ -421,7 +421,7 @@ private:
{
int compute_threads = WFGlobal::get_global_settings()->compute_threads;
if (compute_threads <= 0)
if (compute_threads < 0)
compute_threads = sysconf(_SC_NPROCESSORS_ONLN);
if (compute_executor_.init(compute_threads) < 0)

View File

@@ -54,7 +54,7 @@ struct WFGlobalSettings
int dns_threads;
int poller_threads;
int handler_threads;
int compute_threads; ///< auto-set by system CPU number if value<=0
int compute_threads; ///< auto-set by system CPU number if value<0
int fio_max_events;
const char *resolv_conf_path;
const char *hosts_path;
@@ -124,6 +124,16 @@ public:
static const char *get_error_string(int state, int error);
static bool increase_compute_thread()
{
return WFGlobal::get_compute_executor()->increase_thread() == 0;
}
static bool decrease_compute_thread()
{
return WFGlobal::get_compute_executor()->decrease_thread() == 0;
}
// Internal usage only
public:
static bool is_scheduler_created();