views:

249

answers:

4

I know that in java when u want to create a high performance server you use nio instead of the regular socket. So is there such a thing for C#, to create high performance servers?

A: 

There are different ways of using the regular sockets. Typically, asynchronous use scales better.

Steven Sudit
+7  A: 

Yes, SocketAsyncEventArgs:

The SocketAsyncEventArgs class is part of a set of enhancements to the System.Net.Sockets.Socket class that provide an alternative asynchronous pattern that can be used by specialized high-performance socket applications. This class was specifically designed for network server applications that require high performance. An application can use the enhanced asynchronous pattern exclusively or only in targeted hot areas (for example, when receiving large amounts of data).

Remus Rusanu
Uhm, this isn't wrong, but it makes it sound as if this is a special class that's used *instead* of regular `Socket`, when in fact it's just the event type for certain kinds of async calls to `Socket`.
Steven Sudit
Programming with SocketAsyncEventArgs is definitely not 'just the event for certain kind of async calls'. When one starts a project it has a clear choice to make: use sync calls, use classic async (beginsend/callback/endsend) or use SocketAsyncEvent. See Socket Performance Enhancements in Version 3.5 http://msdn.microsoft.com/en-us/library/bb968780.aspx
Remus Rusanu
+2  A: 

You can use asynchronous sockets. If that one is not good enough, you can always check out the Network Direct SPI, part of the HPC SDK. Note that Network Direct does require hardware-specific provider, though.

Franci Penov
+1 But there is no managed API for network direct, is there?
Remus Rusanu
This looks interesting, but the hardware-specific requirements make me wonder if it's a great idea. Another interesting-but-perhaps-unwise option is to just use P/Invoke.
Steven Sudit
Thanks, asynchronous doesn't do it, we are talking about over 5k client connecting to the server, and stay connected, and communicate wth the server. I'll take a look at network direct SPI, thanks
aryaxt
No, there isn't a managed API for network direct, you have to use COM to interop with the ND SPI provider.
Franci Penov
A: 

SocketAsyncEventArgs uses Windows I/O Completion Ports, which makes it fast. It is asynchronous, which makes it scalable. The really big deal with SocketAsyncEventArgs is I/O Completion Ports.

See http://www.codeproject.com/KB/cs/socketasynceventargs.aspx for how to use SocketAsyncEventArgs.

Stan Kirk