简体   繁体   English

扭曲与队列的CPU绑定任务

[英]Twisted with queue for CPU-bound tasks

I have an HTTP server which does some IO stuff, then does some CPU-bound stuff (PIL) and then replies with data (magnitude of megabyte or so). 我有一个HTTP服务器,它做一些IO的东西,然后做一些CPU绑定的东西(PIL),然后回复数据(兆字节大小左右)。

(a) My first idea is something like this: a process for server and IO, based on Twisted, and several processes for PIL stuff, with queue. (a)我的第一个想法是这样的:服务器和IO的过程,基于Twisted,以及PIL的几个进程,带队列。

If this architecture is reasonable, then there probably is a library which does exactly that: multiprocess queue for Twisted. 如果这种架构是合理的,那么可能存在一个完全相同的库:Twisted的多进程队列。 However, I'm not really experienced in Twisted and know nothing of its community so the only thing I found is ampoule , for which I found neither docs nor description which would persuade me that it's the right tool for a job. 然而,我在Twisted中并没有真正的经验,对它的社区一无所知,所以我发现的唯一的东西就是ampoule ,我找不到任何文件或说明,这些都不能说服我这是一个适合工作的工具。

(b) Another idea is to just run several servers in several threads, with both IO and CPU stuff going in each on of them. (b)另一个想法是在几个线程中运行多个服务器,每个服务器上都有IO和CPU内容。 This seems stupid because CPU stuff will block, but maybe I'm not really understanding it. 这看起来很愚蠢,因为CPU的东西会阻塞,但也许我真的不理解它。

So, questions: 所以,问题:

  1. Is any of these architectures reasonable? 这些架构中的任何一个都合理吗?
  2. How would you implement it (using Twisted + ampoule or what?) 你会如何实现它(使用Twisted + ampoule或什么?)
  3. For (a), how would you send a huge pile of data from "worker" to the server thread? 对于(a),您如何从“worker”向服务器线程发送大量数据? Or maybe I can tell the worker to write into the response directly somehow? 或者我可以告诉工人直接以某种方式写入回复?
  4. How many "workers" are reasonable? 有多少“工人”是合理的?
  1. Yes, those architectures are probably reasonable 是的,这些架构可能是合理的
  2. I'd probably use ampoule too, but I don't know a lot about it right now either. 我也可能使用安瓿,但我现在也不太了解它。 This link is the closest thing to a good introduction that I remember seeing. 这个链接是我记得看到的最好的介绍。
  3. Since it sounds like your workers will always be on the same machine, you should be able to use shared memory. 因为听起来你的工作人员总是在同一台机器上,所以你应该能够使用共享内存。
  4. That depends pretty wildly on the number of cores you have available and how intensive the work is (both with respect to CPU time and other resources, like memory and disk). 这在很大程度上取决于您可用的核心数量以及工作的密集程度(包括CPU时间和其他资源,如内存和磁盘)。 It's probably hard to give any answer better than "benchmark with around 1-5 processes per core and see what's fastest". 可能很难给出任何答案,而不是“每个核心大约1-5个进程的基准测试,看看哪个是最快的”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM