The idea of threads and workers is unclear to me. We can assign the no of threads associated for the CherryPy server as,
server = Server()
server.socket_port = port
server.socket_host = "0.0.0.0"
server.thread_pool = 100
There is no property for defining the workers, so does it mean that the server I am instantiating is the only worker and the threads associated in the thread_pool property is the maximum number of threads that it can utilize while serving the application (Mostly concurrent requests). Or is there a way to define the number of workers in CherryPy.
Any help is appreciated!
I can understand your confusion, because Cherrypy is notoriously poorly documented.
To understand the concepts of worker
and thread
, we need to step back and learn the structure of a typical cherrypy application.
When you run your server application, you start a process. That process contains a main thread, which is the cherrpy.engine
. cherrypy.engine
starts the server, which runs in its own thead. cherrypy.tree
holds an hierachy of page handlers, and each of those handler may be a worker
. But whether that worker
has its own thread to run, or has to wait until other workers
finish and free up a thread, is totally dependent on how many threads are left. Once a worker
acquires a free thread
, it becomes a worker thread
and it immediately starts to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.