简体   繁体   English

高流量栏杆性能调整

[英]High traffic rails perf tuning

I was attempting to evaluate various Rails server solutions. 我试图评估各种Rails服务器解决方案。 First on my list was an nginx + passenger system. 我名单上的第一个是nginx +乘客系统。 I spun up an EC2 instance with 8 gigs of RAM and 2 processors, installed nginx and passenger, and added this to the nginx.conf file: 我启动了一个具有8个RAM和2个处理器的EC2实例,安装了nginx和passenger,并将其添加到nginx.conf文件中:

passenger_max_pool_size 30;
passenger_pool_idle_time 0;
rails_framework_spawner_idle_time 0;
rails_app_spawner_idle_time 0;
rails_spawn_method smart;

I added a little "awesome" controller to rails that would just render :text => (2+2).to_s 我在rails上添加了一个“真棒”控制器,它将仅render :text => (2+2).to_s

Then I spun up a little box and ran this to test it: 然后我旋转了一个小盒子并运行它进行测试:

ab -n 5000 -c 5 'http://server/awesome'

And the CPU while this was running on the box looked pretty much like this: 在盒子上运行时的CPU看起来非常像这样:

05:29:12 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
05:29:36 PM     all     62.39      0.00     10.79      0.04     21.28      5.50

And I'm noticing that it takes only 7-10 simultaneous requests to bring the CPU to <1% idle, and of course this begins to seriously drag down response times. 而且我注意到,仅需要7-10个并发请求即可将CPU置于<1%的空闲状态,这当然会严重缩短响应时间。

So I'm wondering, is a lot of CPU load just the cost of doing business with Rails? 所以我想知道,大量的CPU负载仅仅是与Rails开展业务的成本吗? Can it only serve a half dozen or so super-cheap requests simultaneously, even with a giant pile of RAM and a couple of cores? 即使有大量的RAM和几个内核,它也只能同时满足六打左右的超便宜请求吗? Are there any great perf suggestions to get me serving 15-30 simultaneous requests? 有什么很棒的性能建议可以使我同时处理15-30个请求?

Update: tried the same thing on one of the "super mega lots and lots of CPUs" EC2 thing. 更新:在“超级批处理和大量CPU” EC2之一中尝试了相同的操作。 Holy crap was that a lot of CPU power. 废话是很多CPU能力。 The sweet spot seemed to be about 2 simultaneous requests per CPU, was able to get it up to about 630 requests/second at 16 simultaneous requests. 最有效的地方似乎是每个CPU大约2个并发请求,能够在16个并发请求下将其提高到每秒630个请求。 Don't know if that's actually cost efficient over a lot of little boxes, though. 不过,不知道在许多小盒子上这是否真正具有成本效益。

I must say that my Rails app got a massive boost to supporting about 80 concurrent users from about 20 initially supported after adding some memcached servers (4 mediums at EC2). 我必须说,在添加了一些内存缓存服务器(EC2中的4种介质)之后,我的Rails应用程序从最初支持的约20个用户中获得了极大的支持。 I run a high traffic sports site that really hit it a few months ago. 我经营着一个高流量的体育网站,几个月前真的很受欢迎。 Database size is about 6 gigs with heavy updates/inserts. 数据库大小约为6演出,其中包含大量更新/插入。

MySQL (RDS large high usage) cache also helped a bit. MySQL(RDS高使用率)高速缓存也有所帮助。

I've tried playing with the passenger settings but got some curious results - like for example each thread eats up 250 megs of RAM which is odd considering the application isn't that big. 我试过玩乘客设置,但得到了一些奇怪的结果-例如每个线程吃掉250兆的RAM,考虑到应用程序不是那么大,这很奇怪。

You can also save massive $ by using spot instances but don't rely entirely on that - their pricing seems to spike on occasion. 您还可以通过使用竞价型实例节省大量资金,但不要完全依靠它-它们的价格有时会飙升。 I'd AutoScale with two policies - one with spot instances and another with on demand (read: reserved) instances. 我将使用两种策略进行自动缩放-一种具有竞价型实例,另一种具有按需(读:保留)实例。

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

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