473,785 Members | 3,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling thousands of TCP socket connections

I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not always
passed each minute so would result in a degree of threads being blocked for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...
Jul 21 '05 #1
9 2481
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a thread from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not always passed each minute so would result in a degree of threads being blocked for a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...

Jul 21 '05 #2
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I simply
call this method for each and every socket I am handling on the basis it
will call the callback method using the threads in the standard threadpool
and it will only do so when data is avaiable or the socket closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent
connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread
for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which
will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a
socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a
time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...



Jul 21 '05 #3
I have done some more resarch and I beleive the standard socket.BeginRec eive
does use Completion Ports, but I have also seen reference to the number of
IO Completion Port threads being around 1000. Is this correct? And will this
prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look into
load balancing servers/routers to scale this further but 1000 connections
will prove a major limit very early on in the life of this project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:ua******** ******@TK2MSFTN GP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread
for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which
will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a
thread
from a threadpool class to handle reading and logging of the data
before
returning the socket to the queue. Is it possible to identify if a
socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a
time
stamp against each socket and using this to wait until there 'should'
be
data available and then spawning a thread to read it but data is not
always
passed each minute so would result in a degree of threads being blocked
for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...



Jul 21 '05 #4
Hi Phil,

Yeah BeginRecieve does use completion ports. Unfortunatly the solution does
not scale up past the max number allowed by the ThreadPool but this is
determined by the hardware on which you are running. Look at
ThreadPool.GetM axThreads and ThreadPool.SetM inThreads. If and when you hit
1000 concurrent users switching to a dual CPU machine should double the
number of clients you can handle.
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:e2******** ******@TK2MSFTN GP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginRe ceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000. Is
this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:ua******** ******@TK2MSFTN GP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using
.NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
> I am try to evaluate the most efficient method of handling thousands
> of
> simultaneous TCP connects each of which remain connected to the server
> for
> hours and pass a small amount of data usually once a minute. The data
> received is logged in a SQL Server database.
>
> The only method I have found of reading each socket requires a thread
> for
> each connection which blocks waiting for data. This appears to be very
> inefficient as it will result in thousands of threads, each of which
> will
> have a networkstream and reader object doing very little. Is this
> blocking
> method the best/only method of reading data from a TCP socket?
>
> I was thinking of implementing a queue of open sockets which I cycled
> through checking if each had any data ready to handle, spawning off a
thread
> from a threadpool class to handle reading and logging of the data
> before
> returning the socket to the queue. Is it possible to identify if a
> socket
> has data ready to be read and how many bytes to read to prevent it
> from
> blocking?
>
> I can possibly do an inefficient variation of the above by keeping a
> time
> stamp against each socket and using this to wait until there 'should'
> be
> data available and then spawning a thread to read it but data is not
always
> passed each minute so would result in a degree of threads being
> blocked
for
> a duration.
>
> Does anybody have a suggestion as to the best method?
>
> Thanks
>
> Phil...
>
>



Jul 21 '05 #5
Thanks for the information this has helped point me in a good direction to
evaluate further.

As I can "almost" anticipate when data will be available (because it comes
once a minute or somtime after) I may be able to delay initiating each
subesquent BeginReceive by a minute thus the number of pending reads at any
point in time will be considerably less, increasing the capacity
significatntly passed the thread limitation. It will probably be run on a
Quad Xeon server ultimatly

Thanks for the ideas.

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:m5******** ******@newsfe6-win.ntli.net...
Hi Phil,

Yeah BeginRecieve does use completion ports. Unfortunatly the solution
does not scale up past the max number allowed by the ThreadPool but this
is determined by the hardware on which you are running. Look at
ThreadPool.GetM axThreads and ThreadPool.SetM inThreads. If and when you hit
1000 concurrent users switching to a dual CPU machine should double the
number of clients you can handle.
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:e2******** ******@TK2MSFTN GP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginR eceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000.
Is this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:ua******** ******@TK2MSFTN GP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I
am after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
> Check out the static method Socket.Select() (assuming you are using
> .NET
> framework).
>
> Mike
>
>
> "Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
> news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
>> I am try to evaluate the most efficient method of handling thousands
>> of
>> simultaneous TCP connects each of which remain connected to the
>> server for
>> hours and pass a small amount of data usually once a minute. The data
>> received is logged in a SQL Server database.
>>
>> The only method I have found of reading each socket requires a thread
>> for
>> each connection which blocks waiting for data. This appears to be
>> very
>> inefficient as it will result in thousands of threads, each of which
>> will
>> have a networkstream and reader object doing very little. Is this
>> blocking
>> method the best/only method of reading data from a TCP socket?
>>
>> I was thinking of implementing a queue of open sockets which I cycled
>> through checking if each had any data ready to handle, spawning off a
> thread
>> from a threadpool class to handle reading and logging of the data
>> before
>> returning the socket to the queue. Is it possible to identify if a
>> socket
>> has data ready to be read and how many bytes to read to prevent it
>> from
>> blocking?
>>
>> I can possibly do an inefficient variation of the above by keeping a
>> time
>> stamp against each socket and using this to wait until there 'should'
>> be
>> data available and then spawning a thread to read it but data is not
> always
>> passed each minute so would result in a degree of threads being
>> blocked
> for
>> a duration.
>>
>> Does anybody have a suggestion as to the best method?
>>
>> Thanks
>>
>> Phil...
>>
>>
>
>



Jul 21 '05 #6
Note that with the current version of the CLR you have a max of 1000 IOCP
threads per CPU in the pool.

Willy.

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:e2******** ******@TK2MSFTN GP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginRe ceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000. Is
this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:ua******** ******@TK2MSFTN GP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using
.NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
> I am try to evaluate the most efficient method of handling thousands
> of
> simultaneous TCP connects each of which remain connected to the server
> for
> hours and pass a small amount of data usually once a minute. The data
> received is logged in a SQL Server database.
>
> The only method I have found of reading each socket requires a thread
> for
> each connection which blocks waiting for data. This appears to be very
> inefficient as it will result in thousands of threads, each of which
> will
> have a networkstream and reader object doing very little. Is this
> blocking
> method the best/only method of reading data from a TCP socket?
>
> I was thinking of implementing a queue of open sockets which I cycled
> through checking if each had any data ready to handle, spawning off a
thread
> from a threadpool class to handle reading and logging of the data
> before
> returning the socket to the queue. Is it possible to identify if a
> socket
> has data ready to be read and how many bytes to read to prevent it
> from
> blocking?
>
> I can possibly do an inefficient variation of the above by keeping a
> time
> stamp against each socket and using this to wait until there 'should'
> be
> data available and then spawning a thread to read it but data is not
always
> passed each minute so would result in a degree of threads being
> blocked
for
> a duration.
>
> Does anybody have a suggestion as to the best method?
>
> Thanks
>
> Phil...
>
>



Jul 21 '05 #7
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:OU******** ******@TK2MSFTN GP15.phx.gbl...
Note that with the current version of the CLR you have a max of 1000 IOCP
threads per CPU in the pool.
I don't understand what you mean. An IOCP isn't a thread. What is this
1000 limit? Does the CLR create a new thread for every 1000 objects sharing
an IOCP? I understand IOCPs and I understand that the CLR uses them but,
I'm not quite sure how the CLR uses them or what this limit of 1000 is.

Willy.

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:e2******** ******@TK2MSFTN GP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginR eceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000.
Is this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:ua******** ******@TK2MSFTN GP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I
am after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginRec eive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com > wrote in message
news:4P******** *****@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
> Check out the static method Socket.Select() (assuming you are using
> .NET
> framework).
>
> Mike
>
>
> "Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
> news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
>> I am try to evaluate the most efficient method of handling thousands
>> of
>> simultaneous TCP connects each of which remain connected to the
>> server for
>> hours and pass a small amount of data usually once a minute. The data
>> received is logged in a SQL Server database.
>>
>> The only method I have found of reading each socket requires a thread
>> for
>> each connection which blocks waiting for data. This appears to be
>> very
>> inefficient as it will result in thousands of threads, each of which
>> will
>> have a networkstream and reader object doing very little. Is this
>> blocking
>> method the best/only method of reading data from a TCP socket?
>>
>> I was thinking of implementing a queue of open sockets which I cycled
>> through checking if each had any data ready to handle, spawning off a
> thread
>> from a threadpool class to handle reading and logging of the data
>> before
>> returning the socket to the queue. Is it possible to identify if a
>> socket
>> has data ready to be read and how many bytes to read to prevent it
>> from
>> blocking?
>>
>> I can possibly do an inefficient variation of the above by keeping a
>> time
>> stamp against each socket and using this to wait until there 'should'
>> be
>> data available and then spawning a thread to read it but data is not
> always
>> passed each minute so would result in a degree of threads being
>> blocked
> for
>> a duration.
>>
>> Does anybody have a suggestion as to the best method?
>>
>> Thanks
>>
>> Phil...
>>
>>
>
>



Jul 21 '05 #8
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent connections
on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...


Nov 22 '05 #9
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent connections
on that basis.
"Mike Jansen" <mj**********@m ail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co .uk.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...


Nov 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2274
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end point. System.Net.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr); System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
4
18135
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call shutdown and close asynchronously if possible.
12
428
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
2
6879
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
0
4689
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a number of different types of data coming in. I have a databuffer for each type of data coming in.
4
3605
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
5
12804
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? I thought about putting a boolean in there, but then what if it's still waiting for an incoming...
11
8619
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.