2

在使用 Django 开发我的 Web 应用程序时,我遇到了一个问题,当我在本地调用一些函数时它们可以正常工作,但是一旦我通过 HTTP 请求调用它们,它们就不会被执行。我四处询问,并被告知使用 celery 和消息队列服务器在请求响应周期之外异步执行它们,它运行良好,但我仍然不明白为什么我必须异步执行某些任务,即使我没有竞争条件,并且只有一个客户端调用 Web 服务。这对我来说是一个很大的黑点,因为我在不知道如何做的情况下让它工作。谁能给我解释一下?

谢谢。

4

1 回答 1

1

The two main benefits I know of for queue-based systems are:

One, a response can be given to the client without having to wait for work to be done. This lets pages load faster and clients spend less time waiting.

Second, a queue gives you a central location for scheduled jobs that multiple workers can draw from. If a certain component of your application can't keep up with the amount of work there is to do (or if it fails for some reason), you can have other instances of that component doing the work, and there is a single place where all of the work that needs to be done can be found.

于 2013-07-07T22:07:51.320 回答