Async sockets vs synch sockets and threads

N

nyhetsgrupper

I'm writing a server application connection to multiple clients using
sockets. I want one socket for each client, and the comunication needs
to be async. I could use the async sockets methods (beginsend,
beginrecv...) or I could start a new thread for each client and run the
comunication using the sync mehtods (send,recv). What is the best
aproach? This is a performance critical application.
 
V

Vadym Stetsyak

Hello, (e-mail address removed)!

n> I'm writing a server application connection to multiple clients using
n> sockets. I want one socket for each client, and the comunication needs
n> to be async. I could use the async sockets methods (beginsend,
n> beginrecv...) or I could start a new thread for each client and run the
n> comunication using the sync mehtods (send,recv). What is the best
n> aproach? This is a performance critical application.

Have a look at
( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/progthrepool.asp )
( http://msdn.microsoft.com/msdnmag/issues/05/08/HighPerformanceSockets/default.aspx )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
S

simida

Hi,

Async socket method uses .Net ThreadPool thread to handle async method
process.
As far as I know, .Net ThreadPool is not a high performance way to
process this. Maybe you
can customize a new thread pool model to fit your applicaiton.

( Plz refer to here,http://www.bearcanyon.com/dotnet/#threadpool )

Hope it works.
 
P

Peter Duniho

simida said:
Async socket method uses .Net ThreadPool thread to handle async method
process.
As far as I know, .Net ThreadPool is not a high performance way to
process this. Maybe you
can customize a new thread pool model to fit your applicaiton.

Actually, .NET async sockets (using Begin/End<foo> methods) use i/o
completion ports if the OS supports them (anything based on NT does), and
IOCP is the best-performing, most scalable mechanism for using sockets. A
special thread pool, the "completion port threads" pool, is used in this
case and used properly should offer excellent performance.

This is all outlined in the first link provided in the previous reply in
this thread.

Pete
 
C

Chris Mullins

(e-mail address removed) wrote in message
I'm writing a server application connection to multiple clients using
sockets.

Alright. This sounds pretty common.
I want one socket for each client, and the comunication needs
to be async. I could use the async sockets methods (beginsend,
beginrecv...) or I could start a new thread for each client and run the
comunication using the sync mehtods (send,recv). What is the best
aproach?

How many sockets do you think will be connected at any given time? If the
answer if "a few" then go with whatever programming mechanism you understand
the best and can debug the easiest.

If the answer is "I'm Not Sure" or "Alot" then you need to use Async Socket.
This is a performance critical application.

On any modern machine, as long as you follow the rule above, you'll have no
issue with socket performance unless you have some very unusual performance
requirements.

What are your performance requirements, and how do you plan to know if
you've met them?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top