1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-22990 Threadpool : Optimize network/named pipe IO for Windows

This patch reduces the overhead of system calls prior to a query, for
threadpool.  Previously, 3 system calls were done

1. WSARecv() to get notification of input data from client, asynchronous
equivalent of select() in one-thread-per-connection

2. recv(4 bytes) - reading packet header length
3. recv(packet payload)

Now there will be usually, just WSARecv(), which pre-reads user data into
a buffer, so we spared 2 syscalls

Profiler shows the most expensive call WSARecv(16%CPU) becomes 4% CPU,
after the patch, benchmark results (network heavy ones like point-select)
improve by ~20%

The buffer management was rather carefully done to keep
buffers together, as Windows would keeps the pages pinned
in memory for the duration of async calls.
At most 1MB memory is used for the buffers, and overhead per-connection is
only 256 bytes, which should cover most of the uses.

SSL does not yet use the optmization, so far it does not properly use
VIO for reads and writes. Neither one-thread-per-connection would get any
benefit, but that should be fine, it is not even default on Windows.
This commit is contained in:
Vladislav Vaintroub
2020-06-26 14:43:56 +02:00
parent b3acad4a48
commit d15c839c0d
9 changed files with 449 additions and 169 deletions

View File

@ -28,6 +28,10 @@
#include "wsrep_trans_observer.h"
#endif /* WITH_WSREP */
#ifdef _WIN32
#include "threadpool_winsockets.h"
#endif
/* Threadpool parameters */
uint threadpool_min_threads;
@ -48,7 +52,7 @@ TP_STATISTICS tp_stats;
static void threadpool_remove_connection(THD *thd);
static int threadpool_process_request(THD *thd);
static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data);
static THD* threadpool_add_connection(CONNECT *connect, TP_connection *c);
extern bool do_command(THD*);
@ -221,7 +225,7 @@ error:
}
static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data)
static THD *threadpool_add_connection(CONNECT *connect, TP_connection *c)
{
THD *thd= NULL;
@ -243,9 +247,10 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data)
return NULL;
}
delete connect;
server_threads.insert(thd);
thd->set_mysys_var(mysys_var);
thd->event_scheduler.data= scheduler_data;
thd->event_scheduler.data = c;
/* Login. */
thread_attach(thd);
@ -260,6 +265,8 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data)
if (thd_prepare_connection(thd))
goto end;
c->init_vio(thd->net.vio);
/*
Check if THD is ok, as prepare_new_connection_state()
can fail, for example if init command failed.
@ -397,6 +404,9 @@ static bool tp_init()
pool= 0;
return true;
}
#ifdef _WIN32
init_win_aio_buffers(max_connections);
#endif
return false;
}
@ -484,6 +494,9 @@ static void tp_wait_end(THD *thd)
static void tp_end()
{
delete pool;
#ifdef _WIN32
destroy_win_aio_buffers();
#endif
}
static void tp_post_kill_notification(THD *thd)