使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在生产中使用了 Beanstalk,并且在测试时通过它发送了数百万条简单消息 - 通常是批量发送,但在我离开公司之前,生产系统已经处理了超过 100,000 个任务。它可能仍在运行,在这种情况下,现在的数量将达到数千万——或者更多,如果他们按照我的计划进一步扩展它的使用范围的话。
我会推荐它,因为它有很多优点。
我完成的第一个任务是图像处理 - 在 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.
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.