码头是轨道上宝石GIL限制的可能解决方案吗? [英] Is docker a possible solution to ruby GIL limitation in rails?

查看:163
本文介绍了码头是轨道上宝石GIL限制的可能解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是一个想法,让我知道如果我缺少任何东西,或者如果它是一个好的。



通常有N rails进程运行在单个服务器/ VM上,但是由于GIL(Global Interpreter Lock),它们无法执行。



而不是在单个服务器中运行N个进程,我可以运行每个N个容器每个都有一个导轨进程(每个容器在不同的端口上运行)。



以这种方式,我应该能够并行执行更多的rails进程?



我猜容器会增加开销,但可能有意义。



任何意见?



谢谢

解决方案

这比运行N进程的效率要差得多。这里的简单原因是,大多数Ruby on Rails的进程管理器都使用前叉模式,其中在进程被拆分之前加载了大量代码。



<两个进程的p> A fork 使用非常少的额外内存,第二个进程继承了第一个的近似精确副本。任何对此的更改都会引起更多的内存开销,但是像Rails库和其他宝石这样的东西也不会改变,基本上是免费的。



如果你有多个进程是独立的,每个进程都需要加载,解析和初始化运行Rails所需的每个Ruby类。



这并不是说容器 - 但是它可能需要一个混合方法:N个容器,每个M个进程。



记住,如果你真的有麻烦的GIL ,只需使用没有一个的 Jruby


This is just an idea, let me know if I'm missing anything or if it could be a good one.

It's common to have N rails processes running on a single server/VM, but they can't perform at best due GIL (Global Interpreter Lock).

Instead of running N processes inside a single server I could run N containers each one with a single rails process (each one running on a different port).

In this way I should be able to execute more rails processes in parallel, right?

I guess containers add overhead but probably it could make sense anyway.

Any opinions?

Thank you

解决方案

This would be far less efficient than running N processes. The simple reason here is that most process managers for Ruby on Rails use the "pre-fork" model where a large amount of code is loaded in before the processes are split off.

A fork of two process uses very little additional memory, the second process inherits a near exact copy of the first. Any changes made to this will incur more memory overhead, but as things like the Rails library and other gems are not changed, that comes along for free, basically.

If you had multiple processes that are independent, each would need to load, parse, and initialize every Ruby class necessary to run Rails.

This isn't to say that the container-ized approach isn't without merit, but it may necessitate a hybrid approach: N containers with M processes each.

Remember, if you're really having trouble with the GIL, just use Jruby which doesn't have one.

这篇关于码头是轨道上宝石GIL限制的可能解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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