delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/14/13:59:43

X-Spam-Check-By: sourceware.org
X-AntiVirus: PTMail-AV 0.3.88
X-Virus-Status: Clean (0.01936 seconds)
Mime-Version: 1.0 (Apple Message framework v746.3)
In-Reply-To: <20060311181653.GA10054@trixie.casa.cgf.cx>
References: <1753CE61-D772-46F7-8393-84E419E49307 AT ptnix DOT com> <4412EF74 DOT 1070500 AT byu DOT net> <890F74C6-8E51-405F-86CC-551170A2EA70 AT honeynet-pt DOT org> <20060311181653 DOT GA10054 AT trixie DOT casa DOT cgf DOT cx>
Message-Id: <F8A4659D-D483-4219-9EAF-7698FFC5A938@honeynet-pt.org>
From: Pedro Inacio <pedro DOT inacio AT honeynet-pt DOT org>
Subject: Re: select() too slow
Date: Tue, 14 Mar 2006 18:59:28 +0000
To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Note-from-DJ: This may be spam

--Apple-Mail-1-846811584
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=WINDOWS-1252;
	delsp=yes;
	format=flowed

Hello again,

as promised attached you will find a very simplistic non-blocking=20=20
echo server that compiles on Linux and Cygwin.
The main objective is that you compile it and run on both environments.
Of course that the same hardware is recommended in order to compare=20=20
the results in a more accurate way.

After compile and run it, on a different machine you do something like:

$ time cat big_file | nc =96w 1 echo_server_ip_address port > dest_file

On my test a big_file of 100 mb toke 22 seconds on Linux and 4=20=20
minutes on Cygwin.

This is my problem, why it takes so much more time on Cygwin?
There is any obvious wrong thing I'm doing?
It seems to be a select() problem.

Thanks in advance,

Pedro Inacio

--Apple-Mail-1-846811584
Content-Transfer-Encoding: quoted-printable
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="echo_server.c"
Content-Disposition: attachment;
	filename=echo_server.c

#include <stdio.h>=0D
#include <stdlib.h>=0D
#include <unistd.h>=0D
#include <string.h>=0D
#include <errno.h>=0D
#include <sys/types.h>=0D
#include <sys/socket.h>=0D
#include <netinet/in.h>=0D
#include <sys/select.h>=0D
#include <fcntl.h>=0D
=0D
=0D
#define PORT 12345=0D
=0D
#define BUFFER_SIZE 1024=0D
                                     =0D
=0D
int main(void) {=0D
  char buffer[BUFFER_SIZE];=0D
  struct sockaddr_in server_addr;=0D
  struct sockaddr_in client_addr;=0D
  int server_fd, client_fd, client_len;=0D
  fd_set read_fds, write_fds;=0D
  int r, bytes =3D 0;=0D
  int in =3D 1, out =3D 0; =0D
  int offset =3D 0;=0D
=0D
=0D
  memset(&server_addr, 0, sizeof(server_addr));=0D
  server_addr.sin_family =3D AF_INET;=0D
  server_addr.sin_port =3D htons(PORT);=0D
  server_addr.sin_addr.s_addr =3D INADDR_ANY;=0D
=0D
  if((server_fd =3D socket(AF_INET, SOCK_STREAM, 0)) < 0)=0D
  {=0D
    printf("Can't create socket\n");=0D
    exit(0);=0D
  }=0D
=0D
  if(bind(server_fd, (struct sockaddr *) &server_addr, sizeof(server_addr))=
 < 0)=0D
  {=0D
    printf("Can't bind socket\n");=0D
    exit(0);=0D
  }=0D
  =0D
  if(listen(server_fd, 1) < 0)=0D
  {=0D
    printf("Can't listen on socket\n");=0D
    exit(0);=0D
  }=0D
=0D
  client_len =3D sizeof(client_addr);=0D
  client_fd =3D accept(server_fd, (struct sockaddr *) &client_addr, &client=
_len);=0D
=0D
  if(client_fd < 0)=0D
  {=0D
    printf("Can't accept connection\n");=0D
    exit(0);=0D
  }=0D
 =0D
  close(server_fd);=0D
=0D
  fcntl(client_fd, F_SETFL, fcntl(client_fd, F_GETFL) | O_NONBLOCK);=0D
=0D
  while(1) {=0D
    FD_ZERO(&read_fds);=0D
    FD_ZERO(&write_fds);=0D
=0D
=0D
    if (in)=0D
      FD_SET(client_fd, &read_fds);=0D
=0D
    if (out)=0D
      FD_SET(client_fd, &write_fds);=0D
=0D
    r =3D select(client_fd + 1, &read_fds, &write_fds, NULL, NULL);=0D
=0D
    if (r < 0) =0D
    {=0D
      if (errno =3D=3D EINTR) =0D
        continue;=0D
      goto END;=0D
    }=0D
=0D
    if (FD_ISSET(client_fd, &read_fds))=0D
    {=0D
      bytes =3D read(client_fd, buffer, BUFFER_SIZE);=0D
      offset =3D 0;=0D
=0D
      if (bytes <=3D 0)=0D
      {=0D
        goto END;=0D
      }=0D
      else=0D
        FD_SET(client_fd, &write_fds);=0D
    }=0D
=0D
    if (FD_ISSET(client_fd, &write_fds))=0D
    {=0D
      r =3D write(client_fd, buffer + offset, bytes);=0D
      offset +=3D r; =0D
      bytes -=3D r;=0D
=0D
      if (bytes =3D=3D 0)=0D
      {=0D
        in =3D 1;=0D
        out =3D 0;=0D
      }=0D
      else=0D
      {=0D
        in =3D 0;=0D
        out =3D 1;=0D
      }=0D
    }=0D
  }=0D
=0D
END:=0D
=0D
  close(client_fd);=0D
=0D
  printf("Finished...\n");=0D
=0D
  return 0;=0D
}=0D

--Apple-Mail-1-846811584
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed


On 2006/03/11, at 18:16, Christopher Faylor wrote:

> On Sat, Mar 11, 2006 at 06:04:37PM +0000, Pedro Inacio wrote:
>> On 2006/03/11, at 15:40, Eric Blake wrote:
>>
>>>
>>> I'm afraid that this is not a very good bug report, as you have not
>>> attempted to describe WHAT is too slow, and have not provided a  
>>> simple
>>> test case that compiles out of the box, with timing numbers on the
>>> test
>>> case compared between Linux and Cygwin.  Cygwin is only as fast  
>>> as the
>>> underlying Windows system calls permit it to be.  Also, cygwin is  
>>> open
>>> source.  Go look at the source code to select() and you will see
>>> that it
>>> is very complex, since Windows does not provide good hooks for an
>>> efficient implementation.  If you would like it to be faster, then
>>> consider writing a patch to cygwin that can speed it up.
>>
>> first of all this is not a bug report, but just trying to understand
>> what might be the problem.  If I knew what the problem is I was not
>> asking if there is any known issue, a fix, or something.  I've  
>> read the
>> archives before posting and there are some guys with similar problems
>> but no answers.
>
> But we don't know what the actual problem *is*.  What does "too slow"
> mean?  select takes an extra twenty milliseconds under Cygwin?   
> select doesn't
> respond within 24 hours?
>
> You are apparently a programmer because you know about select().   
> Think
> of this from the point of view of someone reporting a problem with  
> your
> software.  Wouldn't you ask them for more details if the bug report  
> was
> merely "Your program is slow?"
>
>> I know that the select() function on windows is quite different
>
> It is different to the point of being nonexistent -- except for  
> sockets.
>
>> and not very handy.  One thing is weird for sure, similar code works
>> just fine on Unix but is not very performante on Windows.
>
> Whether it is a bug report or not, you haven't given enough details  
> for
> anyone to comprehend what you are talking about.
>
> Your email seems to have been sent with an understanding that everyone
> will just automatically understand what you're talking about.  That
> is not the case.  You can't take shortcuts to describing a problem if
> you truly want help.  You haven't provided enough information to even
> provide a WAG.
>
> cgf
>
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
>



--Apple-Mail-1-846811584
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--Apple-Mail-1-846811584--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019