From c5eb1f2ca10af8c33fabddcf5e90685db7633eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 9 Aug 2015 21:13:59 +0000 Subject: [PATCH] Random delay before accept() --- lib/MySQL_Thread.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index aafe9871b..b26e13e2c 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1532,6 +1532,10 @@ void MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *myds, unsig struct sockaddr *addr=(struct sockaddr *)malloc(sizeof(struct sockaddr)); socklen_t addrlen=sizeof(struct sockaddr); memset(addr, 0, sizeof(struct sockaddr)); + if (GloMTH->num_threads > 1) { + // there are more than 1 thread . We pause for a little bit to avoid all connections to be handled by the same thread + usleep(50+rand()%50); + } c=accept(myds->fd, addr, &addrlen); if (c>-1) { // accept() succeeded // create a new client connection