#At file:///home/bzr/mkindahl/plugin-next-mr-wl5136/ based on revid:mats.kindahl@stripped
3056 Mats Kindahl 2010-06-03
WL#5136: New Thread Pool Design
This patch turns the new thread pool design into a
plugin by moving the code for the scheduler into a
separate directory plugin/thread_pool and add the
necessary build files for creating a plugin.
@ configure.in
Removing checks for epoll(7) and poll(7) and moving them to the thread-pool plugin.
@ include/mysql/plugin.h
Adding prototypes for functions thd_set_thread_scheduler() and thd_reset_thread_scheduler().
@ mysql-test/suite/sys_vars/r/thread_pool_size_basic.result
Adding test for thread_pool_size.
@ mysql-test/suite/sys_vars/t/thread_pool_size_basic-master.opt
Options are needed to load the thread pool implementation.
@ plugin/thread_pool/plug.in
Moving checks for epoll(7) and poll(7) from configure.in to here.
@ sql/CMakeLists.txt
Thread pool files are moved to plugin/thread_pool.
@ sql/Makefile.am
Thread pool files are moved to plugin/thread_pool.
@ sql/mysql_priv.h
Removing thread_pool_size since it is not part of the server any more.
added:
mysql-test/suite/sys_vars/t/thread_pool_size_basic-master.opt
plugin/thread_pool/
plugin/thread_pool/CMakeLists.txt
plugin/thread_pool/Makefile.am
plugin/thread_pool/plug.in
plugin/thread_pool/thread_pool_plugin.cc
renamed:
sql/scheduler_epoll.ic => plugin/thread_pool/epoll.ic
sql/scheduler_poll.ic => plugin/thread_pool/poll.ic
sql/scheduler_thread_pool.cc => plugin/thread_pool/thread_pool.cc
sql/scheduler_thread_pool.h => plugin/thread_pool/thread_pool.h
modified:
configure.in
include/mysql/plugin.h
include/mysql/plugin.h.pp
mysql-test/r/mysqld--help-notwin.result
mysql-test/r/mysqld--help-win.result
mysql-test/suite/rpl/combinations
mysql-test/suite/sys_vars/r/thread_pool_size_basic.result
mysql-test/suite/sys_vars/t/thread_pool_size_basic.test
sql/CMakeLists.txt
sql/Makefile.am
sql/mysql_priv.h
sql/mysqld.cc
sql/scheduler.cc
sql/scheduler.h
plugin/thread_pool/epoll.ic
plugin/thread_pool/poll.ic
plugin/thread_pool/thread_pool.cc
plugin/thread_pool/thread_pool.h
=== modified file 'configure.in'
--- a/configure.in 2010-03-18 14:54:00 +0000
+++ b/configure.in 2010-06-03 10:12:28 +0000
@@ -850,7 +850,7 @@ AC_CHECK_HEADERS(fcntl.h fenv.h float.h
sys/timeb.h sys/types.h sys/un.h sys/vadvise.h sys/wait.h term.h \
unistd.h utime.h sys/utime.h termio.h termios.h sched.h crypt.h alloca.h \
sys/ioctl.h malloc.h sys/malloc.h sys/ipc.h sys/shm.h linux/config.h \
- sys/prctl.h sys/resource.h sys/param.h port.h sys/epoll.h ieeefp.h \
+ sys/prctl.h sys/resource.h sys/param.h port.h ieeefp.h \
execinfo.h)
AC_CHECK_HEADERS([xfs/xfs.h])
@@ -2636,15 +2636,6 @@ then
AC_DEFINE([HAVE_PTHREAD_ATTR_SETSCOPE], [1], [pthread_attr_setscope])
fi
-# Check for Linux epoll(7).
-AC_MSG_CHECKING([for Linux epoll(7)])
-haveepoll=no
-AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes])
-if test "x$haveepoll" = "xyes" ; then
- AC_DEFINE(HAVE_EPOLL, 1,
- [System supports the epoll(7) system calls])
-fi
-
# Check for bad includes
AC_MSG_CHECKING("can netinet files be included")
AC_TRY_COMPILE(
=== modified file 'include/mysql/plugin.h'
--- a/include/mysql/plugin.h 2010-03-08 10:00:20 +0000
+++ b/include/mysql/plugin.h 2010-06-03 10:12:28 +0000
@@ -464,6 +464,9 @@ struct st_mysql_information_schema
/* handlertons of different MySQL releases are incompatible */
#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
+struct handlerton;
+struct scheduler_functions;
+
/*
The real API is in the sql/handler.h
Here we define only the descriptor structure, that is referred from
@@ -475,8 +478,6 @@ struct st_mysql_storage_engine
int interface_version;
};
-struct handlerton;
-
/*
API for Replication plugin. (MYSQL_REPLICATION_PLUGIN)
@@ -582,6 +583,27 @@ unsigned long thd_get_thread_id(const MY
void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
/**
+ Set the thread scheduler to use for the server.
+
+ @param scheduler Pointer to scheduler callbacks to use.
+ @retval 0 Scheduler installed correctly.
+ @retval 1 Invalid value (NULL) used for scheduler.
+*/
+int thd_set_thread_scheduler(struct scheduler_functions *scheduler);
+
+/**
+ Restore the previous thread scheduler.
+
+ @note If no thread scheduler was installed previously with
+ thd_set_thread_scheduler, this function will report an error.
+
+ @retval 0 Scheduler installed correctly.
+ @retval 1 No scheduler installed.
+*/
+int thd_reset_thread_scheduler();
+
+
+/**
Invalidate the query cache for a given table.
@param thd user thread connection handle
@@ -618,6 +640,7 @@ thd_set_ha_data(const MYSQL_THD thd, con
{
*thd_ha_data(thd, hton)= (void*) ha_data;
}
+
#endif
#endif
=== modified file 'include/mysql/plugin.h.pp'
--- a/include/mysql/plugin.h.pp 2010-06-01 10:27:49 +0000
+++ b/include/mysql/plugin.h.pp 2010-06-03 10:12:28 +0000
@@ -153,11 +153,12 @@ struct st_mysql_information_schema
{
int interface_version;
};
+struct handlerton;
+struct scheduler_functions;
struct st_mysql_storage_engine
{
int interface_version;
};
-struct handlerton;
struct Mysql_replication {
int interface_version;
};
@@ -183,6 +184,8 @@ int mysql_tmpfile(const char *prefix);
int thd_killed(const void* thd);
unsigned long thd_get_thread_id(const void* thd);
void thd_get_xid(const void* thd, MYSQL_XID *xid);
+int thd_set_thread_scheduler(struct scheduler_functions *scheduler);
+int thd_reset_thread_scheduler();
void mysql_query_cache_invalidate4(void* thd,
const char *key, unsigned int key_length,
int using_trx);
=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result 2010-03-08 10:00:20 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result 2010-06-03 10:12:28 +0000
@@ -688,10 +688,7 @@ The following options may be given as th
How many threads we should keep in a cache for reuse
--thread-handling=name
Define threads usage for handling queries, one of
- one-thread-per-connection, no-threads, pool-of-threads
- --thread-pool-size=#
- How many threads we should create to handle query
- requests in case of 'thread_handling=pool-of-threads'
+ one-thread-per-connection, no-threads, loaded-dynamically
--thread-stack=# The stack size for each thread
--time-format=name The TIME format (ignored)
--timed-mutexes Specify whether to time mutexes (only InnoDB mutexes are
@@ -932,7 +929,6 @@ table-open-cache 400
tc-heuristic-recover COMMIT
thread-cache-size 0
thread-handling one-thread-per-connection
-thread-pool-size 16
thread-stack 262144
time-format %H:%i:%s
timed-mutexes FALSE
=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result 2010-03-08 10:00:20 +0000
+++ b/mysql-test/r/mysqld--help-win.result 2010-06-03 10:12:28 +0000
@@ -692,10 +692,7 @@ The following options may be given as th
How many threads we should keep in a cache for reuse
--thread-handling=name
Define threads usage for handling queries, one of
- one-thread-per-connection, no-threads, pool-of-threads
- --thread-pool-size=#
- How many threads we should create to handle query
- requests in case of 'thread_handling=pool-of-threads'
+ one-thread-per-connection, no-threads, loaded-dynamically
--thread-stack=# The stack size for each thread
--time-format=name The TIME format (ignored)
--timed-mutexes Specify whether to time mutexes (only InnoDB mutexes are
@@ -938,7 +935,6 @@ table-open-cache 400
tc-heuristic-recover COMMIT
thread-cache-size 0
thread-handling one-thread-per-connection
-thread-pool-size 16
thread-stack 262144
time-format %H:%i:%s
timed-mutexes FALSE
=== modified file 'mysql-test/suite/rpl/combinations'
--- a/mysql-test/suite/rpl/combinations 2008-09-05 13:31:09 +0000
+++ b/mysql-test/suite/rpl/combinations 2010-06-03 10:12:28 +0000
@@ -6,3 +6,18 @@ binlog-format=statement
[mix]
binlog-format=mixed
+
+[stmt-thread_pool]
+binlog-format=statement
+plugin-dir=../plugin/thread_pool/.libs
+plugin-load=thread_pool=thread_pool.so
+
+[mix-thread_pool]
+binlog-format=mix
+plugin-dir=../plugin/thread_pool/.libs
+plugin-load=thread_pool=thread_pool.so
+
+[row-thread_pool]
+binlog-format=row
+plugin-dir=../plugin/thread_pool/.libs
+plugin-load=thread_pool=thread_pool.so
=== modified file 'mysql-test/suite/sys_vars/r/thread_pool_size_basic.result'
--- a/mysql-test/suite/sys_vars/r/thread_pool_size_basic.result 2010-01-18 15:43:30 +0000
+++ b/mysql-test/suite/sys_vars/r/thread_pool_size_basic.result 2010-06-03 10:12:28 +0000
@@ -7,6 +7,10 @@ COUNT(@@GLOBAL.thread_pool_size)
SET @@GLOBAL.thread_pool_size=0;
ERROR HY000: Variable 'thread_pool_size' is a read only variable
Expected error ER_INCORRECT_GLOBAL_LOCAL_VAR
+# Set from command line in .opt file
+SELECT @@GLOBAL.thread_pool_size;
+@@GLOBAL.thread_pool_size
+12
SELECT COUNT(@@GLOBAL.thread_pool_size);
COUNT(@@GLOBAL.thread_pool_size)
1
=== added file 'mysql-test/suite/sys_vars/t/thread_pool_size_basic-master.opt'
--- a/mysql-test/suite/sys_vars/t/thread_pool_size_basic-master.opt 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/thread_pool_size_basic-master.opt 2010-06-03 10:12:28 +0000
@@ -0,0 +1,4 @@
+--plugin-dir=../plugin/thread_pool/.libs
+--plugin-load=thread_pool=thread_pool.so
+--thread-pool-size=12
+
=== modified file 'mysql-test/suite/sys_vars/t/thread_pool_size_basic.test'
--- a/mysql-test/suite/sys_vars/t/thread_pool_size_basic.test 2010-01-19 17:07:12 +0000
+++ b/mysql-test/suite/sys_vars/t/thread_pool_size_basic.test 2010-06-03 10:12:28 +0000
@@ -43,6 +43,9 @@ SET @@GLOBAL.thread_pool_size=0;
--ECHO Expected error ER_INCORRECT_GLOBAL_LOCAL_VAR
+--echo # Set from command line in .opt file
+SELECT @@GLOBAL.thread_pool_size;
+
SELECT COUNT(@@GLOBAL.thread_pool_size);
--echo 1 Expected
=== added directory 'plugin/thread_pool'
=== added file 'plugin/thread_pool/CMakeLists.txt'
--- a/plugin/thread_pool/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ b/plugin/thread_pool/CMakeLists.txt 2010-06-03 10:12:28 +0000
@@ -0,0 +1,16 @@
+# Copyright (C) Oracle
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+MYSQL_ADD_PLUGIN(thread_pool thread_pool.cc MODULE_ONLY)
=== added file 'plugin/thread_pool/Makefile.am'
--- a/plugin/thread_pool/Makefile.am 1970-01-01 00:00:00 +0000
+++ b/plugin/thread_pool/Makefile.am 2010-06-03 10:12:28 +0000
@@ -0,0 +1,33 @@
+# Copyright (C) 2006 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+## Makefile.am for thread pool
+
+pkgplugindir = $(pkglibdir)/plugin
+INCLUDES = -I$(top_srcdir)/include \
+ -I$(top_srcdir)/sql \
+ -I$(top_srcdir)/regex \
+ -I$(srcdir)
+
+noinst_HEADERS = thread_pool.h
+
+pkgplugin_LTLIBRARIES = thread_pool.la
+
+thread_pool_la_LDFLAGS = -module -rpath $(pkgplugindir) -L$(top_builddir)/libservices -lmysqlservices
+thread_pool_la_CXXFLAGS= $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+thread_pool_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+thread_pool_la_SOURCES = thread_pool_plugin.cc thread_pool.cc
+
+EXTRA_DIST= CMakeLists.txt plug.in poll.cc epoll.cc
=== renamed file 'sql/scheduler_epoll.ic' => 'plugin/thread_pool/epoll.ic'
--- a/sql/scheduler_epoll.ic 2010-03-01 11:18:18 +0000
+++ b/plugin/thread_pool/epoll.ic 2010-06-03 10:12:28 +0000
@@ -14,7 +14,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
- @file sql/scheduler_epoll.cc
+ @file
+
Pool of Threads low level using epoll (implementation).
*/
=== added file 'plugin/thread_pool/plug.in'
--- a/plugin/thread_pool/plug.in 1970-01-01 00:00:00 +0000
+++ b/plugin/thread_pool/plug.in 2010-06-03 10:12:28 +0000
@@ -0,0 +1,20 @@
+AC_CHECK_HEADERS(sys/epoll.h)
+
+# Check for Linux epoll(7).
+AC_MSG_CHECKING([for Linux epoll(7)])
+haveepoll=no
+AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes])
+AS_IF([test "x$haveepoll" = "xyes"],
+ [AC_DEFINE(HAVE_EPOLL, 1, [System supports the epoll(7) system calls])])
+
+# Check for Linux epoll(7). One Shot
+AC_MSG_CHECKING([for Linux epoll(7) support of EPOLLONESHOT])
+haveepolloneshot=no
+AC_CHECK_DECLS([EPOLLONESHOT], [], [], [[#include <sys/epoll.h>]])
+AS_IF([test "x$haveepoll" = "xyes"],
+ [AC_DEFINE(HAVE_EPOLLONESHOT, 1,
+ [System supports the epoll(7) system calls with EPOLLONESHOT])])
+
+MYSQL_PLUGIN(thread_pool,[Thread Pool Plugin],
+ [Thread Pool Plugin])
+MYSQL_PLUGIN_DYNAMIC(thread_pool, [thread_pool.la])
=== renamed file 'sql/scheduler_poll.ic' => 'plugin/thread_pool/poll.ic'
--- a/sql/scheduler_poll.ic 2010-03-01 11:18:18 +0000
+++ b/plugin/thread_pool/poll.ic 2010-06-03 10:12:28 +0000
@@ -14,7 +14,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
- @file sql/scheduler_poll.cc
+ @file
+
Pool of Threads low level using poll (implementation).
*/
=== renamed file 'sql/scheduler_thread_pool.cc' => 'plugin/thread_pool/thread_pool.cc'
--- a/sql/scheduler_thread_pool.cc 2010-03-04 15:07:01 +0000
+++ b/plugin/thread_pool/thread_pool.cc 2010-06-03 10:12:28 +0000
@@ -14,7 +14,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
- @file sql/scheduler_thread_pool.cc
+ @file
+
Pool of Threads - shared with poll() and epoll() versions (implementation).
*/
@@ -31,13 +32,12 @@
#define usleep(a) Sleep(max(1, a/1000))
#endif
+#define MYSQL_SERVER 1
#include <mysql_priv.h>
#include <my_global.h>
#include "probes_mysql.h"
#include "scheduler.h"
-#include "scheduler_thread_pool.h"
-
-#ifdef HAVE_POOL_OF_THREADS
+#include "thread_pool.h"
/*********************************************************************/
/* Defines */
@@ -496,6 +496,9 @@ clear_user_psi_env(THD *thd)
#define set_tp_psi_env() {}
#define clear_user_psi_env(thd) {}
#endif
+
+ulong thread_pool_size= 0;
+
/*********************************************************************/
/* Internal (private) Functions */
/*********************************************************************/
@@ -636,7 +639,7 @@ static inline void tp_thd_cleanup(THD *t
if (close)
close_connection(thd, errcode, 1);
- thd->scheduler.pool_of_threads_context= NULL;
+ thd->scheduler.data= NULL;
clear_user_psi_env(thd);
/*
@@ -686,6 +689,7 @@ static inline void tp_full_cleanup(THD *
init_process_count(my_tp_group, my_thread_data);
add_active_threads(my_tp_group, -1);
}
+ set_tp_psi_env(); // Set perfschema accounting to thread pool
tp_client_low_level_end(my_thread_data->client_low_level_cntx);
DBUG_VOID_RETURN;
}
@@ -762,7 +766,7 @@ static inline void thread_detach(THD* th
{
DBUG_ENTER("thread_detach");
DBUG_PRINT("enter",
- ("Detach connection id %d from thread group %d with client_cntx 0x%lx",
+ ("Detach connection id %lu from thread group %d with client_cntx 0x%lx",
thd->thread_id,
my_tp_group->group_idx,
(ulong)(my_thread_data->client_low_level_cntx)));
@@ -823,7 +827,7 @@ static void tp_process_event(tp_thread_t
thd= tp_client_low_level_get_thd(my_thread_data->client_low_level_cntx);
DBUG_PRINT("info",
- ("Process a query in thread group %d for connection id %d, using client_cntx 0x%lx",
+ ("Process a query in thread group %d for connection id %lu, using client_cntx 0x%lx",
my_tp_group->group_idx,
thd->thread_id,
(ulong)my_thread_data->client_low_level_cntx));
@@ -1707,12 +1711,9 @@ void thd_pool_end(void)
DBUG_ENTER("thd_pool_end");
- if (!have_thread_pool() ||
- tp_shutdown == 1)
- {
- /* Either have no thread pool or it hasn't been started */
+ if (tp_shutdown == 1)
DBUG_VOID_RETURN;
- }
+
tp_shutdown++;
self= pthread_self();
@@ -1796,11 +1797,6 @@ bool thd_pool_init(void)
tp_group_t *cur_group;
DBUG_ENTER("thd_pool_init");
- if (!have_thread_pool())
- DBUG_RETURN(FALSE);
-
- if (init_tp_psi_keys())
- DBUG_RETURN(FALSE);
tp_shutdown= 0;
if ((thread_pool_size > MAX_THREAD_GROUPS) || (thread_pool_size <= 0))
@@ -1994,18 +1990,17 @@ void thd_pool_add_connection(THD *thd)
*/
thd->net.reading_or_writing= 1;
- thd->scheduler.pool_of_threads_context= tp_client_low_level_init(
+ thd->scheduler.data= tp_client_low_level_init(
thd,
cur_group->group_low_level_cntx);
- DBUG_PRINT("info", ("Arming connection id %d", thd->thread_id));
- if (thd->scheduler.pool_of_threads_context != NULL)
+ DBUG_PRINT("info", ("Arming connection id %lu", thd->thread_id));
+ if (thd->scheduler.data != NULL)
{
if (tp_client_low_level_arm(
- (tp_client_low_level_t)thd->scheduler.pool_of_threads_context) != 0)
+ (tp_client_low_level_t)thd->scheduler.data) != 0)
{
sql_print_error("tp_client_low_level_arm() failed");
- tp_client_low_level_end(
- (tp_client_low_level_t)thd->scheduler.pool_of_threads_context);
+ tp_client_low_level_end((tp_client_low_level_t) thd->scheduler.data);
tp_thd_cleanup(thd, TRUE, TRUE, 0);
}
}
@@ -2046,13 +2041,13 @@ void thd_pool_post_kill_notification(THD
tp_client_low_level_t my_tp_client_low_level_cntx;
DBUG_ENTER("thd_pool_post_kill_notification");
- DBUG_PRINT("enter", ("close connection id %d",
+ DBUG_PRINT("enter", ("close connection id %lu",
thd->thread_id));
if (thd->net.vio != NULL)
{
my_tp_client_low_level_cntx=
- (tp_client_low_level_t)thd->scheduler.pool_of_threads_context;
+ (tp_client_low_level_t)thd->scheduler.data;
if (my_tp_client_low_level_cntx != NULL)
tp_client_low_level_close(my_tp_client_low_level_cntx);
}
@@ -2099,8 +2094,7 @@ void thd_pool_wait_begin(THD *thd, int w
DBUG_VOID_RETURN;
}
- my_tp_client_low_level_cntx=
- (tp_client_low_level_t)thd->scheduler.pool_of_threads_context;
+ my_tp_client_low_level_cntx= (tp_client_low_level_t) thd->scheduler.data;
if (my_tp_client_low_level_cntx != NULL)
{
@@ -2188,8 +2182,7 @@ void thd_pool_wait_end(THD *thd)
DBUG_VOID_RETURN;
}
- my_tp_client_low_level_cntx=
- (tp_client_low_level_t)thd->scheduler.pool_of_threads_context;
+ my_tp_client_low_level_cntx= (tp_client_low_level_t) thd->scheduler.data;
if (my_tp_client_low_level_cntx != NULL)
{
@@ -2215,9 +2208,9 @@ void thd_pool_wait_end(THD *thd)
}
#ifdef HAVE_EPOLL
-#include "scheduler_epoll.ic"
+#include "epoll.ic"
#else
-#include "scheduler_poll.ic"
+#include "poll.ic"
#endif
#ifndef DBUG_OFF
@@ -2433,4 +2426,3 @@ get_highest_priority_query(tp_group_t *m
DBUG_RETURN(client_cntx);
DBUG_RETURN(NULL);
}
-#endif
=== renamed file 'sql/scheduler_thread_pool.h' => 'plugin/thread_pool/thread_pool.h'
--- a/sql/scheduler_thread_pool.h 2010-03-01 11:18:18 +0000
+++ b/plugin/thread_pool/thread_pool.h 2010-06-03 10:12:28 +0000
@@ -17,11 +17,17 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
- @file sql/scheduler_thread_pool.h
+ @defgroup ThreadPool Thread Pool Scheduler
+ */
+
+/**@{*/
+
+/**
+ @file
+
Pool of Threads - shared with poll() and epoll() versions (definition).
*/
-#ifdef HAVE_POOL_OF_THREADS
/*
Results on an 8-way AMD box as of 2009 Nov
0x0001 << 4--> 16 groups ... works well in 2009 on 8 and 16 way CPUs
@@ -36,5 +42,9 @@ void thd_pool_post_kill_notification(THD
void thd_pool_wait_begin(THD *thd, int wait_type);
void thd_pool_wait_end(THD *thd);
void thd_pool_end(void);
-#endif
+
+extern ulong thread_pool_size;
+
+/**@}*/
+
#endif
=== added file 'plugin/thread_pool/thread_pool_plugin.cc'
--- a/plugin/thread_pool/thread_pool_plugin.cc 1970-01-01 00:00:00 +0000
+++ b/plugin/thread_pool/thread_pool_plugin.cc 2010-06-03 10:12:28 +0000
@@ -0,0 +1,120 @@
+/*
+ Copyright (C) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#define MYSQL_SERVER
+
+#include <mysql_priv.h>
+#include <mysql/plugin.h>
+#include <scheduler.h>
+#include "thread_pool.h"
+
+typedef struct st_mysql_sys_var SYS_VAR;
+
+/*
+ Pool of threads scheduler.
+
+ This is the scheduler we add if we have a pool of threads
+ implementation.
+
+ Linux: epoll
+ FreeBSD/Mac OS X: kqueue
+ Solaris: event_port
+ Windows: io completion ports (IOCP)
+*/
+
+static scheduler_functions pool_of_threads_scheduler=
+{
+ 0, // max_threads
+ thd_pool_init, // init
+ init_new_connection_handler_thread, // init_new_connection_thread
+ thd_pool_add_connection, // add_connection
+ thd_pool_wait_begin, // thd_wait_begin
+ thd_pool_wait_end, // thd_wait_end
+ NULL, // post_kill_notification
+ NULL, // end_thread
+ thd_pool_end, // end
+};
+
+/**
+ Thread pool initialization function.
+
+ Code to make this a daemon plugin. These plugins do not really do
+ anything, but it will allow options to be loaded and provide a value
+ to the thread scheduler.
+ */
+static int
+thread_pool_plugin_init(void *plugin __attribute__((unused)))
+{
+ DBUG_ENTER("thread_pool_plugin_init");
+ /*
+ We need to set this value dynamically since it is dependent on
+ what max_connections happens to have.
+ */
+ pool_of_threads_scheduler.max_threads=
+ max_connections + MAX_THREAD_GROUPS;
+ (void) thd_set_thread_scheduler(&pool_of_threads_scheduler);
+ DBUG_RETURN(0);
+}
+
+
+/**
+ Thread pool deinitialization function.
+ */
+static int thread_pool_plugin_deinit(void *ptr)
+{
+ DBUG_ENTER("thread_pool_plugin_deinit");
+ (void) thd_reset_thread_scheduler();
+ DBUG_RETURN(0);
+}
+
+
+static MYSQL_SYSVAR_ULONG(size, thread_pool_size,
+ PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG,
+ "How many threads we should create to handle query requests",
+ NULL, NULL, // check, update
+ 16, 1, 16384, 1); // def, min, max, blk
+
+static SYS_VAR* thread_pool_system_vars[]= {
+ MYSQL_SYSVAR(size),
+ NULL,
+};
+
+struct st_mysql_daemon thread_pool_plugin=
+{ MYSQL_DAEMON_INTERFACE_VERSION };
+
+
+/*
+ Plugin library descriptor
+*/
+
+mysql_declare_plugin(thread_pool)
+{
+ MYSQL_DAEMON_PLUGIN,
+ &thread_pool_plugin,
+ "thread_pool",
+ "Mikael Ronstrom, Kelly Long, Mats Kindahl", // What order should be used?
+ "Threads pool implementation to handle multiple connections for each thread",
+ PLUGIN_LICENSE_GPL,
+ thread_pool_plugin_init, /* plugin init */
+ thread_pool_plugin_deinit, /* plugin deinit */
+ 0x0009, /* 0.9: beta */
+ NULL, /* status variables */
+ thread_pool_system_vars, /* system variables */
+ NULL /* config options */
+}
+mysql_declare_plugin_end;
+
=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt 2010-03-08 10:00:20 +0000
+++ b/sql/CMakeLists.txt 2010-06-03 10:12:28 +0000
@@ -72,7 +72,7 @@ SET (SQL_SOURCE
sql_tablespace.cc events.cc ../sql-common/my_user.c
partition_info.cc rpl_utility.cc rpl_injector.cc sql_locale.cc
rpl_rli.cc rpl_mi.cc sql_servers.cc sql_audit.cc
- sql_connect.cc scheduler.cc scheduler_thread_pool.cc
+ sql_connect.cc scheduler.cc
sql_profile.cc event_parse_data.cc
sql_signal.cc rpl_handler.cc mdl.cc
transaction.cc sys_vars.cc
=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am 2010-03-08 10:00:20 +0000
+++ b/sql/Makefile.am 2010-06-03 10:12:28 +0000
@@ -34,7 +34,6 @@ DTRACEFILES = filesort.o \
mysqld.o \
net_serv.o \
scheduler.o \
- scheduler_thread_pool.o \
sp_head.o \
sql_cache.o \
sql_connect.o \
@@ -52,7 +51,6 @@ DTRACEFILES_DEPEND = filesort.o \
mysqld.o \
net_serv.o \
scheduler.o \
- scheduler_thread_pool.o \
sp_head.o \
sql_cache.o \
sql_connect.o \
@@ -108,7 +106,7 @@ noinst_HEADERS = item.h item_func.h item
tztime.h my_decimal.h keycaches.h \
sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \
parse_file.h sql_view.h sql_trigger.h \
- sql_array.h sql_cursor.h events.h scheduler.h scheduler_thread_pool.h \
+ sql_array.h sql_cursor.h events.h scheduler.h \
event_db_repository.h event_queue.h \
sql_plugin.h authors.h event_parse_data.h \
event_data_objects.h event_scheduler.h \
@@ -128,7 +126,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.
lock.cc my_lock.c \
sql_string.cc sql_manager.cc sql_map.cc \
main.cc mysqld.cc password.c hash_filo.cc hostname.cc \
- sql_connect.cc scheduler.cc scheduler_thread_pool.cc sql_parse.cc \
+ sql_connect.cc scheduler.cc sql_parse.cc \
keycaches.cc set_var.cc sql_yacc.yy sys_vars.cc \
sql_base.cc table.cc sql_select.cc sql_insert.cc \
sql_profile.cc \
@@ -190,7 +188,6 @@ BUILT_SOURCES = $(BUILT_MAINT_SRC) lex_
EXTRA_DIST = udf_example.c udf_example.def $(BUILT_MAINT_SRC) \
nt_servc.cc nt_servc.h \
message.mc message.h message.rc MSG00001.bin \
- scheduler_epoll.ic scheduler_poll.ic \
CMakeLists.txt
CLEANFILES = lex_hash.h sql_yacc.output link_sources
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h 2010-06-01 10:27:49 +0000
+++ b/sql/mysql_priv.h 2010-06-03 10:12:28 +0000
@@ -1921,7 +1921,7 @@ extern time_t server_start_time, flush_s
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
extern uint mysql_data_home_len, mysql_real_data_home_len;
extern const char *mysql_real_data_home_ptr;
-extern uint thread_handling;
+extern scheduler_types thread_handling;
extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
extern char server_version[SERVER_VERSION_LENGTH];
@@ -1990,7 +1990,7 @@ extern ulong binlog_cache_size, open_fil
extern ulonglong max_binlog_cache_size;
extern ulong max_binlog_size, max_relay_log_size;
extern ulong opt_binlog_rows_event_max_size;
-extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
+extern ulong rpl_recovery_rank, thread_cache_size;
extern ulong back_log;
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2010-06-01 10:27:49 +0000
+++ b/sql/mysqld.cc 2010-06-03 10:12:28 +0000
@@ -568,7 +568,7 @@ char *mysql_data_home= const_cast<char*>
const char *mysql_real_data_home_ptr= mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH];
char *mysqld_unix_port, *opt_mysql_tmpdir;
-uint thread_handling;
+scheduler_types thread_handling;
/** name of reference on left expression in rewritten IN subquery */
const char *in_left_expr_name= "<left expr>";
@@ -7544,9 +7544,6 @@ static int get_options(int *argc_ptr, ch
set_root(mysqld_chroot);
if (opt_bootstrap)
thread_handling= SCHEDULER_ONE_THREAD_PER_CONNECTION;
- if (thread_handling == SCHEDULER_POOL_OF_THREADS &&
- !have_thread_pool())
- thread_handling= SCHEDULER_ONE_THREAD_PER_CONNECTION;
#else
thread_handling = SCHEDULER_NO_THREADS;
max_allowed_packet= global_system_variables.max_allowed_packet;
=== modified file 'sql/scheduler.cc'
--- a/sql/scheduler.cc 2010-06-01 10:27:49 +0000
+++ b/sql/scheduler.cc 2010-06-03 10:12:28 +0000
@@ -142,7 +142,7 @@ thd_scheduler::~thd_scheduler()
}
static scheduler_functions *saved_thread_scheduler;
-static uint saved_thread_handling;
+static scheduler_types saved_thread_handling;
extern "C"
int my_thread_scheduler_set(scheduler_functions *scheduler)
=== modified file 'sql/scheduler.h'
--- a/sql/scheduler.h 2010-06-01 10:27:49 +0000
+++ b/sql/scheduler.h 2010-06-03 10:12:28 +0000
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/*
+/** @file
Classes for the thread scheduler
*/
@@ -24,26 +24,6 @@
#pragma interface
#endif
-#if !defined(EMBEDDED_LIBRARY)
-#if defined (HAVE_EPOLL) || defined (HAVE_POLL) || defined (_WIN32)
-# define HAVE_POOL_OF_THREADS 1
-#endif
-#endif
-
-#ifdef _WIN32
- bool have_thread_pool();
-#else
-inline bool
-have_thread_pool()
-{
-#ifdef HAVE_POOL_OF_THREADS
- return TRUE;
-#else
- return FALSE;
-#endif
-}
-#endif
-
class THD;
/* Functions used when manipulating threads */
@@ -84,12 +64,7 @@ enum scheduler_types
the first entry in this enum and the first entry in the
thread_handling_names array.
*/
-#ifdef HAVE_POOL_OF_THREADS
- SCHEDULER_POOL_OF_THREADS=0,
- SCHEDULER_ONE_THREAD_PER_CONNECTION,
-#else
SCHEDULER_ONE_THREAD_PER_CONNECTION=0,
-#endif
SCHEDULER_NO_THREADS,
SCHEDULER_TYPES_COUNT
};
Attachment: [text/bzr-bundle] bzr/mats.kindahl@oracle.com-20100603101228-2k0wfcg47qo3nxuj.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (mats.kindahl:3056) WL#5136 | Mats Kindahl | 3 Jun |