views:

215

answers:

2

I'm re-building an IM gateway and hope to take advantage of the new performance features in AsyncSockets for .net35.

My existing implementation simply creates packets and forwards IM requests from users to the various IM networks as required, handling request/ response streams for each connected users session(socket).

i presently have to coupe with IasyncResult and as you know it's not very pretty or scalable.

My confusion is this basically:

1) in using the new Begin/End and SocketAsyncEventArgs in 3.5 do we still need to create one SocketAsyncEventArgs per socket?

2) do we gain anything by pre-initializing say, 20000 client connections since we know the expected max_connections per server is 20000

3) do we still need to use a LOH (large object heap) allocated byte[] to handle receive data as shown in SocketServers example on MSDN, we are not building a server per say, but are still handling a lot of independent receives for each connected socket.

4) maybe there is a better pattern altogether for what i'm trying to acheive?

Thanks in advance.

Charles.

+1  A: 

1) IAsyncResult/Begin/End is a completely different system from The "xAsync" methods that use SocketAsyncEventArgs. You're better off using SocketAsyncEventArgs and dropping Begin/End entirely.

2) Not really. Initialize a smaller number (50? 100?) and use an intermediate class (ie/ a "resource pool") to manage them. As more requests come in, grow the pool by another 50 or 100 for example. The tough part is efficiently "scaling down" the number of pooled items as resource requirements drop. A large # of sockets/buffers/etc will consume a large amount of memory, so it's better to only allocate it in batches as the server requires it.

3) Don't need to use it, but it's still a good idea. The buffer will still be "pinned" during each call.

ShadowChaser
@ShadowChaserPlease can you point me to any resourses you found useful when learning to use SocketAsyncEventArgs 'properly'.MSDN and the popular CodeProject article are basically one and the same and of little help.Thanks
CharlesO
Unfortunately, all of the SocketAsyncEventArgs documentation and tutorials I found was woefully inadequate. It was a lot of trial and error and digging into how native overlapped IO works.
ShadowChaser
A: 

i neeed business

robert