嗨,我有点想说,我的小型基准测试显示Play的性能无法与.net匹敌,至少在我的小型笔记本电脑中是这样。以下是详细信息:
播放代码
// Controller
public class Benchmark extends Controller {
@CacheFor
public static void hello() {
String who = "world";
render(who);
}
}
// View
hello ${who}!
ASP.Net代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Benchmark.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Hello <span id="spnName" runat="server"></span></p>
</div>
</form>
</body>
</html>
using System;
namespace Benchmark {
public partial class Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
spnName.InnerText = "world";
}
}
}
基准工具:ab,在同一台机器上运行:
`ab -n 10000 -c 100 http://localhost/`
播放结果:
Server Software: Play!
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 13 bytes
Concurrency Level: 100
Time taken for tests: 4.839 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3650000 bytes
HTML transferred: 130000 bytes
Requests per second: 2066.42 [#/sec] (mean)
Time per request: 48.393 [ms] (mean)
Time per request: 0.484 [ms] (mean, across all concurrent requests)
Transfer rate: 736.57 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 7
Processing: 5 48 7.0 45 79
Waiting: 2 33 11.3 34 74
Total: 5 48 7.1 45 80
Percentage of the requests served within a certain time (ms)
50% 45
66% 47
75% 49
80% 53
90% 58
95% 62
98% 69
99% 72
100% 80 (longest request)
asp.net结果:
Server Software: Microsoft-IIS/7.5
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 5160 bytes
Concurrency Level: 100
Time taken for tests: 3.806 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 53780000 bytes
HTML transferred: 51600000 bytes
Requests per second: 2627.28 [#/sec] (mean)
Time per request: 38.062 [ms] (mean)
Time per request: 0.381 [ms] (mean, across all concurrent requests)
Transfer rate: 13798.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 2
Processing: 6 38 3.8 37 61
Waiting: 4 27 7.6 28 57
Total: 6 38 3.8 37 61
Percentage of the requests served within a certain time (ms)
50% 37
66% 38
75% 39
80% 40
90% 43
95% 44
98% 48
99% 51
100% 61 (longest request)
注:
IIS预热非常快,运行基准测试2次以达到其峰值性能;而Play大约需要4到5次才能达到它的极限。
游戏在刺激模式下开始。
更改ab的并发设置不会对结果2产生太大影响。IIS总是表现出色。
我的机器的配置:windows 7(32位)在HP 4720s上,CPU:i5 M 430 2.27GHz 4核;内存4GB
所以我有点沮丧,因为我是一个超级游戏迷,在这个平台上工作了两年多。有人知道如何提高Play的性能吗?
以下是我的经历;
-
Play在linux/ngix或linux/apache上的运行速度比在windows/is 上快得多
-
play1.2.x的问题在于它的groovy(动态)渲染引擎;所以我建议播放2以获得性能和低内存使用率。正如你所知,play2的模板引擎是基于静态编译的scala代码的,我可以说play2是我见过的最快的web框架。
我认为您在play 1中遇到了默认groovy模板支持的糟糕性能。
在Play 2中,有一个更快的基于标量的模板引擎。
对于Play 1,还实现了许多其他模板系统,即:我认为是Japid。
此外:play 1有一个更快的groovy模板引擎实现,您可以在这里找到相关信息:http://kjetland.com/blog/2011/11/playframework-new-faster-groovy-template-engine/
很多时候,我们看到围绕框架的"炒作",找到真相的唯一方法是通过自己的测试或寻找专业的基准。我建议您检查基准结果"http://www.techempower.com/benchmarks/#section=data-r8&hw=i7&test=query"。如果你知道老式的"javaservletraw"在TOP性能框架列表中,而忽略了围绕"Non-Blocking"、Scala、NodeJS.的流行语,你会感到惊讶
与Play1相比,Play2可能有更好的性能,但"低内存使用率"绝对不是事实。运行bootstrap Play1应用程序仅消耗5000万内存,运行bootstrapp Play2应用程序可轻松消耗300多万内存。