You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use Python's multiprocessing.Pool (see get_multiprocessing_pool in tools/shared.py) to compile system libraries etc., so that we use all cores. This may be slower on windows. Perhaps there is a faster way to execute a bunch of shell commands in parallel?
If we are just running commands, a platform non-specific way would be to use threads. This should be as easy as using multiprocessing.ThreadPool instead of multiprocessing.Pool.
On POSIX, using select/poll/epoll/kqueue would probably be more efficient than a thread or process pool, but that is highly non-trivial.
Thing to think about with thread pools:
we must make sure we aren't doing any computation heavy things in python with a thread pool, since python code is run with the GIL, but I/O is fine
multiprocessing forks (on POSIX) or spawns a child process and sends things to it (on Windows), if we mutate global state, it would be shared across all workers. This may force us to make certain things thread local or require a mutex, but it should not be a concern if we are just executing subprocesses.
Hmm, there doesn't seem to be multiprocessing.ThreadPool. Is it in a library perhaps?
It does sound like that could speed us up, as we do very little python in those pools, it's mostly calling external things like clang, node, etc. - which we mostly do by creating a new process for each - which is also something maybe we should optimize.
Sorry, I meant multiprocessing.pool.ThreadPool. It's not exactly documented, but it's the pool used by the dummy version of multiprocessing. It has been around for a long time and I don't think it will be removed anytime soon.
It think it should be easier to develop and maintain code using a thread pool vs a multi-process pool. We've run into many issue in the past with the way results get serialized back from multiprocess pools.
If each of the child jobs is simply a subprocess there is no point in adding the extra python process so I would support moving to threads. Not sure about using an undocumented API though. Does python not have a thread pool builtin that isn't part of multiprocessing?
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
Activity
quantum5 commentedon Jun 12, 2019
If we are just running commands, a platform non-specific way would be to use threads. This should be as easy as using
multiprocessing.ThreadPoolinstead ofmultiprocessing.Pool.On POSIX, using
select/poll/epoll/kqueuewould probably be more efficient than a thread or process pool, but that is highly non-trivial.Thing to think about with thread pools:
multiprocessingforks (on POSIX) or spawns a child process and sends things to it (on Windows), if we mutate global state, it would be shared across all workers. This may force us to make certain things thread local or require a mutex, but it should not be a concern if we are just executing subprocesses.kripken commentedon Jun 12, 2019
Hmm, there doesn't seem to be
multiprocessing.ThreadPool. Is it in a library perhaps?It does sound like that could speed us up, as we do very little python in those pools, it's mostly calling external things like clang, node, etc. - which we mostly do by creating a new process for each - which is also something maybe we should optimize.
quantum5 commentedon Jun 13, 2019
Sorry, I meant
multiprocessing.pool.ThreadPool. It's not exactly documented, but it's the pool used by the dummy version ofmultiprocessing. It has been around for a long time and I don't think it will be removed anytime soon.quantum5 commentedon Jun 14, 2019
I found no visible improvement on Linux with a thread pool. I do not have a Windows machine to check if the same holds true there.
#8794 contains the code used to test the thread pool.
On a side note, significant improvement in build performance is found with #8795.
quantum5 commentedon Jun 18, 2019
There appears to be no visible improvement on Windows either.
sbc100 commentedon Jun 18, 2019
It think it should be easier to develop and maintain code using a thread pool vs a multi-process pool. We've run into many issue in the past with the way results get serialized back from multiprocess pools.
If each of the child jobs is simply a subprocess there is no point in adding the extra python process so I would support moving to threads. Not sure about using an undocumented API though. Does python not have a thread pool builtin that isn't part of multiprocessing?
stale commentedon Jun 17, 2020
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.