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!
分享到:
相关推荐
在构建高性能的Web服务时,通常会采用反向代理服务器如Nginx,缓存服务如Memcached,以及应用服务器如Tomcat的组合。本文将详细介绍如何配置Nginx、Memcached并集成到Tomcat中,同时讲解如何处理Tomcat中的jar包。 ...
这里我们讨论的主题是如何通过Nginx、Tomcat和Memcached来实现集群环境下的session共享。Nginx作为反向代理服务器,负责负载均衡,Tomcat作为应用服务器运行Java Web应用程序,而Memcached则作为分布式内存缓存系统...
本文将介绍如何使用`nginx`、`memcached`和`tomcat`搭建一个高可用的集群环境,实现负载均衡和Session共享。 1. **Nginx环境搭建**: Nginx是一款高性能的HTTP和反向代理服务器,它能够处理静态文件、动态内容、...
在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 将...
在IT行业中,尤其是在服务器端的高性能缓存服务领域,Nginx和Memcached的结合使用是一种常见的优化策略。本文将详细讲解如何在Nginx服务器上配置与Memcached交互的Java Archive (JAR) 文件,以提升Web应用程序的性能...
在构建分布式系统时,Session共享是一个关键问题,特别是在使用多种服务器技术如Nginx、Tomcat和Memcached的环境中。本文将深入探讨如何利用这些组件实现跨服务器的Session共享,以确保用户在登录后能够在整个系统中...
Nginx-1.6.2+Memcached-1.2.6+Tomcat7负载均衡实现Session共享 搭建所需要的JAR包文件, 请复制到Tomcat Lib目录下, 搭建方法, 请查看博客:http://blog.csdn.net/army16/article/details/40585637
Nginx+Memcached+Tomcat集群需要的jar包
在这个配置文件中,我们重点关注的是已经包含了对`memcached`支持的完整Nginx配置。`memcached`是一个分布式内存对象缓存系统,用于加速动态Web应用,通过在内存中缓存数据和对象来减少数据库的访问。 1. **Nginx...
nginx tomcat memcached
在构建高性能、高可用性的Web服务时,"nginx_memcached_tomcat集群工具及配置文件"是一个关键的组件。这个组合充分利用了各个组件的优势,提供了一种高效且可扩展的解决方案。下面将详细介绍这些组件以及它们如何...
为了实现这一目标,我们可以结合Nginx反向代理服务器和memcached内存缓存系统来达到高效、可靠的Session共享。以下是对这个主题的详细阐述: 首先,让我们理解Session的概念。Session是Web应用程序用来跟踪用户状态...
标题 "nginx集成memcached-session-manager所需要的jar" 涉及到的是将Nginx服务器与MemcachedSessionManager组件结合使用的主题。Nginx是一款高性能的HTTP和反向代理服务器,而Memcached则是一个分布式内存对象缓存...
在构建高性能、高可用性的Web服务时,Linux下的Nginx、Memcached和Tomcat的组合是一个常见的选择。Nginx作为一个高效的反向代理服务器,负责分发流量;Memcached用于缓存数据,提高响应速度;而Tomcat作为Java应用...
本文将详细探讨如何在Windows操作系统上配置一个基于Nginx、Memcached和Tomcat的负载均衡架构,以实现高性能、高可用性以及资源优化。 **Nginx** Nginx是一款流行的开源Web服务器,以其高性能、低内存占用和反向...
Windows+Nginx+Memcached+Tomcat6负载均衡
**Memcached与Nginx整合使用详解** Memcached和Nginx是两个在Web开发中广泛应用的工具。Memcached是一款高性能、分布式内存对象缓存系统,它可以用来减轻数据库的负载,提高网站性能。而Nginx则是一款强大的、高...
《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...