From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladislav Shpilevoy Subject: [PATCH v2 4/4] Allow to configure TX fiber pool size Date: Mon, 23 Apr 2018 20:05:04 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com List-ID: TX fiber pool size provides fibers to execute transactions and remote requests, so it is linked with maximal remote request count, that is allowed to be altered in the previous patch. Lets do the same for fiber pool size. Follow up #3320 --- src/box/box.cc | 9 ++++++++- src/box/lua/load_cfg.lua | 2 ++ src/fiber_pool.h | 6 +++++- test/box/fat_tx.lua | 30 ++++++++++++++++++++++++++++ test/box/request_limit.result | 43 +++++++++++++++++++++++++++++++++++++++++ test/box/request_limit.test.lua | 15 ++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 test/box/fat_tx.lua diff --git a/src/box/box.cc b/src/box/box.cc index 80684ad48..d2552709a 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1716,8 +1716,15 @@ box_is_configured(void) static inline void box_cfg_xc(void) { + int fiber_pool_size = + cfg_geti_default("fiber_pool_size", FIBER_POOL_SIZE_DEFAULT); + if (fiber_pool_size < FIBER_POOL_SIZE_MIN) { + tnt_raise(ClientError, ER_CFG, "fiber_pool_size", + tt_sprintf("minimal value is %d", + FIBER_POOL_SIZE_MIN)); + } /* Join the cord interconnect as "tx" endpoint. */ - fiber_pool_create(&tx_fiber_pool, "tx", FIBER_POOL_SIZE, + fiber_pool_create(&tx_fiber_pool, "tx", fiber_pool_size, FIBER_POOL_IDLE_TIMEOUT); /* Add an extra endpoint for WAL wake up/rollback messages. */ cbus_endpoint_create(&tx_prio_endpoint, "tx_prio", tx_prio_cb, &tx_prio_endpoint); diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index 6ed30e016..b8af58450 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -64,6 +64,7 @@ local default_cfg = { feedback_host = "https://feedback.tarantool.io", feedback_interval = 3600, iproto_msg_max = 768, + fiber_pool_size = 4096, } -- types of available options @@ -125,6 +126,7 @@ local template_cfg = { feedback_host = 'string', feedback_interval = 'number', iproto_msg_max = 'number', + fiber_pool_size = 'number', } local function normalize_uri(port) diff --git a/src/fiber_pool.h b/src/fiber_pool.h index d6a95105b..9f99da5ea 100644 --- a/src/fiber_pool.h +++ b/src/fiber_pool.h @@ -41,7 +41,11 @@ extern "C" { #endif /* defined(__cplusplus) */ -enum { FIBER_POOL_SIZE = 4096, FIBER_POOL_IDLE_TIMEOUT = 1 }; +enum { + FIBER_POOL_SIZE_DEFAULT = 4096, + FIBER_POOL_SIZE_MIN = 100, + FIBER_POOL_IDLE_TIMEOUT = 1 +}; /** * A pool of worker fibers to handle messages, diff --git a/test/box/fat_tx.lua b/test/box/fat_tx.lua new file mode 100644 index 000000000..6ef5c8f96 --- /dev/null +++ b/test/box/fat_tx.lua @@ -0,0 +1,30 @@ +#!/usr/bin/env tarantool +os = require('os') + +box.cfg{ + listen = os.getenv("LISTEN"), + pid_file = "tarantool.pid", + fiber_pool_size = 5000, + iproto_msg_max = 5000 +} + +require('console').listen(os.getenv('ADMIN')) +net_box = require('net.box') +fiber = require('fiber') + +box.schema.user.grant('guest', 'read,write,execute', 'universe') +conn = net_box.connect(box.cfg.listen) +net_box = require('net.box') +active = 0 +continue = false +function do_long_f() + active = active + 1 + while not continue do + fiber.sleep(0.1) + end + active = active - 1 +end + +function do_long(c) + c:call('do_long_f') +end diff --git a/test/box/request_limit.result b/test/box/request_limit.result index 8f722b1b9..068ba3766 100644 --- a/test/box/request_limit.result +++ b/test/box/request_limit.result @@ -270,6 +270,49 @@ conn2:close() conn:close() --- ... +-- +-- Test that new fiber pool limit can be reached. +-- +test_run:cmd('create server fat_tx with script = "box/fat_tx.lua"') +--- +- true +... +test_run:cmd("start server fat_tx") +--- +- true +... +test_run:cmd('switch fat_tx') +--- +- true +... +box.cfg.fiber_pool_size +--- +- 5000 +... +for i = 1, 5000 do fiber.create(do_long, conn) end +--- +... +while active ~= 5000 do fiber.sleep(0.01) end +--- +... +continue = true +--- +... +while active ~= 0 do fiber.sleep(0.01) end +--- +... +test_run:cmd("switch default") +--- +- true +... +test_run:cmd("stop server fat_tx") +--- +- true +... +test_run:cmd("cleanup server fat_tx") +--- +- true +... box.schema.user.revoke('guest', 'read,write,execute', 'universe') --- ... diff --git a/test/box/request_limit.test.lua b/test/box/request_limit.test.lua index 286df0455..f02d0dcdd 100644 --- a/test/box/request_limit.test.lua +++ b/test/box/request_limit.test.lua @@ -136,5 +136,20 @@ wait_finished(run_max * 2) conn2:close() conn:close() +-- +-- Test that new fiber pool limit can be reached. +-- +test_run:cmd('create server fat_tx with script = "box/fat_tx.lua"') +test_run:cmd("start server fat_tx") +test_run:cmd('switch fat_tx') +box.cfg.fiber_pool_size +for i = 1, 5000 do fiber.create(do_long, conn) end +while active ~= 5000 do fiber.sleep(0.01) end +continue = true +while active ~= 0 do fiber.sleep(0.01) end +test_run:cmd("switch default") +test_run:cmd("stop server fat_tx") +test_run:cmd("cleanup server fat_tx") + box.schema.user.revoke('guest', 'read,write,execute', 'universe') box.cfg{readahead = old_readahead, iproto_msg_max = limit} -- 2.15.1 (Apple Git-101)