[英]Rails: Can I run backgrounds jobs in a different server?
Is it possible to host the application in one server and queue jobs in another server? 是否可以在一台服务器中托管应用程序并在另一台服务器中排队作业?
Possible examples: 可能的例子:
Two different EC2 instances, one with the main server and the second with the queueing service. 两个不同的EC2实例,一个与主服务器,另一个与排队服务。
Host the app in Heroku and use an EC2 instance with the queueing service 在Heroku中托管应用程序并使用EC2实例和排队服务
Is that possible? 那可能吗?
Thanks 谢谢
Yes, definitely. 当然是。 We have delayed_job set up that way where I work.
我们在工作的地方设置了delayed_job。
There are a couple of requirements for it to work: 它有几个要求:
To do it, you simply have the same application on both (or all, if more than two) servers, and start workers on whichever server you want to process jobs. 要做到这一点,您只需在两个(或所有,如果超过两个)服务器上拥有相同的应用程序,并在要处理作业的任何服务器上启动工作程序。 Either server can still queue jobs, but only the one(s) with workers running will actually process them.
服务器仍然可以对作业进行排队,但只有运行工作程序的服务器才能实际处理它们。
For example, we have one interface
server, a db
server and several worker
servers. 例如,我们有一个
interface
服务器,一个db
服务器和几个worker
服务器。 The interface
server serves the application via Apache/Passenger, connecting the Rails application to the db
server. interface
服务器通过Apache / Passenger为应用程序提供服务,将Rails应用程序连接到db
服务器。 The workers
have the same application, though Apache isn't running and you can't access the application through http. 虽然Apache没有运行,但是您无法通过http访问应用程序,因此
workers
具有相同的应用程序。 They do, on the other hand, have delayed_jobs workers running. 另一方面,他们确实有延迟工作的工人。 In a common scenario, the
interface
server queues up jobs in the db
, and the worker
servers process them. 在常见情况下,
interface
服务器将db
作业排队,并且worker
服务器处理它们。
One word of caution: If you're relying on physical files in your application (attachments, log files, downloaded XML or anything else), you'll most likely need a solution like S3 to keep those files. 需要注意的一点是:如果您依赖应用程序中的物理文件(附件,日志文件,下载的XML或其他任何内容),您很可能需要像S3这样的解决方案来保存这些文件。 The reason for this is that the individual servers might not have the actual files.
原因是各个服务器可能没有实际文件。 An example of this is if your user were to upload their profile picture on your web-facing server, the files would likely be stored on that server.
例如,如果您的用户要在面向Web的服务器上上传其个人资料图片,则这些文件可能会存储在该服务器上。 If you then have another server to resize the profile pictures, the image wouldn't exist on the worker server.
如果您有另一台服务器来调整配置文件图片的大小,那么该工作服务器上将不存在该图像。
Just to offer another viable option: you can use a new worker service like IronWorker that relies completely on an elastic farm of cloud servers inside EC2. 只是提供另一个可行的选择:您可以使用像IronWorker这样的新工作服务,它完全依赖于EC2内的弹性云服务器场。
This way you can queue/schedule jobs to run and they will parallelize across tons of threads spanning multiple servers - all without worrying about the infrastructure. 通过这种方式,您可以排队/安排作业运行,并且它们将跨越多个服务器的大量线程并行化 - 所有这些都无需担心基础架构。
Same deal with the database though - it needs to be accessible from the outside. 但是与数据库相同 - 它需要从外部访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.