2.4 request per second ........
http://blog.splayer.org/index.php/2010/10/performance-penalty-in-mvc-web-deployment/
PHP win!
我以前有个奇葩同事做性能测试。。。测出的结果是 7 request per second,然后发现他开的是 dev 模式,所以我搞不懂 2.4 是如何做到的?
#3 楼 @fresh_fish 这篇里提到的:http://www.aqee.net/php-needs-to-die-what-will-replace-it/
射手官网测试比较了下 php 和 ror 的性能,结果 php 赢得很彻底阿。
我就搜到了这篇文章,赢得很彻底。
测试了一下,用 passenger start -p 4000 -e production --max-pool-size 100 --min-instances 10 启动
ab -c 10 -n 100 http://localhost:4000/
按原文的代码
Server Software: nginx/1.2.3
Server Hostname: localhost
Server Port: 4000
Document Path: /
Document Length: 512451 bytes
Concurrency Level: 10
Time taken for tests: 21.563 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 51319400 bytes
HTML transferred: 51245100 bytes
Requests per second: 4.64 [#/sec] (mean)
Time per request: 2156.277 [ms] (mean)
Time per request: 215.628 [ms] (mean, across all concurrent requests)
Transfer rate: 2324.22 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 1273 2107 311.6 2128 2994
Waiting: 1273 2106 311.6 2128 2994
Total: 1273 2107 311.7 2128 2994
Percentage of the requests served within a certain time (ms)
50% 2128
66% 2290
75% 2336
80% 2362
90% 2460
95% 2544
98% 2747
99% 2994
100% 2994 (longest request)
把 view 里面的循环移到 controller
class MainController < ApplicationController
def index
sleep(0.2)
@content = 128000.times.map{rand(8999)+1000}.join
end
end
<%= @content %>
结果有了不少改善
Server Software: nginx/1.2.3
Server Hostname: localhost
Server Port: 4000
Document Path: /
Document Length: 512451 bytes
Concurrency Level: 10
Time taken for tests: 4.817 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 51319400 bytes
HTML transferred: 51245100 bytes
Requests per second: 20.76 [#/sec] (mean)
Time per request: 481.690 [ms] (mean)
Time per request: 48.169 [ms] (mean, across all concurrent requests)
Transfer rate: 10404.33 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 363 466 97.4 442 768
Waiting: 362 465 97.2 442 768
Total: 363 466 97.4 442 768
Percentage of the requests served within a certain time (ms)
50% 442
66% 480
75% 502
80% 513
90% 593
95% 735
98% 767
99% 768
100% 768 (longest request)
结论是
循环放在 View 里面的日志
Started GET "/" for 127.0.0.1 at 2012-11-24 22:20:45 +0800
Processing by MainController#index as */*
Rendered main/index.html.erb within layouts/application (1670.9ms)
Completed 200 OK in 1873ms (Views: 1672.4ms | ActiveRecord: 0.0ms)
移出后的日志
Started GET "/" for 127.0.0.1 at 2012-11-24 22:23:24 +0800
Processing by MainController#index as */*
Rendered main/index.html.erb within layouts/application (1.6ms)
Completed 200 OK in 410ms (Views: 3.1ms | ActiveRecord: 0.0ms)
可见效率是有差异的。不过我觉得一般不会用到 128000 这么大的循环,View 按正常写就行了。
顺便,我把模板从 erb 换到 slim,发现性能有提升
- 128000.times do
= rand(8999)+1000
Server Software: nginx/1.2.3
Server Hostname: localhost
Server Port: 4000
Document Path: /
Document Length: 512450 bytes
Concurrency Level: 10
Time taken for tests: 6.919 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 51319300 bytes
HTML transferred: 51245000 bytes
Requests per second: 14.45 [#/sec] (mean)
Time per request: 691.885 [ms] (mean)
Time per request: 69.188 [ms] (mean, across all concurrent requests)
Transfer rate: 7243.47 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 454 672 103.5 677 911
Waiting: 454 670 103.8 673 910
Total: 454 672 103.5 677 911
Percentage of the requests served within a certain time (ms)
50% 677
66% 709
75% 753
80% 778
90% 808
95% 864
98% 880
99% 911
100% 911 (longest request)
Started GET "/" for 127.0.0.1 at 2012-11-24 22:26:31 +0800
Processing by MainController#index as */*
Rendered main/index.html.slim within layouts/application (703.5ms)
Completed 200 OK in 905ms (Views: 704.9ms | ActiveRecord: 0.0ms)
Rendered main/index.html.slim within layouts/application (482.9ms)
Completed 200 OK in 685ms (Views: 484.5ms | ActiveRecord: 0.0ms)
@luikore 也就是说 第一次运行某个页面的时候会较慢 以后直接使用编译好的 view 这也就呵 jsp -》servlet 的模式就类似了 我理解的对吧?
#16 楼 @luikore https://speakerdeck.com/m_seki/rails-is-a-follower 这个 slide 里第三页有提到《The ERB Book》但是我搜不到这本书..
@luikore 推测是首次访问编译,这个可以看 log 的 view 的执行时间推测 但我有疑问 xdite 提到过代码放 erb 里的执行效率不如放 helper 里 并建议让 view 尽可能的轻 复杂的判断可以放到 helper 里 如果 erb 会被转换成一个方法的话 那这样的看法就是说不通的了啊
@hooopo http://www.kuwata-lab.com/erubis/users-guide.05.html#rails-preprocessing
处理模板的方式 guide 里似乎没有涉及 不过这节似乎有些用处
If you use '[%= %]' instead of '<%= %>', preprocessor evaluate it only once when template is loaded.
我看,没有更好的,只有更适用的,rails 也可以做到 php 那样,只要你写的够好,如果没有到非得去优化性能或者通过系统管理员架构调优去节约成本,做其他得优化都是空谈
PHP 比 ruby 运行快,从项目来看,好像是这样。 很多细节就决定了的。就像写完了 ruby,再来写 php 要想吐一样,这个也是其语言本身很多细节就决定了的。没有人去跟 c 比。 ==>>正常情况下,就不必深究这个了。要是有人诋毁,就喷他~~
rails。 实事求是,说法不够精确。没有像射手应用那样搞测试。只是从使用中的感觉来比较的。 从语言和框架的设计角度来看,也应该如此。 另外,搞这种对比的东西,最好是能深入理解对比对象的原理,思想,运行方式,优化方式等。 一般的二流公司不太适合搞咨询。
看你关注什么了,关注性能的话,用 Rails 可能不是最好的选择。 对于一般网站来说更看重的是开发成本。性能是在做大之后才考虑的事情。 公司做大了,有钱了再换语言嘛。。 http://www.csdn.net/article/2012-10-08/2810589