没有Marshal的缓存第一部分:从内到外的Marshal

Caching is critical to how Rails applications work. At every layer, whether it be in page rendering, database querying, or external data retrieval, the cache is what ensures that no single bottleneck brings down an entire application. 

缓存对于Rails应用程序的工作方式至关重要。在每一层,无论是页面渲染、数据库查询,还是外部数据检索,缓存都是确保没有任何一个瓶颈导致整个应用程序瘫痪的原因。

But caching has a dirty secret, and that secret’s name is Marshal.

但缓存有一个肮脏的秘密,这个秘密的名字是Marshal。

Marshal is Ruby’s ultimate sharp knife, able to transform almost any object into a binary blob and back. This makes it a natural match for the diverse needs of a cache, particularly the cache of a complex web framework like Rails. From actions, to pages, to partials, to queries—you name it, if Rails is touching it, Marshal is probably caching it. 

Marshal是Ruby的终极尖刀,能够将几乎所有的对象转化为二进制的blob,然后再返回。这使得它很自然地满足了缓存的各种需求,尤其是像Rails这样复杂的网络框架的缓存。从动作,到页面,到参数,到查询--你能想到的,如果Rails接触到它,Marshal可能就在缓存它了。

Marshal’s magic, however, comes with risks.

然而,Marshal的魔法也有风险。

A couple of years ago, these risks became very real for us. It started innocently enough. A developer at Shopify, in an attempt to clean up some code in our core monolith, shipped a PR refactoring some key classes around beta flags. The refactor got the thumbs up in review and passed all tests and other checks.

几年前,这些风险对我们来说变得非常真实。它开始的时候是很无辜的。Shopify的一个开发者,为了清理我们核心单体的一些代码,提交了一份PR,重构了一些围绕beta标志的关键类。这个重构在审查中被竖起了大拇指,并通过了所有的测试和其他检查。

As it went out to production, though, it became clear something was very wrong. A flood of exceptions triggered an incident, and the refactor was quickly rolled back and reverted. We were lucky to escape so easily.

然而,当它进入生产阶段时,很明显有些事情是非常错误的。大量的异常触发了一个事件,重构后的系统很快就被回滚和恢复了。我们很幸运能如此轻松地逃脱。

The incident was a wake-up call for us. Nothing in our set of continuous integration (CI) checks had flagged the change. Indeed, even in retrospect, there was nothing wrong with the code change at all. The issue wasn’t the code, but the fact that the code had changed.

这一事件给我们敲响了警钟。在我们的持续集成(CI)检查中,没有任何东西标记了这个变化。事实上,即使回过头来看,这个代码的改变也没有什么问题。问题不在于代码,而在于代码的改变

The probl...

开通本站会员,查看完整译文。

ホーム - Wiki
Copyright © 2011-2024 iteam. Current version is 2.129.0. UTC+08:00, 2024-07-06 15:29
浙ICP备14020137号-1 $お客様$