By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Async sockets and threads

P: n/a
Hi,
I've written a async server app. This app start by connecting to a
client and then send some data (BeginSend). When the data is sent, the
server is starting to listen for incomming data. (BeginRecieve). In the
receive callback I always call BeginRecieve again to keep listen for
more data. The server is continualy listening, and from time to time
sending (but if it is sending more data when there is already a
listening socket, I don't run BeginReceive again). I have one socket
for each client. This works very well but I am very confused about the
Thread-count showing in Windows-task-manager. I would expect that if
the server is Connected to 60 clients, it would also be 60 threads,
because I am listening for incomme all the time. What suprise me is
that the thread count is about 30?? How come? Can anybody explain?

Sep 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
BeginRecieve on a socket wont occupy a workerthread but will use an IO
Completion Thread in the OS.

Ciaran O'Donnell

"ny***********@gmail.com" wrote:
Hi,
I've written a async server app. This app start by connecting to a
client and then send some data (BeginSend). When the data is sent, the
server is starting to listen for incomming data. (BeginRecieve). In the
receive callback I always call BeginRecieve again to keep listen for
more data. The server is continualy listening, and from time to time
sending (but if it is sending more data when there is already a
listening socket, I don't run BeginReceive again). I have one socket
for each client. This works very well but I am very confused about the
Thread-count showing in Windows-task-manager. I would expect that if
the server is Connected to 60 clients, it would also be 60 threads,
because I am listening for incomme all the time. What suprise me is
that the thread count is about 30?? How come? Can anybody explain?

Sep 18 '06 #2

P: n/a
Thank you both of you:)
Ciaran O''Donnell wrote:
BeginRecieve on a socket wont occupy a workerthread but will use an IO
Completion Thread in the OS.

Ciaran O'Donnell

"ny***********@gmail.com" wrote:
Hi,
I've written a async server app. This app start by connecting to a
client and then send some data (BeginSend). When the data is sent, the
server is starting to listen for incomming data. (BeginRecieve). In the
receive callback I always call BeginRecieve again to keep listen for
more data. The server is continualy listening, and from time to time
sending (but if it is sending more data when there is already a
listening socket, I don't run BeginReceive again). I have one socket
for each client. This works very well but I am very confused about the
Thread-count showing in Windows-task-manager. I would expect that if
the server is Connected to 60 clients, it would also be 60 threads,
because I am listening for incomme all the time. What suprise me is
that the thread count is about 30?? How come? Can anybody explain?
Sep 18 '06 #3

P: n/a
Just to clarify for others. Techinically, BeginReceive uses the caller's
thread until it returns IAsyncResult. When the IO completes, the callback
is called on an IOCP thread. Until then, no threads are used.

--
William Stacey [MVP]

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:CF**********************************@microsof t.com...
| BeginRecieve on a socket wont occupy a workerthread but will use an IO
| Completion Thread in the OS.
|
| Ciaran O'Donnell
|
| "ny***********@gmail.com" wrote:
|
| Hi,
| I've written a async server app. This app start by connecting to a
| client and then send some data (BeginSend). When the data is sent, the
| server is starting to listen for incomming data. (BeginRecieve). In the
| receive callback I always call BeginRecieve again to keep listen for
| more data. The server is continualy listening, and from time to time
| sending (but if it is sending more data when there is already a
| listening socket, I don't run BeginReceive again). I have one socket
| for each client. This works very well but I am very confused about the
| Thread-count showing in Windows-task-manager. I would expect that if
| the server is Connected to 60 clients, it would also be 60 threads,
| because I am listening for incomme all the time. What suprise me is
| that the thread count is about 30?? How come? Can anybody explain?
| >
| >
Sep 18 '06 #4

P: n/a
<ny***********@gmail.comwrote in message
I've written a async server app.
[...]
I have one socket
for each client. This works very well but I am very confused
about the Thread-count showing in Windows-task-manager.
I would expect that if the server is Connected to 60 clients, it
would also be 60 threads, because I am listening for incomme
all the time. What suprise me is that the thread count is
about 30?? How come? Can anybody explain?
When you use Async Sockets, you're not using a 1-thread-per-socket model at
all. You're posting events to I/O Completion Ports which in turn is playing
some very advanced threading games under the hood.

By your reasoning, if I had 1000 users connected I would have 1000 threads.
100000 users would be 100000 threads. The scaling of this is pretty brutal
and probably wouldn't get too far past 1000 threads, at least not with any
semblance of performance.

Windows Async Sockets has crazy performance and scalability and this is
mostly because it's not using the 1-thread-per-socket approach. For some
more information on this approach and some variations, see my blog:
http://www.coversant.net/dotnetnuke/...=88&EntryID=10

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Sep 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.