Re: Buffer Pooling?

From: David Browne (meat_at_hotmail.com)
Date: 05/05/04


Date: Wed, 5 May 2004 10:03:10 -0500


"MIke" <anonymous@discussions.microsoft.com> wrote in message
news:882b01c432a3$724c2f30$a401280a@phx.gbl...
> Hi, I'm writing a server that is using asynchronous IO. I
> need this server to be scalable and fast. But how do I
> implement the send and recieve buffers in an efficient
> way?
>
> If I just allocate the memory on the fly, there's no way
> to explicitly free it up, so all of these large buffers
> will be floating around until the GC runs. This might be
> okay for 100 or so connections, but 1000? I don't think
> it would.
>
. . .
>
> ARGH! Where is .NET when you need it! What are your
> thoughts?
>

Use per-thread buffers, and do it the easy way with the ThreadStatic
attribute.

in C#

[ThreadStatic()]
private static byte[] buf;

private static byte[] getBuf()
{
  if (buf == null)
  {
    buf = new byte[1024*10];
  }
  return buf;
}

will allocate a seperate 10k buffer for each thread.

David



Relevant Pages

  • Re: Buffer Pooling?
    ... >Use per-thread buffers, and do it the easy way with the ... >> need this server to be scalable and fast. ... >> implement the send and recieve buffers in an efficient ... >will allocate a seperate 10k buffer for each thread. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: [NFS] NFS on loopback locks up entire system(2.6.23-rc6)?
    ... if one of the NFS server/mount goes offline for ... I have turned off the NFS server and started another dd process ... I see only about 550MB in buffers, rest all is pretty much available. ... file systems like VxFS use their own buffer cache different from ...
    (Linux-Kernel)
  • RE: AW: BUFFERS on Solaris-Box
    ... You are running a very old patch level of Solaris - install the latest 9_Recommended patch cluster. ... It won't help you with this issue, but good from a server management perspective:) ... Subject: AW: BUFFERS on Solaris-Box ... > monitor. ...
    (comp.databases.informix)
  • Re: Socket switch delay
    ... buffers are queued and will be later sent. ... socket, not sure about a blocking socket. ... >>(and I noticed you don't do overlapped receive at the server!) ... > optional in the client too). ...
    (microsoft.public.win32.programmer.networks)
  • Re: 1 file, multiple threads
    ... >only one) thread while reading the file in multiple other threads. ... buffers both before and after any file access. ... Much simpler to designate a single file-handler 'server', ...
    (comp.lang.python)