使用 beanstalkd 进行 PHP 异步处理。你推荐吗?

发布于 2024-08-08 23:13:57 字数 192 浏览 10 评论 0原文

您是否建议使用 beanstalkd [ http://kr.github.com/beanstalkd/ ] 进行

异步处理在 PHP 中?

我需要使用过该库的任何人的一些反馈/意见。

谢谢,

would you recommend using beanstalkd [ http://kr.github.com/beanstalkd/ ] for

asynchronous processing in PHP ?

I need some feedback/comments pros-cons, from anyone that has used this lib.

Thanks,

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

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

发布评论

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

评论(1

吃颗糖壮壮胆 2024-08-15 23:13:57

我在生产中使用了 Beanstalk,并且在测试时通过它发送了数百万条简单消息 - 通常是批量发送,但在我离开公司之前,生产系统已经处理了超过 100,000 个任务。它可能仍在运行,在这种情况下,现在的数量将达到数千万——或者更多,如果他们按照我的计划进一步扩展它的使用范围的话。

我会推荐它,因为它有很多优点。

  • 命名管可用于限制正在交付的作业。我根据机器主机名观看一个管道,它限制了工作人员的运行位置 - 对于仅存储在特定服务器上的上传文件很有用)。
  • 延迟可用于设置未来事件
  • 最新版本的服务器还支持 bin-logging,提供持久性,尽管它从未对我造成崩溃。

我完成的第一个任务是图像处理 - 在 Apache/mod_php 进程之外完成这项工作使我能够调整较大图像的大小而不影响服务器(破坏 Web 服务器)。由于队列负载较轻,它在上传后刷新页面之前就创建了缩略图。

还有许多其他潜在的任务也可以异步处理。

我遇到的唯一问题是确保工作人员顺利完成 - 或者捕获任何错误,以便可以“埋葬”作业,从而确保作业不会被放回队列中再次运行(并让工人再次崩溃)。

让工作进程重新启动以清除内存也很有用,因为 PHP 不太适合长时间运行的进程。

I've used Beanstalk in production, and also while testing threw millions of simple messages through it - generally en-mass, but the production system had over a 100,000 tasks put through it till I left the company. It may still be running, in which case it would be tens of millions be now - or more, if they had extended it's use further, as I had planned.

I would recommend it, as it's got a number of excellent points.

  • named tubes can be used to limit the jobs being delivered. I watch a tube based on the machine hostname, which limited where a worker would be running - useful for uploaded files which are only stored on a particular server).
  • The delays can be used to set future events
  • Latest versions of the server also support bin-logging, giving persistence, though it has never crashed on me.

My first task I put through it was image processing - and doing that work outside of an Apache/mod_php process allowed me to resize larger images without affecting the server (blowing out the Webserver). With a lightly loaded queue, it had created the thumbnails before the page had refreshed after the upload.

There are many other potential tasks that could also be processed asynchronously.

The only problems I have ever had was making sure that the workers completed without incident - or that any errors were caught so that the job could be 'bury'ed, thus ensuring that the job was not put back into the queue to be run again (and have the worker crash again).

Having the workers also restart to clear memory can also be useful as PHP is less well suited to long-running processes.

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