G
G
GreenX52021-10-12 18:35:10
Python
GreenX5, 2021-10-12 18:35:10

Does Windows allocate Python threads across cores?

As you know, Python is basically single-threaded, the GIL is to blame, and so on.
We raise a web server in Python, for each visitor request we create a separate thread to quickly release the input, the load is growing, there are already hundreds of threads at the same time, the question is - will Windows start distributing them among the cores, or will it only cook the distributor itself with handles?
Actually the question is from the expediency of a multi-core server without a gate like nginx.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-10-12
@GreenX5

It will start, but only one core will work at a time. CPU utilization in Python is solved by running a separate process for each core, and within a process it is better to use asynchrony rather than multithreading.

A
Armenian Radio, 2021-10-12
@gbg

Running threads in an amount that exceeds the number of cores is the path to a dramatic increase in latency and a drop in speed.
Both in Windows (IO Completion Ports), and in Linux (epoll), all the latest mass TCP connection servicing mechanisms launch exactly as many threads as there are cores, and spool events from sockets between them. That is why, in front of various kinds of Python scripts, they put the Big Iron Felix (nginx), which will optimally push IO into the necessary tasks.
Without this, multiple context jerks and cache flushes on the processor will occur, and not when it makes sense (the IO operation has completed, the cache is not needed), but when it happens.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question