简体   繁体   English

Rails:我可以在不同的服务器上运行后台作业吗?

[英]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: 可能的例子:

  1. Two different EC2 instances, one with the main server and the second with the queueing service. 两个不同的EC2实例,一个与主服务器,另一个与排队服务。

  2. 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: 它有几个要求:

  1. The servers have to have synced clocks. 服务器必须具有同步时钟。 This is usually not a problem as long as the server timezones are all set to the same. 只要服务器时区都设置​​为相同,这通常不是问题。
  2. The servers all have to access the same database. 服务器都必须访问同一个数据库。

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. 但是与数据库相同 - 它需要从外部访问。

Full disclosure: I helped build IW . 完全披露:我帮助建立了IW

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以运行我的 rake 作业吗:在运行我的 rails 服务器时在同一个 docker 容器中工作? - Can I run my rake jobs:work in the same docker container as I run my rails server? 如何在AWS Elastic Beanstalk上运行Rails后台作业? - How can I run Rails background jobs on AWS Elastic Beanstalk? 如何运行 Rails 服务器守护进程? - how can I run rails server daemon? 我无法运行 Rails 服务器 - I can't run rails server 如何在AWS Elastic Beanstalk上使用Resque运行Rails后台作业? - How can I run Rails background jobs with Resque on AWS Elastic Beanstalk? apache和rails可以在同一服务器上的不同目录中运行吗? - can apache and rails run on the same server in different directories? 我可以在同一服务器上运行Rails 2和Rails 3应用程序吗? - Can I run a Rails 2 and a Rails 3 applications on the same server? 我可以在rails应用程序的管理服务器上运行Elastic服务器吗? - Can I run Elastic server on manage server for in rails app 如何使用线程在Puma或Raptor服务器上运行Sidekiq作业? - How can I dedicate threads to run Sidekiq jobs with Puma or Raptor server? 我似乎无法运行 Rails 服务器 - I can't seem to get rails server to run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM