473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Async sockets and threads

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
4 2121
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
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
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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Morgan Leppink | last post by:
Hi all - We have been developing a complex TCP socket communication app that is responsible for keeping numerous connections open to clients on routable IPs. The app receives request on a...
1
by: Ben | last post by:
I've written a fair amount of sockets code using the Winsock2 API, but I am having some trouble converting to the .Net Sockets API, specifically asynchronous sockets. What I have is a form that is...
6
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
7
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
4
by: nyhetsgrupper | last post by:
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...
15
by: dennis.richardson | last post by:
Greetings all. Here's a problem that's been driving me nuts for the last 48 hours. I'm hoping that someone has come across this before. I have a C# Application that reads a UDP broadcast...
3
by: Ryan Liu | last post by:
Will TcpClient.GetStream().Read()/ReadByte() block until at least one byte of data can be read? In a Client/Server application, what does it mean at the end of stream/no more data available? ...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
13
by: Alexander Gnauck | last post by:
Hello, while using async sockets I ran into a strange problem which occurs only on some machines. I wrote a small demo application which can be used to reproduce the problem. You can download it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.