Question

I'm wondering which of the async types would be the best in both development speed and stability. I'm writing a proof of concept network application which has to support 1000 concurent clients.

Each client sends about 5 packets of 30 bytes each second. The server sends about 5 packets of 200 bytes each second.

I got these number from an earlier test with a blocking socket. I think I should use the SocketAsyncEventArgs cause of the high throughput but that also takes a bit longer to develop.

Thanks

Was it helpful?

Solution

IIRC the main difference between the two is that SocketAsyncEventArgs removes the need for lots of objects to be allocated (i.e. callbacks etc), which may be a valid concern given your throughput. In particular, this may help prevent periodic performance degradation due to GC. One additional benefit is the hybrid "this might run async, or it might run sync; I'll tell you which" - takes a brief moment of getting used to, but quite handy.

However, as with all things, any high-throughput system needs to be designed to be high throughput. If you are starting from scratch, I would struggle to find a reason not to use SocketAsyncEventArgs - either way async network IO always needs a little bit of head-scratching and planning. When we wrote the web-socket server for SE (which handles 50k+ concurrent connections), one trick that was particularly useful was to ensure we recycled all the byte[] buffers, i.e. fetch them from (and return them to) a central pool of buffers, only allocating new buffers when the pool is empty (and as a corollary, only dropping buffers on the floor when the pool is full). Of course, in that scenario we might not be talking to all the clients every time; if you are going to be regularly talking to each client, another option might be to stick a buffer to each connection. More memory overhead, perhaps, but might make things simpler.

As for "also takes a bit longer to develop"; that is possibly true, especially if you are already very familiar with the older async model. I guess it comes down to how important it is to have a consistently performing server. Both methods will need rigorous testing, of course.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top