Messages in this thread | | | Date | 10 Jan 99 04:51:33 MET | From | lnxhkr <> | Subject | system freezing with 10 connections - 2.0.33 |
| |
hello,
I was testing some programming with unix sockets and I tested this program on a Linux machine and there seems to be a problem somewhere :
when I execute the following program "./prog localhost 19 >& log" the system freeze.
This program just connects 10 clients with the chargen service.
I was logging data to a file on the second drive and I noticed that both drives were running, the first drive contained the swap partition.
my config : Cyrix 120MHz, 16Mb Linux 2.0.33 #4 Thu Dec 17 21:49:45 MET 1998 i486 unknown gcc version 2.7.2.2 (this is a rtlinux patched kernel)
Is this normal ?
I have read in the apache docs : htdocs/manual/misc/perf.html
"The most common problem on Linux shows up on heavily-loaded systems where the whole server will appear to freeze for a couple of minutes at a time, and then come back to life. This has been traced to a listen() queue overload - certain Linux implementations have a low value set for the incoming connection queue which can cause problems. "
Are these problems related ?
On a faster machine you probably should increase MAX_TRIES as the machine doesn't freeze immediately after starting the program, it takes about 10-20 seconds to freeze (the drives still continue to run).
please CC your messages/comments to: lnxhkr@netscape.net
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdlib.h> #include <unistd.h>
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <sys/ioctl.h> #include <string.h> #include <errno.h>
#include <sys/time.h> #include <signal.h> #include <sys/types.h> #include <sys/wait.h>
/* * gcc -g -O -Wall -o prog prog.c * ./prog localhost 19 >& log */
#define NICHOST "localhost" #define MAX(a, b) ((a) > (b) ? (a) : (b))
typedef struct { char *host; int port; int socket; } ConnectionInfo;
#define NB_CLIENTS 10 #define MAX_TRIES 100000
int main(argc, argv) int argc; char **argv; { char *host; int port; int i,j,k; int maxsocket; ConnectionInfo Cinfo[NB_CLIENTS]; fd_set readfds; fd_set writefds; struct timeval tv; signal(SIGPIPE, SIG_IGN); if(argc> 1) host = argv[1]; else host = NICHOST; if(argc> 2) /* chargen 19/tcp echo 7/tcp */ port = atoi(argv[2]); else port = 19; maxsocket = 0; for(i=0;i<NB_CLIENTS;i++){ int socket; Cinfo[i].host = host; Cinfo[i].port = port; if( (socket = Connect(&(Cinfo[i]))) < 0) { printf("error on client %d\n", i); exit 0; } maxsocket = MAX(maxsocket, socket); /* Make the socket non-blocking */ ioctl(socket, FIONBIO, 1); } FD_ZERO(&readfds); FD_ZERO(&writefds); for(j=0;j<MAX_TRIES;j++){ /* for(;;){ */ for(i=0;i<NB_CLIENTS;i++){ FD_SET(Cinfo[i].socket, &readfds); FD_SET(Cinfo[i].socket, &writefds); } tv.tv_sec = 2; tv.tv_usec = 500000; if(select(maxsocket+1, &readfds, &writefds, NULL, &tv) == -1) { perror("select"); return 1; }
for(i=0;i<NB_CLIENTS;i++){ if(FD_ISSET(Cinfo[i].socket, &writefds)){ xsend(Cinfo[i].socket); } } for(i=0;i<NB_CLIENTS;i++){ if(FD_ISSET(Cinfo[i].socket, &readfds)){ if(xrecv(Cinfo[i].socket) < 0) close(Cinfo[i].socket); } }
} } int xsend(int s){ char buf[] = "test_test_test_test_test_test_test_test_test_test_"; int r; r = send(s,buf,strlen(buf),0); fprintf(stderr,"xsend socket %d\n", s); return r; }
int xrecv(int s){ char buf[101]; int r; r = recv(s,buf,100,0); if(r>0) { buf[100] = 0; fprintf(stderr,"xrecv socket %d: %s\n", s, buf); } else { if(r==0){ /* end of communication */ fprintf(stderr,"xrecv socket %d: error:%d\n", s, r); } else { /* error */ fprintf(stderr,"xrecv socket %d: error:%d\n", s, r); } } return r; }
int Connect(ConnectionInfo *Cinfo) { register FILE *sfi, *sfo; register int ch; struct sockaddr_in sin; struct hostent *hp; struct servent *sp; int s; char *host; int nb; int r; hp = gethostbyname(Cinfo->host); if (hp == NULL) { (void)fprintf(stderr, "prog: %s: ", Cinfo->host); herror((char *)NULL); return -1; }
host = hp->h_name; s = socket(hp->h_addrtype, SOCK_STREAM, 0); if (s < 0) { perror( "socket"); return -2; } bzero((caddr_t)&sin, sizeof (sin)); sin.sin_family = hp->h_addrtype; bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
/*sp = getservbyname("chargen", "tcp"); if (sp == NULL) { errx(1, "chargen/tcp: unknown service"); return -3; } */
sin.sin_port = htons(Cinfo->port) /* htons(80) */ /* sp->s_port */ ; if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { close(s); perror( "connect"); return -4; } Cinfo->socket = s; return s; }
____________________________________________________________________ More than just email--Get your FREE Netscape WebMail account today at http://home.netscape.com/netcenter/mail
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |