mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Enable increasing/decreasing compute threads.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ public:
|
||||
|
||||
int request(ExecSession *session, ExecQueue *queue);
|
||||
|
||||
public:
|
||||
int increase_thread();
|
||||
int decrease_thread();
|
||||
|
||||
private:
|
||||
struct __thrdpool *thrdpool;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user