在Rails中无缝部署 [英] Seamless deployment in Rails

查看:71
本文介绍了在Rails中无缝部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想无缝升级我的Rails应用程序:

I would like to seamlessly upgrade my Rails app:

含义:


  1. 如果不需要运行任何迁移,我想透明地升级代码,并且在部署期间不会有任何请求进入404。

  2. 这很困难,我想拥有一些可以无缝升级数据库的过程,在此期间,只需暂停Web请求(在Web请求中排队)即可。管道)在数据库更新完成后,允许通过。 (我只需要使用它即可进行短暂的迁移-例如5-10秒的迁移)。

  1. If no migrations need to run I would like to transparently upgrade the code and have no requests go 404 during the deployment.
  2. This is hard I would like to have some process that can upgrade the database seamlessly and during that time just hold back on the web requests (queue them in the pipe) when the db update is done, allow stuff through. (I only need this to work for short migrations - like 5-10 second migrations).

您将如何实现这一目标?

How would you go about achieving this?

推荐答案

仅升级代码

如果您只是升级应用程序代码,旅客应该允许您这样做而无需跳过击败。但是,如果升级失败,这将无法保护您,因为您应该考虑拥有两个或更多负载平衡的Web服务器,您可以分别循环升级。

If you're just upgrading the application code passenger should allow you to do that without skipping a beat. However it's not going to protect you if an upgrade goes wrong, for that you should consider having two or more load balanced web servers which you can upgrade individually round robin.

升级数据库

作为用户,我宁愿看到维护中断页面,也不愿浏览器旋转10秒钟。如果您解释说停机时间将是几秒钟,并将页面设置为自动刷新。

As a user I'd rather see a "down for maintenance" page than my browser spinning for 10 seconds. If you explain that the downtime will be an order of a few seconds and set the page to auto-refresh.

如果您坚持要在执行db时不停机,升级时,您有几种选择:

If you're adamant about having no downtime while doing db upgrades you have a few options:


  1. 您可以以保持旧模式有效的方式重构数据库。这意味着您可以使两个版本的应用程序在同一个数据库上运行,并随着时间的推移迁移到新架构。有很多数据库重构文章,其中大多数都主张使用触发器/等来达到预期的效果。我个人认为这会付出很多努力,而不会带来很多回报。

  1. You can refactor your database in such a way that you keep the old schema valid. This means you can keep two version of your app running against the same database and over time migrate to the new schema. There's a lot of 'database refactoring' articles, with most of them advocating using triggers/etc... to achieve the desired result. I personally think it's a lot of effort for not a lot of reward.

根据您的应用程序,您可能会严重偏向于读取而不是写入,这意味着您可以在升级数据库时显示未缓存数据的维护页面(这是facebook对其数据库进行升级的方式)。如果您的大量数据存储在memcached或redis中,这将更加有效。或者,您可以切换到只读数据库从属服务器并禁用任何写操作。

Depending on your application you might be heavily biased towards reads over writes, which means you can show a 'maintenance' page for uncached data while you upgrade the database (this is how facebook does their database upgrades). This is even more effective if lots of your data is stored in memcached or redis. Alternatively you can switch to a readonly database slave and disable any write actions.

我希望这会有所帮助!

这篇关于在Rails中无缝部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆