Re: Some more info about CONNECT/ACCEPT problem.

From: Peter Zaitsev (pz@spylog.ru)
Date: Sat Apr 08 2000 - 00:11:57 EST


> You do realise there is some unexpected behavior in your program?
> Instead of creating 200 threads, you create 200! threads.
>
> You basically do
>
> for (t=0;t<200;t++) {
> fork();
> }

No. I bassicaly do a little bit different thing
for(t=0;t<200;t++)
 if (fork()=0)
   {
     /* Do some work in Sun Here */
    return 0; /* Exit */
    }

>
> So you get this
>
> t number of threads
> 0 1
> 1 2
> 2 4
> 3 8
> etc
>
> The load on my system went through the roof.....
May be this is because you tried to run in on localhost - so You got
200client+200server process almost 200 of which was ready to run... This is
bad for 2.2 kernel :(
I just added some more output to the program - can you see what numbers for
connect time you program will return ?

The interesting thing is Ig got number of long connects almost the same for
each thread, depending on connection,nymber of process and other it may vary
from several persent to up to 20.

----------------------------------------------------------------------------
-------------------
#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <strings.h>
#include <unistd.h>

#define CONNECTS 1000
#define PROCESSES 50
#define LONG_CONNECT 1
#define HOST "212.24.53.193"
#define PORT 80

main()
 {
  int sock;
  int t,i;
  int res;
  int c;
  int tm;
  int total;
  int fast=0,sec3=0,sec9=0,sec21=0,sec45=0,other=0;
  struct sockaddr_in serv_addr;
  struct hostent *hp;
  for(t=0;t<PROCESSES;t++)
   if (fork()==0)
    {
     // Here we have the process forked.
     hp=gethostbyname(HOST);
     if (hp==NULL) printf("Lookup failed !");
     total=time(NULL);
     for(c=0;c<CONNECTS;c++)
     {
      tm=time(NULL);
      i=socket(PF_INET,SOCK_STREAM,0);
      if (i==-1) printf("Can't create socket: %d\n",errno);
      bzero(&serv_addr,sizeof(serv_addr));
      bcopy(hp->h_addr,&serv_addr.sin_addr, hp->h_length);
      serv_addr.sin_family=hp->h_addrtype;
      serv_addr.sin_port=htons(PORT);
      res=connect(i,&serv_addr,sizeof(serv_addr));
      if (res==-1)

                     printf("Error while connecting: %d\n",errno);
                     return 0;
                   }
      close(i);
      tm=time(NULL)-tm;
      if (tm>LONG_CONNECT) // two seconds FRESHHOLD
        {
         if (tm=3) sec3++;
          else
           if (tm=9) sec9++;
            else
             if(tm=21) sec21++;
            else
             if (tm=45) sec45++;
              else other++;
// printf("Long connect time: %d\n",tm);
        }
       else fast++;
      }
      total=time(NULL)-total;
      printf("Total time spent for connecting: %d\n",total);
      printf("Times: fast:%d 3sec:%d 9sec:%d 21sec:%d 45sec:%d
other:%d\n",fast,sec3,sec9,sec21,sec45,other);
     return 0;
    }
 }

-
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/



This archive was generated by hypermail 2b29 : Sat Apr 15 2000 - 21:00:11 EST