Fri, 12 Jan 2018 18:36:47 +0100
adds IO threadpool
--- a/src/server/daemon/threadpools.c Fri Jan 12 18:12:42 2018 +0100 +++ b/src/server/daemon/threadpools.c Fri Jan 12 18:36:47 2018 +0100 @@ -34,12 +34,16 @@ #include "threadpools.h" -static UcxMap *thread_pool_map = NULL; -static int numthrpools = 0; +static UcxMap *thread_pool_map; +static int num_thrpools; +static UcxMap *io_pool_map; +static int num_iopools; -threadpool_t *default_thread_pool = NULL; +static threadpool_t *default_thread_pool; +static threadpool_t *last_thrpool_c; -threadpool_t *last_thrpool_c = NULL; +static threadpool_t *default_io_pool; +static threadpool_t *last_io_pool; int create_threadpool(sstr_t name, ThreadPoolConfig *cfg) { if(thread_pool_map == NULL) { @@ -62,8 +66,37 @@ int ret = ucx_map_sstr_put(thread_pool_map, name, tp); if(ret == 0) { - numthrpools++; + num_thrpools++; last_thrpool_c = tp; + if(!default_thread_pool) { + default_thread_pool = tp; + } + } + + return ret; + } +} + +int create_io_pool(sstr_t name, int numthreads) { + if(io_pool_map == NULL) { + io_pool_map = ucx_map_new(4); + } + threadpool_t *pool = ucx_map_sstr_get(io_pool_map, name); + if(pool) { + pool->min_threads = numthreads; + pool->max_threads = numthreads; + return 0; + } else { + threadpool_t *tp = threadpool_new(numthreads, numthreads); + + int ret = ucx_map_sstr_put(io_pool_map, name, tp); + + if(ret == 0) { + num_iopools++; + last_io_pool = tp; + if(!default_io_pool) { + default_io_pool = tp; + } } return ret; @@ -71,22 +104,24 @@ } int check_thread_pool_cfg() { - if(numthrpools > 0 ) { - if(default_thread_pool) { - return 0; - } else { - default_thread_pool = last_thrpool_c; - return 0; + if(num_thrpools == 0) { + ThreadPoolConfig cfg; + cfg.min_threads = 4; + cfg.max_threads = 8; + cfg.queue_size = 64; + cfg.stack_size = 262144; + if(create_threadpool(sstr("default"), &cfg)) { + return 1; } } - ThreadPoolConfig cfg; - cfg.min_threads = 4; - cfg.max_threads = 8; - cfg.queue_size = 64; - cfg.stack_size = 262144; + if(num_iopools == 0) { + if(create_io_pool(sstr("default"), 8)) { + return 1; + } + } - return create_threadpool(sstr("default"), &cfg); + return 0; } threadpool_t* get_default_threadpool() { @@ -96,3 +131,11 @@ threadpool_t* get_threadpool(sstr_t name) { return ucx_map_sstr_get(thread_pool_map, name); } + +threadpool_t* get_default_iopool() { + return default_io_pool; +} + +threadpool_t* get_iopool(sstr_t name) { + return ucx_map_sstr_get(io_pool_map, name); +}
--- a/src/server/daemon/threadpools.h Fri Jan 12 18:12:42 2018 +0100 +++ b/src/server/daemon/threadpools.h Fri Jan 12 18:36:47 2018 +0100 @@ -51,6 +51,8 @@ threadpool_t* get_default_threadpool(); threadpool_t* get_threadpool(sstr_t name); +threadpool_t* get_default_iopool(); +threadpool_t* get_iopool(sstr_t name); #ifdef __cplusplus }
--- a/src/server/daemon/vfs.c Fri Jan 12 18:12:42 2018 +0100 +++ b/src/server/daemon/vfs.c Fri Jan 12 18:36:47 2018 +0100 @@ -664,7 +664,7 @@ } void vfs_queue_aio(aiocb_s *aiocb, VFSAioOp op) { - threadpool_t *pool = get_default_threadpool(); // TODO: use IOPool + threadpool_t *pool = get_default_iopool(); // TODO: use specific IOPool if(op == VFS_AIO_READ) { threadpool_run(pool, (job_callback_f)vfs_aio_read, aiocb); } else if(VFS_AIO_WRITE) {