我正在使用 Python 开发一个相当简单的 CGI.我即将将它放入 Django 等.整体设置是非常标准的服务器端(即计算在服务器上完成):
I'm working on a fairly simple CGI with Python. I'm about to put it into Django, etc. The overall setup is pretty standard server side (i.e. computation is done on the server):
我认为不会有成百上千的人同时使用它;但是,因为正在进行的计算需要相当多的 RAM 和处理器能力(每个实例都使用 Python 的 Pool
分叉出 CPU 最密集的任务).
I don't think there are going to be hundreds or thousands of people using this at once; however, because the computation going on takes a fair amount of RAM and processor power (each instance forks the most CPU-intensive task using Python's Pool
).
我想知道您是否知道使用排队系统是否值得麻烦.我遇到了一个名为 beanstalkc
的 Python 模块,但在页面上它说它是一个内存中"排队系统.
I wondered if you know whether it would be worth the trouble to use a queueing system. I came across a Python module called beanstalkc
, but on the page it said it was an "in-memory" queueing system.
在这种情况下,内存中"是什么意思?我担心内存,而不仅仅是 CPU 时间,因此我想确保一次只运行一个作业(或保存在 RAM 中,无论它是否接收 CPU 时间).
What does "in-memory" mean in this context? I worry about memory, not just CPU time, and so I want to ensure that only one job runs (or is held in RAM, whether it receives CPU time or not) at a time.
另外,我试图决定是否
对于此类问题,您认为适合轻型交通 CGI 的设计方法是什么?非常感谢您的建议.
What do you think is the appropriate design methodology for a light traffic CGI for a problem of this sort? Advice is much appreciated.
一定要用celery.您可以运行 amqp 服务器,或者我认为您可以将数据库作为消息队列进行起诉.它允许您在后台运行任务,并且可以根据需要使用多台工作机器进行处理.如果您使用 django-celery
Definitely use celery. You can run an amqp server or I think you can sue the database as a queue for the messages. It allows you to run tasks in the background and it can use multiple worker machines to do the processing if you want. It can also do cron jobs that are database based if you use django-celery
后台运行任务就这么简单:
It's as simple as this to run a task in the background:
@task
def add(x, y):
return x + y
在一个项目中,我将工作分配到 4 台机器上,而且效果很棒.
In a project I have it's distributing the work over 4 machines and it works great.
这篇关于Python CGI 队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!