Answer the question
In order to leave comments, you need to log in
Lots of socket connections. Which is better to use asyncio or threads?
Lots of socket connections. Which is better to use asyncio or threads?
There are many TLS connections
more than 50
, you need to listen to all of them
. What is the best way to implement this?
And what is the best way to use it?
Answer the question
In order to leave comments, you need to log in
50 is not much :) A lot is a few thousand. Better use async instead of multithreading. In Python, this is both simpler and more performant in most cases.
When using a single thread with asynchronous processing, only one processor core will be involved. When using a per-request thread, there is a large overhead for creating threads. From here:
1. If each request demands serious processing and loads the processor - use flows.
2. If requests are frequent, but do not require processing - use asynchrony.
3. If you have really high loads and you need to use resources as efficiently as possible - use an application with several pre-launched threads (workers) and use asynchrony in each of them, distribute requests evenly between workers. The number of workers must not be less than the number of cores.
PS When using any approach except for one request - one thread, asynchrony should be not only on sockets, all operations (for example, working with files) should be asynchronous so as not to block the thread.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question