简体   繁体   English

1个CPU上的Ruby机架应用程序 - 我应该运行多少个进程?

[英]Ruby rack app on 1 CPU - how many processes should I run?

I'm quite new to Ruby web apps (coming from java). 我是Ruby网络应用程序的新手(来自java)。 I have VPS that has 1 CPU and 2GB of RAM and would like to play with some rails/sinatra stuff. 我有VPS,有1个CPU和2GB的RAM,想玩一些rails / sinatra的东西。

I'm using Ruby 2.1.0 MRI How does number of CPUs maps to number of web server's processes I need to run? 我正在使用Ruby 2.1.0 MRI如何将CPU数量映射到我需要运行的Web服务器进程数量? I use puma as a web server and have default threads (0,16) set up. 我使用puma作为Web服务器并设置了默认线程(0,16)。 But I noticed there is also "workers" option that forks another process to better handle multiple requests. 但是我注意到还有“工作者”选项,它会让另一个进程更好地处理多个请求。

Do I understand correctly that for such setup (1 CPU) there is no point in running 2 web server processes? 我是否正确理解对于这样的设置(1个CPU),运行2个Web服务器进程没有意义? The only reasonable setup is 1 process with threads? 唯一合理的设置是1个进程与线程?

Oh now this is a pretty big question! 哦,现在这是一个非常大的问题!

The number of processes and threads aren't necessarily linked to the number of CPU's. 进程和线程的数量不一定与CPU的数量相关联。 It's more a case of the amount of memory available, the amount of concurrent requests and the amount of 'locking' stuff that's going on. 更多的是可用内存量,并发请求数量以及正在进行的“锁定”内容量。

If you're going to have long running requests that block other requests, then having additional processes can help with that. 如果您将有长时间运行的请求阻止其他请求,那么拥有其他进程可以帮助解决这个问题。 You can still have more than one process with a single CPU. 使用单个CPU仍然可以有多个进程。

There are a number of different servers in Ruby that handle scaling in different ways, Unicorn, Puma, Thin are some of them. Ruby中有许多不同的服务器以不同的方式处理扩展,Unicorn,Puma,Thin就是其中的一部分。 Doing a search on Unicorn vs Puma vs Thin can turn up some useful blog posts on the topic. 对Unicorn vs Puma vs Thin进行搜索可以在该主题上发布一些有用的博客文章。

Here's a couple 这是一对夫妇

http://ylan.segal-family.com/blog/2012/08/20/better-performance-on-heroku-thins-vs-unicorn-vs-puma/ https://www.engineyard.com/articles/rails-server https://www.ruby-forum.com/topic/1822610 http://ylan.segal-family.com/blog/2012/08/20/better-performance-on-heroku-thins-vs-unicorn-vs-puma/ https://www.engineyard.com/articles/ rails-server https://www.ruby-forum.com/topic/1822610

And some information on concurrency in Ruby http://merbist.com/2011/02/22/concurrency-in-ruby-explained/ 以及关于Ruby并发性的一些信息http://merbist.com/2011/02/22/concurrency-in-ruby-explained/

The TL:DR answer is, it depends! TL:DR答案是,这取决于!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM