Published June 6th, 2006 in WWW
keep alive通俗地讲,就是所谓的常连接。常连接节省了TCP连接过程的开销,有一定的优势。现有操作系统越来越先进,建立连接的开销越来越小,比如linux 2.6的epoll,freebsd的kqueue,可以让程序不fork进程或开线程就能同时服务N多连接。与此同时,客户端比如IE,Firefox却可以同时开多个线程取内容,如果开了Keep alive,反而不好。因此一般情况下不需Keep Alive
Keywords:
FreeBSD,
Linux,
Keep Alive,
Apache,
常连接
Published May 14th, 2006 in FreeBSD
Test bed: P3M 800M Hz, 512M RAM, FreeBSD 6.1-STABLE, Apache 2.2.2, libkse.
root@dell 9:32pm ~$# more /etc/libmap.conf
[httpd]
libpthread.so.2 libthr.so.2
libpthread.so libthr.so
testing command: /usr/local/apache2/bin/ab -n 10000 -c 500 http://192.168.0.5/manual/
conclusion: for static page, event mpm has very little difference with worker mpm.
显示正文 »
1) Apache 2.2.2 with worker mpm:
Concurrency Level: 500
Time taken for tests: 11.641157 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 80180000 bytes
HTML transferred: 75960000 bytes
Requests per second: 859.02 [#/sec] (mean)
Time per request: 582.058 [ms] (mean)
Time per request: 1.164 [ms] (mean, across all concurrent requests)
Transfer rate: 6726.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 5
Processing: 71 567 74.4 581 676
Waiting: 29 299 152.0 300 646
Total: 71 567 74.4 581 676
Percentage of the requests served within a certain time (ms)
50% 581
66% 586
75% 590
80% 595
90% 618
95% 633
98% 651
99% 662
100% 676 (longest request)
2) Apache 2.2.2 with event mpm
Concurrency Level: 500
Time taken for tests: 11.780208 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 80180000 bytes
HTML transferred: 75960000 bytes
Requests per second: 848.88 [#/sec] (mean)
Time per request: 589.010 [ms] (mean)
Time per request: 1.178 [ms] (mean, across all concurrent requests)
Transfer rate: 6646.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 7
Processing: 41 573 69.9 587 649
Waiting: 27 295 154.6 294 612
Total: 41 573 69.9 587 649
Percentage of the requests served within a certain time (ms)
50% 587
66% 592
75% 596
80% 599
90% 609
95% 613
98% 635
99% 643
100% 649 (longest request)
Keywords:
Apache,
FreeBSD,
event,
worker,
benchmark
Published May 13th, 2006 in WWW
相信有很多朋友深受baidu spider的苦,经常被扒去上G流量;如果不是水平差,那就是故意这么做。今天花点时间写了apache antibot module,结合mod_setenvif 和 mod_limitipconn两个module的思路,达到对特定user agent的ip连接数量限制。
2006/05/16 更新:修改了NoBot参数的匹配规则。上版本用的是PCRE匹配,多个匹配起来比较麻烦,改成了用空格分隔的区分大小写字符串匹配。
NoBot "audio/ video/" "Google Baidu" 将匹配audio和video文件,GoogleBot和Baiduspider都会被404错误。
2006/05/14 更新:增加NoBot参数,可以让bot不索引你的某些文件(比如mp3,wmv)。
apache带的mime.types文件内容比较老,把wmv加到video/mpeg行的后面支持wmv
源代码下载
显示正文 »
安装过程:(假定apache 2.0.x是安装在/usr/local/apache2目录下)
tar xfz mod_antibot.tar.gz
make install
然后在httpd.conf 中增加
ExtendedStatus On
<IfModule mod_antibot.c>
BotLimit 3 "baiduspider"
Log2Err 1
NoBot "audio/ video/" "Google Baidu"
</IfModule>
设置对baiduspider的最大连接数为3,然后restart apache。
注意要设置ExtendedStatus On,antibot module才能读到其它连接的ip信息。
BotLimit的第二个参数是正则表达式,不区分大小写,它要用引号括起来。
NoBot 让符合文件类型的不被Bot索引,返回HTTP 404 NOT FOUND代码,用法参见上面的例子。
Log2Err参数设置是否记录日志,缺省不记录。
适当时候,可以在apache的errorlog看到类似的消息;)
[Fri May 12 23:47:14 2006] [error] [client 202.108.250.243] Rejecting the 4 Baiduspider+(+http://www.baidu.com/
search/spider.htm) bot, max 3 bots;)
[Sun May 14 13:58:36 2006] [error] [client 202.108.250.243] Rejecting the baiduspider bot for /video/xxx.wmv
其它不好的bot可如法炮制。
Update:一般baiduspider会通过好多个IP来扒,所以每个ip给它两个spider连接就够了
Keywords:
Apache,
patch,
补丁,
优化
Published May 6th, 2006 in Tech
经过血的教训,只要apache用worker模式,php的pconnect方法不会自动释放连接;测试过mysql,memcache的pconnect,操作系统是FreeBSD或Linux。pconnect看上去挺美,实际不美,请各位慎用pconnect
Keywords:
PHP,
Apache
Published April 7th, 2006 in WWW
今天下午突然发现网站流量大增,每小时流量到了500M,大吃一惊,赶快查apache log,发现是mp3 在线试听功能搞的鬼。
其中有一个IP居然试听了林晓培的心动MP3超过100次,万般无奈之下拿起apache武器,把在线试听功能封了,下载功能仍然保留。在httpd.conf增加如下参数:
SetEnvIf Request_URI "(.)+\.(mp3|ape)" mp3_ref=1
BrowserMatchNoCase ^nsplayer !mp3_ref
Order Allow,Deny
Allow from env=mp3_ref
同时探究这么多人喜欢本网站MP3的原因:
搜索“心动 林晓培”,本站的MP3也在结果中,由于本站的MP3文件大小是5.1M,最大,用户因此判断这个版本比其它的好,下载自然多了。
Keywords:
baidu,
百度,
Apache,
在线试听
Published March 17th, 2006 in Tech
就自己关心的技术关键用Google搜索对比流行度(从高到低排序):
- 中文网页中,约有 214,000,000 项符合php的查询结果
- 中文网页中,约有 29,000,000 项符合linux的查询结果
- 中文网页中,约有 24,200,000 项符合java的查询结果
- 中文网页中,约有 3,290,000 项符合freebsd的查询结果
- 中文网页中,约有 2,250,000 项符合wordpress的查询结果
- 中文网页中,约有 498,000 项符合squid的查询结果
- 中文网页中,约有 413,000 项符合qmail的查询结果
- 中文网页中,约有 311,000 项符合postfix的查询结果
- 中文网页中,约有 245,000 项符合apache module的查询结果
- 中文网页中,约有 128,000 项符合berkeley db的查询结果
- 中文网页中,约有 63,400 项符合memcache的查询结果
熟悉的postfix,apache module, berkeley db, memcache被压迫在最底层,加起来的和还不如Wordpress,这给我们指明了技术的出路;)
Keywords:
技术,
postfix,
apache
Published March 8th, 2006 in Tech
mod_alias 适合做一些简单的重定向,比mod_rewrite效率高。Alias参数重定向URI到本地URI;Redirect参数重定向URI到URL的。RedirectMatch ^/www/(.*) http://exampe.com/$1 把www目录的所有访问转到其它URL,但你也想过www下的部分文件、目录不重定向,下面补丁就派上用场。
下载地址:mod_alias.c.patch
显示正文 »
补丁过程:
cd http-2.0.55
patch -p0 < ../mod_alias.c.patch
make install
使用举例:
# File
NoRedirect ^/www/(img_auth\.php|index\.php)$
# Directory
NoRedirect ^/www/(docs|config|includes|images|index\.php)/
# All Others go to new URL
RedirectMatch ^/www/(.+)$ http://www.examples.com/$1
Keywords:
Apache,
补丁,
patch