1 Star 0 Fork 32

惊奇脆片饼干/mariadb

forked from src-openEuler/mariadb 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
subserver-support.patch 5.73 KB
一键复制 编辑 原始数据 按行查看 历史
吴旭 提交于 2020-05-08 17:53 . Add subserver support
diff -uNr a/include/my_sys.h b/include/my_sys.h
--- a/include/my_sys.h 2020-03-18 17:25:17.027057590 +0800
+++ b/include/my_sys.h 2020-05-07 18:25:48.453846400 +0800
@@ -930,6 +930,7 @@
extern my_bool my_gethwaddr(uchar *to);
extern int my_getncpus(void);
+extern int my_getncpus_conf(void);
#define HRTIME_RESOLUTION 1000000ULL /* microseconds */
typedef struct {ulonglong val;} my_hrtime_t;
diff -uNr a/mysys/my_getncpus.c b/mysys/my_getncpus.c
--- a/mysys/my_getncpus.c 2020-03-18 17:25:17.075057590 +0800
+++ b/mysys/my_getncpus.c 2020-05-07 18:24:29.064846057 +0800
@@ -22,6 +22,7 @@
#endif
static int ncpus=0;
+static int ncpus_conf=0;
int my_getncpus()
{
@@ -48,3 +49,16 @@
}
return ncpus;
}
+
+int my_getncpus_conf()
+{
+ if (!ncpus_conf)
+ {
+#ifdef _SC_NPROCESSORS_CONF
+ ncpus_conf = sysconf(_SC_NPROCESSORS_CONF);
+#else
+ ncpus_conf = 2;
+#endif
+ }
+ return ncpus_conf;
+}
diff -uNr a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc 2020-03-18 17:25:16.256057586 +0800
+++ b/sql/mysqld.cc 2020-05-08 10:29:09.538096164 +0800
@@ -445,6 +445,8 @@
my_bool opt_explicit_defaults_for_timestamp= 0;
char *opt_slave_skip_errors;
char *opt_slave_transaction_retry_errors;
+uint subserver_nodes = 0;
+uint subserver_reserved_cpus = 0;
/*
Legacy global handlerton. These will be removed (please do not add more).
@@ -6526,6 +6528,38 @@
do_handle_one_connection(connect);
}
+#ifndef _WIN32
+#include <sched.h>
+
+static int nrcpus_conf = 0;
+static int cpus_per_subserver = 0;
+
+void assign_subserver(pthread_t thread_id, uint64 id)
+{
+ int node;
+ int start, count;
+ cpu_set_t affinity;
+
+ if (!subserver_nodes)
+ return;
+
+ if (!nrcpus_conf)
+ nrcpus_conf = my_getncpus_conf();
+
+ cpus_per_subserver = nrcpus_conf / subserver_nodes;
+ node = (id % nrcpus_conf) / cpus_per_subserver;
+ start = node * cpus_per_subserver;
+ count = cpus_per_subserver;
+
+ CPU_ZERO(&affinity);
+ while (--count >= subserver_reserved_cpus)
+ CPU_SET(start + count, &affinity);
+
+ pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), &affinity);
+}
+#else
+void assign_subserver(pthread_t thread_id, uint64 id) {}
+#endif
/*
Scheduler that uses one thread per connection
@@ -6573,6 +6607,8 @@
ER_OUT_OF_RESOURCES);
DBUG_VOID_RETURN;
/* purecov: end */
+ } else {
+ assign_subserver(connect->real_id, connect->thread_id);
}
DBUG_PRINT("info",("Thread created"));
DBUG_VOID_RETURN;
diff -uNr a/sql/mysqld.h b/sql/mysqld.h
--- a/sql/mysqld.h 2020-03-18 17:25:16.268057586 +0800
+++ b/sql/mysqld.h 2020-05-08 10:23:08.185094603 +0800
@@ -851,4 +851,11 @@
extern uint volatile global_disable_checkpoint;
extern my_bool opt_help;
+/*
+ * Sub-server support
+ */
+extern uint subserver_nodes;
+extern uint subserver_reserved_cpus;
+extern void assign_subserver(pthread_t thread_id, uint64 id);
+
#endif /* MYSQLD_INCLUDED */
diff -uNr a/sql/sys_vars.cc b/sql/sys_vars.cc
--- a/sql/sys_vars.cc 2020-03-18 17:25:16.288057586 +0800
+++ b/sql/sys_vars.cc 2020-05-07 17:42:41.940835224 +0800
@@ -6088,3 +6088,31 @@
"historical behavior, anyone can modify session timestamp",
READ_ONLY GLOBAL_VAR(opt_secure_timestamp), CMD_LINE(REQUIRED_ARG),
secure_timestamp_levels, DEFAULT(SECTIME_NO));
+
+static Sys_var_uint Sys_subserver_nodes(
+ "subserver_nodes", "While underlying platform is growing bigger and bigger,"
+ "scalability becomes a serious problem. In such a system, data movement"
+ "over a long distance can happen frequently, which quickly consumes memory"
+ "bandwidth, result in a performance drop. Sub-server nodes can be a solution"
+ "to ease this problem by limiting user threads within the scope of cpus"
+ "owned by a certain sub-server. Yes, we are essentially talking about the"
+ "schedule affinity of these threads. A sub-server node can only contain a"
+ "specific cpu or cover the entire CPU socket, depending on the type of"
+ "workload. Read-mostly workload may benefit from a more fine-grained nodes"
+ "thus a larger number of sub-server nodes, while write-heavy workload is"
+ "opposite. Set this variable to the number of NUMA nodes or CPU sockets is"
+ "recommended. Use 0 (default) to disable this feature.",
+ GLOBAL_VAR(subserver_nodes), CMD_LINE(REQUIRED_ARG),
+ VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
+
+static Sys_var_uint Sys_subserver_reserved_cpus(
+ "subserver_reserved_cpus", "While sub-server feature is enabled, all the"
+ "threads belonging to a sub-server are restricted within that sub-server"
+ "when migrating. So it makes sense to assign specific and local resources"
+ "like memory/network/storage to each sub-server, eliminating remote IOes."
+ "But these IOes can still make an impact on user threads. To make this"
+ "controllable, a several cpus in that sub-server could be isolated from"
+ "processing user threads and concentrate on dealing with various IOes."
+ "Use 0 (default) to disable the usage of specialized cpus.",
+ GLOBAL_VAR(subserver_reserved_cpus), CMD_LINE(REQUIRED_ARG),
+ VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
diff -uNr a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc
--- a/sql/threadpool_generic.cc 2020-03-18 17:25:16.277057586 +0800
+++ b/sql/threadpool_generic.cc 2020-05-08 10:26:22.244095442 +0800
@@ -953,6 +953,7 @@
thread_group->pthread_attr, worker_main, thread_group);
if (!err)
{
+ assign_subserver(thread_id, (thread_group - all_groups) % group_count);
thread_group->last_thread_creation_time=microsecond_interval_timer();
statistic_increment(thread_created,&LOCK_status);
add_thread_count(thread_group, 1);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dogsheng/mariadb.git
git@gitee.com:dogsheng/mariadb.git
dogsheng
mariadb
mariadb
master

搜索帮助