分享、学习、提高
Thank you for reading...
2010/09/02 22:07
Tags: ,
连续两天有一大堆垃圾广告评论和留言,今天进后台一看,审核评论 (634 待审核),汗。。。这么多啊!还好后台有"一次性删除所有待审核的项目"的功能。还有一大堆自动通过审核的评论,手工删除了好几页。

都什么年代了,还在群发评论留链接。。。

无论是百度还是Google,早就把博客评论里的链接权重降的很低了,为什么还要化时间做这些事呢?
也许这种群发链接的方法现在还有一点点作用,但绝对属于黑帽SEO。
有这时间,不如好好的研究下如何提高网站的用户体验。。。

后台把 [url,<a 归入垃圾留言特征词汇,那种说一句话,留个网址的评论或留言也将会被当作垃圾评论或留言,并会自动屏蔽。
2010/08/27 17:39
Tags: , ,
先停掉syslog
service syslog stop

打开block dump:
echo 1 > /proc/sys/vm/block_dump

多次运行,查看结果
dmesg | egrep "READ|WRITE|dirtied" | egrep -o '([a-zA-Z]*)' | sort | uniq -c | sort -rn | head
排前的比较占用io

抓完后关掉block_dump和启动syslog:
echo 0 > /proc/sys/vm/block_dump
service syslog start
2010/08/22 19:01
Tags: ,
之前在看到可以关闭compile_check来减少模板编译文件的判断,这几天看了下 郭欣 的《构建高性能Web站点》,再次学到好东西。就是放弃smarty自带的缓存文件的判断,直接生成html文件,然后用stat来检查html文件的时间,用来判断是否缓存是否过期。代码类似:
    $cache_filename = 'cache/enjoy_'.$par.'.htm';
    $stat_info = @stat($cache_filename);
    if($stat_info && $stat_info[9] > time()-10800){
        echo file_get_contents($cache_filename);
        exit();
    }
    ......
    $html = $smarty->fetch($template_name,$par);
    file_put_contents($cache_filename,$html);
    echo $html;


用本机的程序测试了下,本机因为是测试环境,没有装apc。

ab.exe -n 100 -c 10 http://www.9enjoy.com/

没用使用smarty缓存,就1句速度很快的SQL查询语句
Document Path:          /
Document Length:        16787 bytes

Time taken for tests:   1.984 seconds
Total transferred:      1697100 bytes
HTML transferred:       1678700 bytes
Requests per second:    50.39 [#/sec] (mean)
Time per request:       198.438 [ms] (mean)
Time per request:       19.844 [ms] (mean, across all concurrent requests)
Transfer rate:          835.19 [Kbytes/sec] received

使用smarty缓存后:
Time taken for tests:   1.891 seconds
Total transferred:      1697100 bytes
HTML transferred:       1678700 bytes
Requests per second:    52.89 [#/sec] (mean)
Time per request:       189.063 [ms] (mean)
Time per request:       18.906 [ms] (mean, across all
Transfer rate:          876.60 [Kbytes/sec] received
没多大提高。

改造之后,但仍然先构造了smarty对象
Time taken for tests:   0.688 seconds
Total transferred:      1697100 bytes
HTML transferred:       1678700 bytes
Requests per second:    145.45 [#/sec] (mean)
Time per request:       68.750 [ms] (mean)
Time per request:       6.875 [ms] (mean, across all concurrent requests)
Transfer rate:          2410.65 [Kbytes/sec] received

显著提高啊!
把加载smarty的语句放在判断后:

Time taken for tests:   0.391 seconds
Total transferred:      1697100 bytes
HTML transferred:       1678700 bytes
Requests per second:    256.00 [#/sec] (mean)
Time per request:       39.063 [ms] (mean)
Time per request:       3.906 [ms] (mean, across all concurrent requests)
Transfer rate:          4242.75 [Kbytes/sec] received
再次大幅提高!


如果自定义了缓存文件名称,那么删除缓存文件就得另外写一个,不能使用smarty自带的。如果要使用smarty自带的删除功能,那么缓存文件就要使用smarty的方式来命名。如模板文件为index.html,那么生成的缓存文件为:%%77^774^774BE9C9%%index.html,如果加了hx这个$cache_id,那么缓存文件为:hx^%%77^774^774BE9C9%%index.html。这是怎么生成的呢?我根据smarty核心程序中的_get_auto_id和_get_auto_filename函数写了一个生成缓存文件名的一个函数。
function get_smarty_cachefile($cache_dir,$template_name,$cache_id=null){
    $_compile_dir_sep = '^';
    $_return = $cache_dir.DIRECTORY_SEPARATOR;
    if(isset($cache_id)) {
        $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($cache_id)));
        $_return .= $auto_id . $_compile_dir_sep;
    }  
    
    $_filename = urlencode(basename($template_name));
    $_crc32 = sprintf('%08X', crc32($template_name));
    $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .
              substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
    $_return .= '%%' . $_crc32 . '%%' . $_filename;
    return $_return;
}
这个函数,未考虑缓存目录分级,如果有使用缓存目录分级$smarty->use_sub_dirs=true,那么只需要把$_compile_dir_sep = '^';改为$_compile_dir_sep =DIRECTORY_SEPARATOR即可。
如上例:            
$cache_filename = get_smarty_cachefile('cache',$template_name,'hx');
这样就可以使用$smarty->clear_cache($template_name, 'hx')来删除这个缓存文件。

这样,只需要更改判断是否有缓存的代码,尽量把加载smarty的代码和初始化smarty放到判断之后,其他的不用考虑,就可以享受smarty性能的提升了。
2010/08/07 11:29
Tags: , ,
今天抽空分别在三个http下(apache,nginx,nginx proxy)用ab测试一下读取静态文件的反应时间。
ab.exe -c 10 -n 100 http://www.9enjoy.com/css/hx.css
Document Path:          /css/hx.css
Document Length:        215 bytes

Concurrency Level:      10
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      38300 bytes
HTML transferred:       21500 bytes

apache
Time taken for tests:   5.297 seconds
              min  mean[+/-sd] median   max
Connect:       16   52 296.3     16    2984
Processing:    16  462 915.0    203    4047
Waiting:       16  246 688.7    109    4047
Total:         47  514 951.7    219    4063


nginx
Time taken for tests:   4.859 seconds
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       16   48 295.1     16    2969
Processing:    16  427 897.8    156    4359
Waiting:       16  191 599.0     94    4359
Total:         47  475 936.5    172    4375


nginx proxy
Time taken for tests:   4.219 seconds
              min  mean[+/-sd] median   max
Connect:       16   18   5.8     16      31
Processing:    31  184 289.0    156    3031
Waiting:       16  123 297.2     94    3031
Total:         47  202 288.8    188    3047

这个文件比较小,在来个稍大一点的测试JQuery v1.3.2
ab.exe -c 10 -n 50 http://www.9enjoy.com/js/jquery.js

Document Path:          /js/jquery.js
Document Length:        57254 bytes

Concurrency Level:      10
Complete requests:      50
Failed requests:        0
Write errors:           0
Total transferred:      2880700 bytes
HTML transferred:       2862700 bytes

apache
Time taken for tests:   34.688 seconds
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       16   22   7.7     16      31
Processing:   438 4861 7810.7   1313   31031
Waiting:       16  827 3082.5     31   21078
Total:        469 4883 7811.5   1328   31047

nginx
Time taken for tests:   29.875 seconds
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       16   20   7.1     16      31
Processing:   438 4940 6601.4   1703   23484
Waiting:       16  574 1563.6     16    9016
Total:        453 4960 6601.6   1734   23516

nginx proxy
Time taken for tests:   28.484 seconds
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       16   19   6.7     16      31
Processing:   406 4532 6301.3   1875   28375
Waiting:       16 1234 4325.4     31   21031
Total:        422 4552 6301.6   1891   28391


测试结果,读取静态文件,nginx_proxy最快,nginx比apache略快一点点。
测试可能受网络和负荷的影响,但基本上是这个结果。
2010/08/06 14:01
Tags: , ,
在日志中看到如下信息:
引用
220.181.32.23 - - [06/Aug/2010:13:47:30 +0800] "GET /hx.htm HTTP/1.1" 200 3155 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; baidu Transcoder;)" -
220.181.108.46 - - [06/Aug/2010:13:53:54 +0800] "GET / HTTP/1.1" 200 3216 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; baidu Transcoder;)" -

baidu Transcoder,这是什么?

搜索了下,原来是Baidu对手机用户访问网页时提供实时转换的一个独立服务。

可以参见,百度百科对Transcoder的说明:http://baike.baidu.com/view/2140769.htm

我在手机上使用百度m.baidu.com搜索后,点开的页面就是经过了baidu的Transcoder处理后显示的,以智能的适应手机的版面,并能把大图变小图,节省一些手机上网所占的流量。如查看9enjoy首页:http://gate.baidu.com/tc_path/pn=9/bd_page_type=1/pu=0/t=0/?&m=1155&noopen=1&src=http%3A%2F%2Fwww%2E9enjoy%2Ecom#tc_area_4

有些人说baidu Transcoder是拔毛蜘蛛,显然是不对的。
分页: 1/94 第一页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]