-- I launch 10 threads
-- Threads share Queue.Queue().
-- Each Thread gets an item from the Queue
-- Each thread communicates first with External WebServer
-- Processes Data coming from Ext. WebServer
-- Communicates with internal DB
-- Gets the next the item from Queue
-- It repeats until Queue finishes
-- At which point all threads are joined and main thread exits normally
-- In the code, in main thread I populate Queue.Queue() with 500 items
-- Then each thread gets the first item in the queue.
我观察到:
- 最初(这意味着当每个线程处理其第一个项目时)所有10个线程都启动并正常进行 - 但是,从第二个项目开始,只有2个来自10个主题的进度。 - 由于涉及多个网络,I / O操作,我假设所有线程都应交错并获得一些CPU时间。
你能解释一下这种行为吗?任何指向文档或先前在堆栈上提出的问题的指针都会有所帮助。
sysctl hw.ncpu(mac OS) hw.ncpu:2
问候,