c - number of concurrent connections in multithreading tcp server -


we know in process, number of threads has limit, around 1000.

if want create tcp server based on multithreading,

each thread responsible 1 connection.

since there 1 process, number of threads limited.

then means number of concurrent connections limted.

am understanding correct or not?

if not, why?

thanks

yes, there resource limits on threads determined operating system , hardware.

maximum number of threads per process in linux?

you never build massively parallel server using thread per connection. use select() or poll() , non-blocking sockets. if need have more 1 thread working on input (it takes lot before can't in 1 process , shouldn't making blocking calls regardless), create worker pool sized around number of processor cores have available, , use process work becomes available.

more details on worker pool concept. 1 thread can handle reading incoming network data off network , tossing somewhere. there still additional work process data, however. simple chat server type application, no matter how many connections, 1 thread can responsible reading data , processing data.

however, if have bunch of physics calculations on each chunk of data received, 1 thread may not able handle math , stay current incoming network data. in case, have 1 thread take data off network , put sychronized queue of data processed. have handful or 2 of worker threads taking data off queue , processing in thread-safe manner.

if try thousands of threads, slow down. contend system resources , proceed slower due none of them getting cpu cycles or ram or cpu cache want.

http://en.wikipedia.org/wiki/thread_pool_pattern


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -