[Mono-bugs] [Bug 644428] New: Mono creates new thread for each call to Socket.xxxAsync

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Oct 7 00:14:25 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=644428

https://bugzilla.novell.com/show_bug.cgi?id=644428#c0


           Summary: Mono creates new thread for each call to
                    Socket.xxxAsync
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.8.x
          Platform: All
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tobias.peciva at kaseya.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development
           Blocker: No


Description of Problem:
In .NET 3.5, Microsoft introduced the SocketAsyncEventArgs (SAEA) mechanism in
System.Net.Sockets. The idea was to improve performance for socket servers with
very high throughput, primarily by reusing SAEA objects instead of reallocating
and garbage collecting EventArgs objects for every send/receive/accept request.
The mechanism is outlined here:
http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx

Here's a variation:
http://www.codeproject.com/KB/IP/socketasynceventargssampl.aspx

We have tested this on Windows with .NET 3.5 and 4.0, and it does indeed offer
very high throughput with minimal GC activity. However, under Mono (we use
Ubuntu 64, but this probably applies to all platforms), SAEA performance is
weak. The reason for this appears to be that for every single
SendAsync/ReceiveAsync/AcceptAsync request, Mono creates a new thread. So in
other words, if you have 1,000 clients connected, and you're waiting for data
from all of them, you'll have 1,000 threads.

This is particularly problematic for servers that need to support a large
number of concurrently connected clients, such as XMPP servers (XMPP servers
commonly support 100k+ concurrent clients, with some going as high as 500k+).


Steps to reproduce the problem:
1. Build the sample code provided in the links above.
2. Create a test client that makes e.g. 10k concurrent connections to the
server.
3. Use e.g. "top" to review the number of running threads on the server.


Actual Results:
Mono appears to have as many threads as open connections - plus a few. For
1,000 threads, it's still possible to get somewhat acceptable performance. But
for 20k or more, our Ubuntu 64 systems grind to a halt and become practically
unusable.


Expected Results:
>From our testing, the Windows SAEA implementation can easily handle 200k
concurrent connections (with intermittent traffic) on a moderately specced
machine. We suspect the limit is much, much higher, but we haven't tested this
as we only have 8 client machines available to generate connections.

I don't know exactly how SAEA is implemented in .NET, but I suspect there is a
single IO completion port for all connections, serviced by threads in the
system thread pool. I would expect Mono to do something similar: Use a single,
global IOCP or poll/epoll set, add all file descriptors to this, and use thread
pool threads to dispatch IO completions.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list