Re: question about 3sec timeouts with tcp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

Kind regards,
Leo

--

Here comes the test program:

/* START test program */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <netinet/tcp.h>
#include <netinet/in.h>

main() {

  /* edit Server and Port */
  char *server = "192.168.1.1";
  int port = 3306;

  int sock;
  int len;
  int flag;
  struct sockaddr_in sock_addr;
  int count = 0;
  struct timeval tim;

  while(1) {

     printf("%d\n", count);

     gettimeofday(&tim, NULL);
     double t1=tim.tv_sec+(tim.tv_usec/1000000.0);

     if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) {
        fprintf(stderr, "ERROR: cannot create socket\n");
        exit(1);
     }

     fcntl(sock, F_SETFL, O_RDONLY);
     fcntl(sock, F_GETFL);

     memset (&sock_addr, 0, sizeof (sock_addr));
     sock_addr.sin_family = AF_INET;
     sock_addr.sin_addr.s_addr = inet_addr (server);
     sock_addr.sin_port = htons (port);
     len = sizeof(sock_addr);

     if (connect(sock, (struct sockaddr *)&sock_addr, len) < 0) {
        fprintf(stderr, "ERROR: cannot connect to %s\n", server);
        continue;
     }

     flag = 8;
     setsockopt(sock, SOL_IP, IP_TOS, (char *) &flag, sizeof(int));
     flag = 1;
     setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &flag, sizeof(int));

     shutdown(sock, SHUT_RDWR);

     close(sock);

     gettimeofday(&tim, NULL);
     double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
     if ((t2-t1) > 1) {
        printf("%s: %.6lf seconds elapsed\n", server, t2-t1);
     }

     count++;

  }

}
/* END test program*/


Marlon de Boer wrote:
Hi list,

I'm trying to solve a problem with 3sec timeouts with tcp connections,we
are seeing these timeouts in both production and test environments. The
timeouts mainly occur from our webservers connecting to our mysql
backend. (about 450 webservers, connecting to somewhat 400 database
servers, serving 13 million pageviews per hour during busy hours).
--
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

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux