Re: Problem with BackLog (TCP Queue)..



On Mon, 07 Jan 2008 00:06:09 -0800, Chizl <Chizl@xxxxxxxxxxxxxx> wrote:

I'm building a web server and having some issues with the
TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using
MS Web Stress Tool to test against my web server and when I see 200
connections at once to it, and I'm seeing 2/3 of the sockets as socket
errors.. They never get into my code, so it has to be failing on the
connection side.. Backlog is the only thing I can think could be the
problem. this.svrListener.Start(1024); should be well over enough, but
with no param passed in Start or with 4096, it seems to be exactly the same.

Just off the top of my head...

My recollection is that the operation system has its own maximum backlog value. Trying to set the backlog above this value will result in either no effect, or setting to the maximum value. In neither case will you get the backlog you're asking for.

I'm not sure it's reasonable to expect that your code will always be able to handle some arbitrarily high number of simultaneous connection requests anyway.

One suggestion: in the code you posted, rather than having a thread sit and loop calling BeginAcceptSocket() over and over, just have the EndAcceptSocket() callback call it (and do so right away). The way the code is written now, you are guaranteed a thread switch between accepting one socket and being ready to accept another, and then of course another thread switch to accept the next one again. This is going to unnecessarily inhibit your throughput, artificially reducing the number of simultaneous connection requests you can process.

You have other performance-hindering design choices there as well:

* your accept callback really should be doing very little. If you have some heavyweight processing you want to do when accepting a client, you should handle that elsewhere if handling a large number of simultaneous connections is a priority for you. Otherwise, you get stuck with a thread that's doing something other than accepting connections.

* You should not be creating a new thread for each connection. Use the async i/o methods for the Socket class instead (e.g. BeginReceive). Using a thread for each connection you will unnecessarily limit the maximum number of connections you can handle -- the number of threads any given process can create is much lower than the number of sockets a process could theoretically handle -- and at the same hurt performance because of the constant thread context switches that will be required to deal with multiple active connections.

Pete
.



Relevant Pages

  • Asynchronous Socket Server data
    ... The socket server knows what type of data it expects due to the interface ... I can have 1 databuffer only for each datatype to handle multiple connections? ... int bytesRead = handler.EndReceive; ... packetIndex, bytesRead); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ping =?ISO-8859-1?Q?kr=E1ft=E9=E9_=3F_Advice_needed_?= =?ISO-8859-1?Q?to_trace_w
    ... He has two telephone extensions leading from the master socket and his ... presume that there is a fault in his extension wiring. ... If it's twisted pair ensure that it's not been connected split pair, in other words the blue white with white blue, orange white with white orange, if you get my drift, & the connections you should use are 2&5 ...
    (uk.telecom.broadband)
  • Re: !EventConnect Problem
    ... the June roll-up is available somewhere, although there's not been the usual ... The socket is not in a listening state. ... The incoming connection queue has no room for connections. ...
    (microsoft.public.windowsce.app.development)
  • Re: !EventConnect Problem
    ... the June roll-up is available somewhere, ... The socket is not in a listening state. ... The incoming connection queue has no room for connections. ...
    (microsoft.public.windowsce.app.development)
  • Re: What is the best way to stop a Socket.BeginAccept call?
    ... If you want a graceful exit, then stop accepting new connections, ... close all worker sockets, close the listener socket. ... public void AddSocketToList ...
    (microsoft.public.dotnet.languages.csharp)