Skip to content

Commit 2d6e230

Browse files
AliSQLAliSQL
authored andcommitted
[Feature] Issue#44 Thread pool
Description: ------------ Supply a new thread handing strategy that is pool-of-thread, one-thread-per-connection strategy will create many threads to service connections that clients requested. Not only it has low efficiency, but also cost much CPU time on context switch. Pool-of-thread only create limited threads to service all connections,and keep the throughput stable no matter how many connection requests.
1 parent 70ad701 commit 2d6e230

63 files changed

Lines changed: 9201 additions & 309 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/my_sys.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ typedef struct my_aio_result {
5252

5353
#define MY_INIT(name) { my_progname= name; my_init(); }
5454

55+
extern ulonglong my_interval_timer(void);
56+
#define microsecond_interval_timer() (my_interval_timer()/1000)
57+
5558
/**
5659
Max length of an error message generated by mysys utilities.
5760
Some mysys functions produce error messages. These mostly go

include/mysql/plugin_audit.h.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
THD_WAIT_BINLOG= 8,
4545
THD_WAIT_GROUP_COMMIT= 9,
4646
THD_WAIT_SYNC= 10,
47-
THD_WAIT_LAST= 11
47+
THD_WAIT_NET= 11,
48+
THD_WAIT_LAST= 12
4849
} thd_wait_type;
4950
extern struct thd_wait_service_st {
5051
void (*thd_wait_begin_func)(void*, int);

include/mysql/plugin_auth.h.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
THD_WAIT_BINLOG= 8,
4545
THD_WAIT_GROUP_COMMIT= 9,
4646
THD_WAIT_SYNC= 10,
47-
THD_WAIT_LAST= 11
47+
THD_WAIT_NET= 11,
48+
THD_WAIT_LAST= 12
4849
} thd_wait_type;
4950
extern struct thd_wait_service_st {
5051
void (*thd_wait_begin_func)(void*, int);

include/mysql/plugin_ftparser.h.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
THD_WAIT_BINLOG= 8,
4545
THD_WAIT_GROUP_COMMIT= 9,
4646
THD_WAIT_SYNC= 10,
47-
THD_WAIT_LAST= 11
47+
THD_WAIT_NET= 11,
48+
THD_WAIT_LAST= 12
4849
} thd_wait_type;
4950
extern struct thd_wait_service_st {
5051
void (*thd_wait_begin_func)(void*, int);

include/mysql/service_thd_wait.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ typedef enum _thd_wait_type_e {
7474
THD_WAIT_BINLOG= 8,
7575
THD_WAIT_GROUP_COMMIT= 9,
7676
THD_WAIT_SYNC= 10,
77-
THD_WAIT_LAST= 11
77+
THD_WAIT_NET= 11,
78+
THD_WAIT_LAST= 12
7879
} thd_wait_type;
7980

8081
extern struct thd_wait_service_st {

include/mysql/thread_pool_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void end_connection(THD *thd);
107107
/* Release resources of the THD object */
108108
void thd_release_resources(THD *thd);
109109
/* Decrement connection counter */
110-
void dec_connection_count();
110+
void dec_connection_count(THD *thd);
111111
/* Destroy THD object */
112112
void destroy_thd(THD *thd);
113113
/* Remove the THD from the set of global threads. */

include/violite.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Vio* vio_new_win32shared_memory(HANDLE handle_file_map,
7474

7575
void vio_delete(Vio* vio);
7676
int vio_shutdown(Vio* vio);
77+
int vio_cancel(Vio* vio, int how);
7778
my_bool vio_reset(Vio* vio, enum enum_vio_type type,
7879
my_socket sd, void *ssl, uint flags);
7980
size_t vio_read(Vio *vio, uchar * buf, size_t size);
@@ -105,6 +106,8 @@ ssize_t vio_pending(Vio *vio);
105106
#endif
106107
/* Set timeout for a network operation. */
107108
int vio_timeout(Vio *vio, uint which, int timeout_sec);
109+
extern void vio_set_wait_callback(void (*before_wait)(void),
110+
void (*after_wait)(void));
108111
/* Connect to a peer. */
109112
my_bool vio_socket_connect(Vio *vio, struct sockaddr *addr, socklen_t len,
110113
int timeout);
@@ -190,6 +193,7 @@ void vio_end(void);
190193
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
191194
#define vio_should_retry(vio) (vio)->should_retry(vio)
192195
#define vio_was_timeout(vio) (vio)->was_timeout(vio)
196+
#define vio_cancel(vio, how) ((vio)->viocancel)(vio, how)
193197
#define vio_shutdown(vio) ((vio)->vioshutdown)(vio)
194198
#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
195199
#define vio_io_wait(vio, event, timeout) (vio)->io_wait(vio, event, timeout)
@@ -256,6 +260,7 @@ struct st_vio
256260
descriptors, handles can remain valid after a shutdown.
257261
*/
258262
int (*vioshutdown)(Vio*);
263+
int (*viocancel)(Vio*, int);
259264
my_bool (*is_connected)(Vio*);
260265
my_bool (*has_data) (Vio*);
261266
int (*io_wait)(Vio*, enum enum_vio_io_event, int);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- require r/have_pool_of_threads.require
2+
disable_query_log;
3+
show variables like 'thread_handling';
4+
enable_query_log;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Variable_name Value
2+
thread_handling pool-of-threads

mysql-test/r/information_schema-big.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SCHEMATA SCHEMA_NAME
4343
SCHEMA_PRIVILEGES TABLE_SCHEMA
4444
SESSION_STATUS VARIABLE_NAME
4545
SESSION_VARIABLES VARIABLE_NAME
46+
SQL_FILTER_INFO TYPE
4647
STATISTICS TABLE_SCHEMA
4748
TABLES TABLE_SCHEMA
4849
TABLESPACES TABLESPACE_NAME
@@ -51,6 +52,15 @@ TABLE_PRIVILEGES TABLE_SCHEMA
5152
TRIGGERS TRIGGER_SCHEMA
5253
USER_PRIVILEGES GRANTEE
5354
VIEWS TABLE_SCHEMA
55+
TABLE_STATISTICS TABLE_SCHEMA
56+
INDEX_STATISTICS TABLE_SCHEMA
57+
THREAD_GROUP_STATUS ID
58+
TokuDB_file_map table_schema
59+
TokuDB_trx trx_id
60+
TokuDB_locks locks_table_schema
61+
TokuDB_lock_waits lock_waits_table_schema
62+
TokuDB_fractal_tree_block_map table_schema
63+
TokuDB_fractal_tree_info table_schema
5464
SELECT t.table_name, c1.column_name
5565
FROM information_schema.tables t
5666
INNER JOIN
@@ -91,6 +101,7 @@ SCHEMATA SCHEMA_NAME
91101
SCHEMA_PRIVILEGES TABLE_SCHEMA
92102
SESSION_STATUS VARIABLE_NAME
93103
SESSION_VARIABLES VARIABLE_NAME
104+
SQL_FILTER_INFO TYPE
94105
STATISTICS TABLE_SCHEMA
95106
TABLES TABLE_SCHEMA
96107
TABLESPACES TABLESPACE_NAME
@@ -99,3 +110,12 @@ TABLE_PRIVILEGES TABLE_SCHEMA
99110
TRIGGERS TRIGGER_SCHEMA
100111
USER_PRIVILEGES GRANTEE
101112
VIEWS TABLE_SCHEMA
113+
TABLE_STATISTICS TABLE_SCHEMA
114+
INDEX_STATISTICS TABLE_SCHEMA
115+
THREAD_GROUP_STATUS ID
116+
TokuDB_file_map table_schema
117+
TokuDB_trx trx_id
118+
TokuDB_locks locks_table_schema
119+
TokuDB_lock_waits lock_waits_table_schema
120+
TokuDB_fractal_tree_block_map table_schema
121+
TokuDB_fractal_tree_info table_schema

0 commit comments

Comments
 (0)