Apache 上面运行 Asp.NET 配置与性能测试
昨天测试了一下在 Apache 下面部署 Asp.NET (3.5) 的网站,其实一开始就在想这东西效率应该不会好多少。后面经过多番测试的确是要比 IIS 慢许多。我是拿公司的项目做的测试,这是一个 Web2.0 网站,功能还是算比较多,很多种应用都有,除了一开始修改了一点点 Rewrite 以外,其它的功能完全能用,没发现任何问题。
先说一下我的安装过程:
Apache 的安装我这里就不说了
需要下载 mod_aspdotnet 这个 Apache Module
项目地址:http://sourceforge.net/projects/mod-aspdotnet
安装过程很简单,只要选对 Apache 的安装目录就好了,并且安装程序会自动发现 Apache 的安装位置的。
修改 httpd.conf (source)
# 添加 80 端口的监听 (得要把 IIS 停了,当然也可以换 8080 或其它,哪么下面的端口号也要跟着改)
Listen 80
# 添加 Module 引用
LoadModule aspdotnet_module modules/mod_aspdotnet.so
# 添加 Handler
AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo
# 加入新的 关于 mod_aspdotnet 的 IfModule
<IfModule mod_aspdotnet.cpp>
# For all virtual ASP.NET webs, we need the aspnet_client files
# to serve the client-side helper scripts.
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
Options FollowSymlinks
Order allow,deny
Allow from all
</Directory>
</IfModule>
# 配置虚拟主机
NameVirtualHost *
# tmitter app Config
<VirtualHost *:80>
ServerName www.tmitter.us
DocumentRoot D:/work/tmitter
AspNetMount / "D:/work/tmitter"
<Directory "D:/work/tmitter/www">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
AllowOverride All
Allow from all
DirectoryIndex index.html default.aspx
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName static.tmitter.us
DocumentRoot D:/work/tmitter/static
AspNetMount / "D:/work/tmitter/static"
<Directory "D:/work/tmitter/static">
Options FollowSymlinks ExecCGI
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
AllowOverride All
Allow from all
DirectoryIndex index.html default.aspx
</Directory>
</VirtualHost>
配置本地域名解析 hosts 文件
打开 c:\windows\system32\drivers\etc\hosts 这个文件,并加入
127.0.0.1 www.tmitter.us
127.0.0.1 static.tmitter.us
最后保存,这里名字和解析的细节跟据自已需求修改。
最后保存重启 Apache,重启过程会有些慢,估计是在编译 Asp.net 程序。完成后,打开 http://www.tmitter.us就可以看到效果了。
性能测试
我用的是公司的项目,这里面有使用 Memcached 做页面缓存的,但从 Url 请求到 Memcached 取数据中间还有一些逻辑,现在我开着缓存测试,结果是差距很明显。
ab -n 2000 -c 200 http://www.tmitter.us/
Apache 测试结果:
Server Software: Apache/2.2.9
Server Hostname: www.ytrip.com.tw
Server Port: 80
Document Path: /
Document Length: 28316 bytes
Concurrency Level: 200
Time taken for tests: 17.922 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 57240000 bytes
HTML transferred: 56632000 bytes
Requests per second: 111.60 [#/sec] (mean)
Time per request: 1792.188 [ms] (mean)
Time per request: 8.961 [ms] (mean, across all concurrent requests)
Transfer rate: 3119.01 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.3 0 16
Processing: 31 1782 3108.0 313 11484
Waiting: 16 1772 3101.9 313 11469
Total: 31 1783 3108.0 313 11484
Percentage of the requests served within a certain time (ms)
50% 313
66% 516
75% 797
80% 4484
90% 9016
95% 9453
98% 10781
99% 11031
100% 11484 (longest request)
IIS 测试结果:
Server Software: Microsoft-IIS/6.0
Server Hostname: www.ytrip.com.tw
Server Port: 80
Document Path: /
Document Length: 28316 bytes
Concurrency Level: 200
Time taken for tests: 1.344 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 57184000 bytes
HTML transferred: 56632000 bytes
Requests per second: 1488.37 [#/sec] (mean)
Time per request: 134.375 [ms] (mean)
Time per request: 0.672 [ms] (mean, across all concurrent requests)
Transfer rate: 41558.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.2 0 16
Processing: 63 125 16.5 125 156
Waiting: 47 119 18.2 125 141
Total: 63 125 16.5 125 156
Percentage of the requests served within a certain time (ms)
50% 125
66% 141
75% 141
80% 141
90% 141
95% 141
98% 141
99% 141
100% 156 (longest request)