Linux Thread / Socket Limitations

First of all: sorry for my English. Guys, I have problems with POSIX sockets and / or pthreads. I am developing an embedded device (ARM9 processor). A multithreaded tcp server will work on the device. And he will be able to handle many incoming connections. The server receives a connection from the client and increments the counter variable (unsigned int counter). Client routines will run in separate threads. All clients will use one instance of the Singleton class (the same files will be opened and closed in this class). Clients work with files, then the client thread closes the connection socket and calls pthread_exit (). Thus, my tcp server cannot process more than 250 threads (counter = 249 +1 (server thread). And I got “Resource is temporarily unavailable.” What is the problem?

+2
source share
3 answers

Whenever you click on a thread restriction - or, as mentioned, ends out of the address space of a virtual process due to the number of threads - you ... do it wrong. More threads are not scalable. Especially when you do inline programming. Instead, you can handle requests in the thread pool. Use poll(2)to process multiple connections to fewer threads. This is a beautiful well-flowing area, and libraries (for example, ACE, asio) used this model for a good reason.

The thread per request model is mostly popular because of this (perceived) simple design.

( ), .

, , , : backlog bind/accept, ​​ ! (: , )

Re:

ulimit , , ? , ulimit , ~ 10-15 .

, , . ; pthread * _destroy, , . , . (vlagrind/helgrind )

+1

ulimit -n, . , .

/etc/security/limits.conf

0

Usually the first limitation that you click on 32-bit systems is that when you use the default stack sizes, you run out of virtual address space.

Try to explicitly specify the stack size when creating threads (less than 1 MB) or set the default stack size using "ulimit -s".

Also note that you need to either pthread_detach or pthread_join your threads so that all resources are freed.

0
source

Source: https://habr.com/ru/post/1599032/


All Articles