If web architectures, performance, or scalability are topics you would like to keep on top of (who doesn't!), then chances are, you've heard of Nginx ("engine x"). Originally developed by Igor Sysoev for rambler.ru (second largest Russian web-site), it is a high-performance HTTP server / reverse proxy known for itsstability, performance, and ease of use. The great track record, a lot of great modules, and an active development community have rightfully earned it a steady uptick of users, and most recently, a notable mention in the Netcraft report.
Memcached module - an easy 4x speed multiplier
Memcached, the darling of every web-developer, is capable of turning almost any application into a speed-demon. Benchmarking one of my own Rails applications resulted in ~850 req/s on commodity, non-optimized hardware - more than enough in the case of this application. However, what if we took Mongrel out of the equation? Nginx, by default, comes prepackaged with the Memcached module, which allows us to bypass the Mongrel servers and talk to Memcached directly. Same hardware, and a quick test later: ~3,550 req/s, or almost a 400% improvement! Not bad for a five minute tweak!
Think smart, forget cache invalidations
The only snag in our scheme for easy performance gains comes with the fact that more often than not, our application servers contain additional caching policies (read invalidations / authentication), and MIME type logic. The former, as recently documented by Tobias Lütke and Geoffrey Grosenbach, if properly thought through can be solved with some clever URL rewriting policies and automatic TTL timeouts. When implemented correctly, we could simply set the memcached key to be the full request URL, allowing us to completely bypass our app. servers.
MIME-type logic
MIME type magic can be as easy as complex as we wish. If you only serve one content type ('text/html', for example), the solution is simple:
> nginx-default.conf
location /dynamic_request {
# Set default type to text/html
default_type text/html;
# ...
}
Dynamic argument types, just for fun
However, if we want to serve multiple content-types, or perhaps even parameterize the request type in a query string, we've got some extra work to do. Not unlike any other HTTP server, Nginx checks the filetype extension at the end of every request path to determine the correct content-type header, a solution which unfortunately breaks down in majority of modern, URL friendly web-applications:
1. GET /dynamic_request.js - Content-Type = text/javascript
2. GET /dynamic_request - Content-Type = ?
3. GET /dynamic_request?format=js - Content-Type = ?
Case 1 is easily solved by Nginx directly. Case 2 is tricky, but can be solved via a 'default_type' line in the config as document above. And case 3 will require some additional logic - namely, we can hardcode a rule to rewrite our dynamic query string parameters to automagically add an extension to the path of each incoming request:
> nginx-rewrite.conf
location /dynamic_request {
# append an extenstion for proper MIME type detection
if ($args ~* format=json) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.js$1 break; }
if ($args ~* format=xml) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.xml$1 break; }
memcached_pass 127.0.0.1:11211;
error_page 404 = @dynamic_request;
}
Downloads: 9549 File Size: 1.4 KB
That should do the trick! Cache invalidations are handled, MIME types are served correctly, and our app. servers are bypassed in 95%+ of the cases. Instead, Nginx talks directly to Memcached and only proxies the cache misses - an easy 400% performance boost!
分享到:
相关推荐
nginx和memcached配置tomcat的jar包
nginx+memcached+tomcat搭建集群环境。
在windows系统上nginx+memcached+tomcat的负载均衡 相关配置过去请查看 http://blog.csdn.net/xu_xiao_ji/article/details/51682693
将附件压缩包的nginx-conf文件夹下的nginx.conf文件放到/nginx-1.10.1/conf/下替换旧的 双击nginx.exe 命令行cd 到根目录然后执行 (1)nginx -t 检查nginx.conf是否正确 (2)nginx -s reload 重启nginx 3 将...
nginx tomcat 配置完整,只需要把项目放到tomcat下。 tomcat端口是8081,8082;nginx端口是8080
Nginx-1.6.2+Memcached-1.2.6+Tomcat7负载均衡实现Session共享 搭建所需要的JAR包文件, 请复制到Tomcat Lib目录下, 搭建方法, 请查看博客:http://blog.csdn.net/army16/article/details/40585637
tomcat memcached nginx 实现session共享,实现登录登录
nginx反射例子,亲测可用!附件中包括 1、nginx工具 2、详细的操作文档。 3、最简单例子的详细说明文档。
tomcat中Nginx+memcached实现session共享 所需要的jar包
Nginx+Memcached+Tomcat集群需要的jar包
使用Nginx + Memcached + Tomcat实现负载均衡和session共享案例
Windows+Nginx+Memcached+Tomcat6负载均衡
nginx配置memcached的jar文件
nginx tomcat memcached
《APMServ 5.2.6》:一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP平台的绿色软件 APMServ 5.2.6 绿色服务器 PHP服务器 ASP服务器 APMServ 5.2.6 是一款拥有图形界面的快速搭建Apache 2.2.9、PHP 5.2.6...
Nginx+Tomcat+Memcached集群Session共享实例,Nginx 1.81 + tomcat1 + tomcat2 + Memcached 完整可运行 访问根目录下 test.jsp 可看效果
基于Nginx和Memcached的高并发WEB服务器设计_戴华, 基于Nginx和Memcached的高并发WEB服务器设计_戴华
nginx+memcached+tomcat 负载均衡+session共享实现所有代码 教程请看:https://blog.csdn.net/dayuang2009/article/details/80312249
nginx配置文件,已配置完全+memcached,nginx+tomcat+memcached