Celery 适合与许多小型分布式系统一起使用吗?

发布于 2024-09-26 12:25:37 字数 774 浏览 1 评论 0原文

我正在编写一些软件,可以间歇性地在“现场”管理数百个小型系统3G(或类似)连接。

总部需要将作业发送到现场系统(例如,“报告您的状态”、“更新您的软件”等),并且现场系统需要将作业发送回服务器(例如, “已检测到故障”、“这是一些数据”等)。

我花了一些时间研究 Celery,它似乎非常适合:<在总部运行的 celeryd 可以为现场系统收集作业,在现场系统上运行的 celeryd 可以为服务器收集作业,并且这些作业可以作为客户端进行交换变得可用。

那么,Celery 适合解决这个问题吗?具体来说:

  • 大多数任务将针对单个工作人员(例如,“将‘get_status’作业发送到‘system51’”)——这会成为问题吗?
  • 它是否能够妥善处理不利的网络状况(例如连接中断)?
  • 哪些功能只有在使用 RabbitMQ 作为后端时才可用? (我不想在现场系统上运行 RabbitMQ)
  • 如果我像我所描述的那样使用 Celery ,还有其他原因会让我的生活变得困难吗?

谢谢!

(认为​​芹菜杀伤力太大是有效的,但还有其他原因可以让我的生活更轻松,所以我想考虑一下)

I'm writing some software which will manage a few hundred small systems in “the field” over an intermittent 3G (or similar) connection.

Home base will need to send jobs to the systems in the field (eg, “report on your status”, “update your software”, etc), and the systems in the field will need to send jobs back to the server (eg, “a failure has been detected”, “here is some data”, etc).

I've spent some time looking at Celery and it seems to be a perfect fit: celeryd running at home base could collect jobs for the systems in the field, a celeryd running on the field systems could collect jobs for the server, and these jobs could be exchanged as clients become available.

So, is Celery a good fit for this problem? Specifically:

  • The majority of tasks will be directed to an individual worker (eg, “send the ‘get_status’ job to ‘system51’”) — will this be a problem?
  • Does it gracefully handle adverse network conditions (like, eg, connections dying)?
  • What functionality is only available if RabbitMQ is being used as a backend? (I'd rather not run RabbitMQ on the field systems)
  • Is there any other reason Celery could make my life difficult if I use it like I've described?

Thanks!

(it would be valid to suggest that Celery is overkill, but there are other reasons that it would make my life easier, so I would like to consider it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筑梦 2024-10-03 12:25:37

大部分任务将被定向
给个体工人(例如,“发送
'get_status' 作业到 'system51'”) —
这会是一个问题吗?

一点也不。只需为每个工作人员创建一个队列,例如,假设每个节点都会侦听名为 default 的循环队列,并且每个节点都有自己的以其节点名称命名的队列:

(a)$ celeryd -n a.example.com -Q default,a.example.com
(b)$ celeryd -n b.example.com -Q default,b.example.com
(c)$ celeryd -n c.example.com -Q default,c.example.com

将任务直接路由到节点很简单:

$ get_status.apply_async(args, kwargs, queue="a.example.com")

或者使用路由器进行配置:

# Always route "app.get_status" to "a.example.com"
CELERY_ROUTES = {"app.get_status": {"queue": "a.example.com"}}

它是否能优雅地处理不利的情况
网络条件(例如,
连接消失)?

工作线程从代理连接失败中正常恢复。
(至少从 RabbitMQ 来看,我不确定所有其他后端,但是这个
易于测试和修复(您只需将相关异常添加到列表中)

对于客户端,如果连接断开,您可以随时重试发送任务,
或者您可以使用 RabbitMQ 设置 HA: http://www.rabbitmq.com/pacemaker.html

哪些功能仅可用
如果 RabbitMQ 被用作
后端? (我不想运行 RabbitMQ
在现场系统上)

远程控制命令,并且仅支持“直接”交换(不支持“主题”或“扇出”)。但这将在 Kombu (http://github.com/ask/kombu) 中得到支持。

我会认真重新考虑使用 RabbitMQ。为什么你觉得不太合适?
恕我直言,我不会在其他地方寻找像这样的系统,(除了 ZeroMQ,如果系统
是暂时的,您不需要消息持久性)。

芹菜可以改变我的生活还有其他原因吗
如果我像我所描述的那样使用它会很困难吗?

从你上面的描述中我想不出任何东西。由于并发模型
是多处理它确实需要一些内存(我正在努力添加对
线程池和 eventlet 池,这在某些情况下可能会有所帮助)。

认为 Celery 杀伤力过大是合理的,但也有
其他会让我的生活更轻松的原因,所以我想
考虑一下)

在这种情况下,我认为你轻微地使用了“过度杀戮”这个词。这真的取决于
关于在没有它的情况下您需要编写多少代码和测试。我认为
最好改进现有的通用解决方案,理论上听起来
就像它应该适合您的应用程序一样。

The majority of tasks will be directed
to an individual worker (eg, “send the
‘get_status’ job to ‘system51’”) —
will this be a problem?

Not at all. Just create a queue for each worker, e.g. say each node listens to a round robin queue called default and each node has its own queue named after its node name:

(a)$ celeryd -n a.example.com -Q default,a.example.com
(b)$ celeryd -n b.example.com -Q default,b.example.com
(c)$ celeryd -n c.example.com -Q default,c.example.com

Routing a task directly to a node is simple:

$ get_status.apply_async(args, kwargs, queue="a.example.com")

or by configuration using a Router:

# Always route "app.get_status" to "a.example.com"
CELERY_ROUTES = {"app.get_status": {"queue": "a.example.com"}}

Does it gracefully handle adverse
network conditions (like, eg,
connections dying)?

The worker gracefully recovers from broker connection failures.
(at least from RabbitMQ, I'm not sure about all the other backends, but this
is easy to test and fix (you only need to add the related exceptions to a list)

For the client you can always retry sending the task if the connection is down,
or you can set up HA with RabbitMQ: http://www.rabbitmq.com/pacemaker.html

What functionality is only available
if RabbitMQ is being used as a
backend? (I'd rather not run RabbitMQ
on the field systems)

Remote control commands, and only "direct" exchanges are supported (not "topic" or "fanout"). But this will be supported in Kombu (http://github.com/ask/kombu).

I would seriously reconsider using RabbitMQ. Why do you think it's not a good fit?
IMHO I wouldn't look elsewhere for a system like this, (except maybe ZeroMQ if the system
is transient and you don't require message persistence).

Is there any other reason Celery could make my life
difficult if I use it like I've described?

I can't think of anything from what you describe above. Since the concurrency model
is multiprocessing it does require some memory (I'm working on adding support for
thread pools and eventlet pools, which may help in some cases).

it would be valid to suggest that Celery is overkill, but there are
other reasons that it would make my life easier, so I would like to
consider it)

In that case I think you use the word overkill lightly. It really depends
on how much code and tests you need to write without it. I think
it's better to improve an already existing general solution, and in theory it sounds
like it should work well for your application.

妳是的陽光 2024-10-03 12:25:37

我可能会设置一个(django)网络服务来接受请求。 Web 服务可以完成验证请求和转移不良请求的工作。那么芹菜就可以完成这项工作。

这将需要远程设备轮询 Web 服务以查看其工作是否已完成。这可能合适也可能不合适,具体取决于您正在做什么。

I would probably set up a (django) web service to accept requests. The web service could do the job of validating requests and deflecting bad requests. Then celery can just do the work.

This would require the remote devices to poll the web service to see if their jobs were done though. That may or may not be appropriate, depending on what exactly you're doing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文