should help you out A very rough picture of how native threads are used by Akka is as follows. Akka Actors are objects instantiated by an ActorSystem Then they are scheduled for execution on a Dispatcher. Dispatcher eventually delegates the execution to some ExecutorService. Actual implementations of Dispatcher and ExecutorService determine the way JVM threads are created and used. By default a fork-join pool-based executor service is used. It is created with ForkJoinExecutorConfigurator which creates a factory which, in turn, creates corresponding implementation of ExecutorService. Fork-join pool creates several Threads internally and uses them to execute given tasks. The actual execution strategy is unimportant; there are other executors which can schedule tasks across threads differently, and Akka can be configured to use them instead of the default one. Thread is a JVM-level abstraction which is implemented in the standard library. It uses bindings to native libraries (written in some native language like C++ or C) which delegate thread management to the OS. So, when Thread object is created and started, eventually a native thread is created and started, and this thread will execute the code provided to this Thread object.
Actor -> Dispatcher -> ExecutorService ----> Thread --| |--> OS thread
|--> Thread --|native code boundary|--> OS thread
\--> Thread --| |--> OS thread
hop of those help? I now see that the value of the DONT_USE_InternalThread field of my System.Threading.Thread object is the decimal equivalent of the hex value appearing under the heading ThreadOBJ in the !threads output.
Is it safe to mix green threads and native threads in a single python process?
Hope that helps With gevent < 1.0 it is most likely a bad idea, as libevent isn't thread safe. You might be okay if you make sure that the OS threads never interact with libevent… But that could be tricky, and bugs cause by libevent's lack of thread safety don't sound like any fun to debug. However, gevent >= 1.0 uses libev, which is entirely thread safe. So (as far as I can tell) there's no problem mixing green threads and OS threads.
Threads, why 1000 threads and 2000 threads does not make much noticeable difference
I hope this helps . As already mentioned in the comments, there is no need to have significantly more threads than CPU-cores. You will actually get less performance if you have more threads than CPU-cores due to the fact that the kernel will waste CPU-cycles switching threads. The more threads you have, the more time will be wasted switching between them, in general at least, it has to do with the nature of the application as well. Also, when you have many threads to switch between, you are more likely to cache-trashing. To clarify:
How many threads are allocated by default by actor system?
# warning: these values are not updated regularly
# see documentation for most recent settings
# Min number of threads to cap factor-based parallelism number to
parallelism-min = 2
# Parallelism (threads) ... ceil(available processors * factor)
parallelism-factor = 2.0
# Max number of threads to cap factor-based parallelism number to
parallelism-max = 10
Unable to create native threads after creating 2700 threads