Re: question about 3sec timeouts with tcp

From: Marlon de Boer
Date: Fri Mar 28 2008 - 11:14:52 EST


Leo wrote:
> We discovered the same problem two month ago (even 3 sec connect
> problems between webserver and mysql backend). I have posted it to
> the list (subject "TCP connect hangs for 3 seconds", 2008-02-04)
> but didn't get any answer yet. When I read your mail it was a
> flicker of hope.
>
> This is not a mysql issue! You can easily reproduce it with a few
> lines of C code (see below, it's similar to your program) running
> against any open port on the server (e.g. netcat: nc -k -l
> <PORTNUMBER>). We have also tested it on different hardware and
> kernel versions (up to 2.6.24.4) and we can deliver further
> information if requested ...
>
> Unfortunately the kernel parameter you mentioned in your second
> mail (net.core.somaxconn) didn't solve the problem.
>
> I think there are many other people out there having this problem
> unconsciously. Can anybody help?
>
I used the c code below to test the server side. After playing with
the kernel settings, some code,
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) and
listen(sd, 8192) the timeouts disappeared.

Did you changed the settings in mysql.cnf? back_log = 8192, and
restarted the mysql daemon? Else try to raise it to 16384 or even higher.

Regards
Marlon

#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <resolv.h>
#include <pthread.h>
#include <netdb.h>

int main(int count, char *args[])
{ struct sockaddr_in addr;
int sd, port;

if ( count != 2 )
{
printf("usage: %s <protocol or portnum>\n", args[0]);
exit(0);
}

/*---Get server's IP and standard service connection--*/
if ( !isdigit(args[1][0]) )
{
struct servent *srv = getservbyname(args[1], "tcp");
if ( srv == NULL )
{
perror("srv");
exit(1);
}
printf("%s: port=%d\n", srv->s_name, ntohs(srv->s_port));
port = srv->s_port;
}
else
port = htons(atoi(args[1]));

/*--- create socket ---*/
sd = socket(PF_INET, SOCK_STREAM, 0);
if ( sd < 0 ) {
perror("socket");
exit(1);
}

int opt = 1;

if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &opt,
sizeof(opt)) == -1)
{
perror("sock_opt_reuse");
exit(1);
}

/*--- bind port/address to socket ---*/
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = port;
addr.sin_addr.s_addr = INADDR_ANY; /* any
interface */
if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
{
perror("bind");
exit(1);
}

if ( listen(sd, 8192) != 0 )
{
perror("listen");
exit(1);
}
else
{ int sf;

while (1) /* process all
incoming clients */
{
sf = accept(sd, 0, 0); /* accept connection */
shutdown(sf, SHUT_RDWR);
close(sf);
}
}
}


--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html