Commit 5d183df7 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Try accept a few times before falling back to poll

Gives ~3% throughput improvemet in sysbench connect benchmark.

Part of MDEV-19515 - Improve connect speed
parent 87775402
...@@ -6375,7 +6375,6 @@ static void set_non_blocking_if_supported(MYSQL_SOCKET sock) ...@@ -6375,7 +6375,6 @@ static void set_non_blocking_if_supported(MYSQL_SOCKET sock)
void handle_connections_sockets() void handle_connections_sockets()
{ {
MYSQL_SOCKET sock= mysql_socket_invalid(); MYSQL_SOCKET sock= mysql_socket_invalid();
MYSQL_SOCKET new_sock= mysql_socket_invalid();
uint error_count=0; uint error_count=0;
struct sockaddr_storage cAddr; struct sockaddr_storage cAddr;
int retval; int retval;
...@@ -6467,29 +6466,28 @@ void handle_connections_sockets() ...@@ -6467,29 +6466,28 @@ void handle_connections_sockets()
for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++) for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
{ {
size_socket length= sizeof(struct sockaddr_storage); size_socket length= sizeof(struct sockaddr_storage);
MYSQL_SOCKET new_sock;
new_sock= mysql_socket_accept(key_socket_client_connection, sock, new_sock= mysql_socket_accept(key_socket_client_connection, sock,
(struct sockaddr *)(&cAddr), (struct sockaddr *)(&cAddr),
&length); &length);
if (mysql_socket_getfd(new_sock) != INVALID_SOCKET || if (mysql_socket_getfd(new_sock) != INVALID_SOCKET)
(socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN)) handle_accepted_socket(new_sock, sock);
break; else if (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN)
} {
/*
if (mysql_socket_getfd(new_sock) == INVALID_SOCKET) accept(2) failed on the listening port.
{ There is not much details to report about the client,
/* increment the server global status variable.
accept(2) failed on the listening port, after many retries. */
There is not much details to report about the client, statistic_increment(connection_errors_accept, &LOCK_status);
increment the server global status variable. if ((error_count++ & 255) == 0) // This can happen often
*/ sql_perror("Error in accept");
statistic_increment(connection_errors_accept, &LOCK_status); if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE)
if ((error_count++ & 255) == 0) // This can happen often sleep(1); // Give other threads some time
sql_perror("Error in accept"); break;
if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE) }
sleep(1); // Give other threads some time
continue;
} }
handle_accepted_socket(new_sock, sock);
} }
sd_notify(0, "STOPPING=1\n" sd_notify(0, "STOPPING=1\n"
"STATUS=Shutdown in progress\n"); "STATUS=Shutdown in progress\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment