由于项目需要,新房的售罄楼盘需要展示二手房的页面,即url一致,有以下几种方案:
1. 新房php使用curl调用二手房页面并返回给客户端
2. php再套一遍二手房的模板,不过这样二手房新做的页面和以后的页面维护都会落在新房这里。
3. 使用openresty将重合的url分离出group_id,然后判断销售状态,再决定是代理到新房的服务器还是二手房的服务器
第一种简单。但是性能是最差的。
第二种对于业务来说也是不合理的。项目过来以后。会再给项目组多一个从吗?显然不会。。而且以后维护会到新房这里
第三种是最优的。写一小段lua代码。连上redis。取销售状态。再决定proxy_pass到哪个upstream。
然而运维对于这种方式不太感冒。觉得性能会牺牲。那么咱们就来测一下。。
1. redis进程池使用100,keepalive_time 设置为60s 2. lua_code_cache on;
为了公平起见。不做真正的proxy_pass代理。只ngx.say出来需要选择的upstream
location / { default_type text/html; set $target ""; set $r_status ""; rewrite_by_lua_file "/home/shijingbo/lua/rewrite.lua"; content_by_lua ' ngx.say(ngx.var.target) '; #content_by_lua_file "/home/shijingbo/lua/content.lua"; #proxy_set_header Host "$host"; #proxy_pass http://$target; }
webbench 5000并发 运行60s结果如下:
不加lua dict缓存的情况下:
root@hackers365-HP-Compaq-Elite-8300-SFF:/data/software/webbench-1.5# ./webbench -t 60 -c 5000 'http://bd.focus.cn:8080/loupan/123.html' Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://bd.focus.cn:8080/loupan/123.html 5000 clients, running 60 sec. Speed=925107 pages/min, 2343632 bytes/sec. Requests: 925107 susceed, 0 failed.
加lua dict缓存的情况下:
root@hackers365-HP-Compaq-Elite-8300-SFF:/data/software/webbench-1.5# ./webbench -t 60 -c 5000 'http://bd.focus.cn:8080/loupan/123.html' Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://bd.focus.cn:8080/loupan/123.html 5000 clients, running 60 sec. Speed=1182816 pages/min, 2996619 bytes/sec. Requests: 1182816 susceed, 0 failed.
差不多每秒2w的并发。。谁还敢说慢?