Skip to content

Commit e047350

Browse files
AliSQLAliSQL
authored andcommitted
[Feature] Issue#26 ADD TOKUDB_CPU_NUMS TO CONTROL TokuDB CPU NUMS
1 parent e6a4bbe commit e047350

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

mysql-test/suite/rds/r/tokudb.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ Tokudb_rows_inserted 41
281281
Tokudb_rows_read 98
282282
Tokudb_rows_deleted 8
283283
Tokudb_rows_updated 19
284+
show variables like 'tokudb_cpu_nums';
285+
Variable_name Value
286+
tokudb_cpu_nums 0
284287
# Restart server.
285288
DROP TABLE t1;
286289
DROP TABLE t2;

mysql-test/suite/rds/t/tokudb.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ SELECT MAX(c1) FROM t3;
183183
--sleep 2
184184
--let $innodb_status =`show engine tokudb status`
185185
show status like '%tokudb_rows%';
186+
show variables like 'tokudb_cpu_nums';
186187

187188
#Restart the server to cover TC_LOG_MMAP recover logic
188189
--disable_reconnect

storage/tokudb/ft-index/buildheader/db-4.6.19.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ struct __db {
17131713
int (*set_bt_prefix)
17141714
__P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
17151715
int (*set_cachesize) __P((DB *, uint32_t, uint32_t, int));
1716+
int (*set_cpunums) __P((DB *, int));
17161717
int (*set_dup_compare)
17171718
__P((DB *, int (*)(DB *, const DBT *, const DBT *)));
17181719
int (*set_encrypt) __P((DB *, const char *, uint32_t));
@@ -2402,6 +2403,7 @@ struct __db_env {
24022403
int (*set_app_dispatch)
24032404
__P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
24042405
int (*set_cachesize) __P((DB_ENV *, uint32_t, uint32_t, int));
2406+
int (*set_cpunums) __P((DB_ENV *, int));
24052407
int (*set_cache_max) __P((DB_ENV *, uint32_t, uint32_t));
24062408
int (*set_data_dir) __P((DB_ENV *, const char *));
24072409
int (*set_encrypt) __P((DB_ENV *, const char *, uint32_t));

storage/tokudb/ft-index/buildheader/make_tdb.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static void print_db_env_struct (void) {
387387
STRUCT_SETUP(DB_ENV, log_flush, "int (*%s) (DB_ENV *, const DB_LSN *)");
388388
STRUCT_SETUP(DB_ENV, open, "int (*%s) (DB_ENV *, const char *, uint32_t, int)");
389389
STRUCT_SETUP(DB_ENV, set_cachesize, "int (*%s) (DB_ENV *, uint32_t, uint32_t, int)");
390+
STRUCT_SETUP(DB_ENV, set_cpunums, "int (*%s) (DB_ENV *, int)");
390391
STRUCT_SETUP(DB_ENV, set_data_dir, "int (*%s) (DB_ENV *, const char *)");
391392
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1
392393
STRUCT_SETUP(DB_ENV, set_errcall, "void (*%s) (DB_ENV *, void (*)(const char *, char *))");

storage/tokudb/ft-index/portability/portability.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ toku_os_get_number_processors(void) {
170170
return sysconf(_SC_NPROCESSORS_CONF);
171171
}
172172

173+
int toku_cpu_nums;
174+
173175
int
174176
toku_os_get_number_active_processors(void) {
175177
int n = sysconf(_SC_NPROCESSORS_ONLN);
@@ -184,6 +186,8 @@ toku_os_get_number_active_processors(void) {
184186
}
185187
}
186188
#endif
189+
if (toku_cpu_nums > 0 && toku_cpu_nums < n)
190+
n = toku_cpu_nums;
187191
return n;
188192
}
189193

storage/tokudb/ft-index/src/ydb.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,14 @@ env_set_cachesize(DB_ENV * env, uint32_t gbytes, uint32_t bytes, int ncache) {
12621262
return 0;
12631263
}
12641264

1265+
static int
1266+
env_set_cpunums(DB_ENV * env, int nums) {
1267+
(void)env;
1268+
extern int toku_cpu_nums;
1269+
toku_drd_unsafe_set(&toku_cpu_nums, nums);
1270+
return 0;
1271+
}
1272+
12651273
static int env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbname, uint32_t flags);
12661274

12671275
static int
@@ -2599,6 +2607,7 @@ toku_env_create(DB_ENV ** envp, uint32_t flags) {
25992607
USENV(cleaner_get_period);
26002608
USENV(cleaner_set_iterations);
26012609
USENV(cleaner_get_iterations);
2610+
USENV(set_cpunums);
26022611
USENV(set_cachesize);
26032612
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
26042613
USENV(get_cachesize);

storage/tokudb/hatoku_hton.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ static uint32_t tokudb_env_flags = 0;
252252
static my_bool tokudb_directio = FALSE;
253253
static my_bool tokudb_checkpoint_on_flush_logs = FALSE;
254254
static ulonglong tokudb_cache_size = 0;
255+
static int tokudb_cpu_nums = 0;
255256
static ulonglong tokudb_max_lock_memory = 0;
256257
static char *tokudb_home;
257258
static char *tokudb_tmp_dir;
@@ -511,6 +512,17 @@ static int tokudb_init_func(void *p) {
511512
goto error;
512513
}
513514
}
515+
516+
if (tokudb_cpu_nums) {
517+
DBUG_PRINT("info", ("tokudb_cpu_nums: %d\n", tokudb_cpu_nums));
518+
r = db_env->set_cpunums(db_env, tokudb_cpu_nums);
519+
if (r) {
520+
DBUG_PRINT("info", ("set_cpunums %d\n", r));
521+
goto error;
522+
}
523+
}
524+
525+
514526
if (tokudb_max_lock_memory == 0) {
515527
tokudb_max_lock_memory = tokudb_cache_size/8;
516528
}
@@ -1463,6 +1475,10 @@ static MYSQL_SYSVAR_ULONGLONG(cache_size, tokudb_cache_size,
14631475
PLUGIN_VAR_READONLY, "TokuDB cache table size", NULL, NULL, 0,
14641476
0, ~0ULL, 0);
14651477

1478+
static MYSQL_SYSVAR_INT(cpu_nums, tokudb_cpu_nums,
1479+
PLUGIN_VAR_READONLY, "TokuDB CPU nums", NULL, NULL, 0,
1480+
0, 0, 0);
1481+
14661482
static MYSQL_SYSVAR_ULONGLONG(max_lock_memory, tokudb_max_lock_memory, PLUGIN_VAR_READONLY, "TokuDB max memory for locks", NULL, NULL, 0, 0, ~0ULL, 0);
14671483
static MYSQL_SYSVAR_ULONG(debug, tokudb_debug, 0, "TokuDB Debug", NULL, NULL, 0, 0, ~0UL, 0);
14681484

@@ -1492,6 +1508,7 @@ static MYSQL_SYSVAR_UINT(fsync_log_period, tokudb_fsync_log_period, 0, "TokuDB f
14921508

14931509
static struct st_mysql_sys_var *tokudb_system_variables[] = {
14941510
MYSQL_SYSVAR(cache_size),
1511+
MYSQL_SYSVAR(cpu_nums),
14951512
MYSQL_SYSVAR(max_lock_memory),
14961513
MYSQL_SYSVAR(data_dir),
14971514
MYSQL_SYSVAR(log_dir),

0 commit comments

Comments
 (0)