高性能缓存服务器 Nuster
Nuster 是一个基于 HAProxy 的高性能缓存服务器。Nuster 完全兼容 HAProxy,并且利用 HAProxy 的 ACL 功能来提供非常细致的缓存规则,比如
- 请求地址为某某时缓存
- 请求参数中的 X 为 Y 时缓存
- 响应头中的 X 为 Y 时缓存
- 请求速率超过多少时缓存
- 等等
Nuster 性能评测
非常快, 单进程模式下是 nginx 的 3 倍,多进程下 nginx 的 2 倍,varnish 的 3 倍。详见benchmark
安装 Nuster
git clone https://github.com/jiangwenyuan/nuster.git cd nuster make TARGET=linux2628 make install
详情请参照 HAProxy README
Naster 使用方法
在global中添加cache on
, 然后在backend或listen中添加 cache filter 和 cache rule
Naster 指令
cache
syntax: cache on|off [data-size size]
default: none
context: global
控制是否开启缓存。 可以设置data-size来控制缓存数据的内存使用量。可以使用m
, M
, g
和 G
. 默认是 1MB,同时也是最小使用量。只有 http 内容计算在内,并不包括使用缓存带来的内存开销。
filter cache
syntax: filter cache [on|off]
default: on
context: backend, listen
定义一个 cache filter, 另外cache-rule
也需要添加。 可以为多个代理添加,并单独设置某个代理的缓存是否开启。 如果定义了多个 filter,需要把 cache filter 放在最后。
cache-rule
syntax: cache-rule name [key KEY] [ttl TTL] [code CODE] [if|unless condition]
default: none
context: backend, listen
定义缓存规则。可以同时定义多个,但是需要注意顺序,匹配则会停止测试。
acl pathA path /a.html filter cache cache-rule all ttl 3600 cache-rule path01 ttl 60 if pathA
path01
这条规则永远不会执行,因为 all 会匹配所有的规则。
name
定义一个名字。
key KEY
定义 key,由以下关键字组成:
- method: http method, GET/POST…
- scheme: http or https
- host: the host in the request
- path: the URL path of the request
- query: the whole query string of the request
- header_NAME: the value of header
NAME
- cookie_NAME: the value of cookie
NAME
- param_NAME: the value of query
NAME
- body: the body of the request
默认 key 是method.scheme.host.path.query.body
Example
GET http://www.example.com/q?name=X&type=Yhttp header: GET /q?name=X&type=Y HTTP/1.1 Host: www.example.com ASDF: Z Cookie: logged_in=yes; user=nuster;
会得到:
- method: GET
- scheme: http
- host: www.example.com
- path: /q
- query: name=X&type=Y
- header_ASDF: Z
- cookie_user: nuster
- param_type: Y
- body: (empty)
所以默认的 key 就会得到GEThttpwww.example.com/qname=X&type=Y
, 而 key method.scheme.host.path.header_ASDF.cookie_user.param_type
则会生成 GEThttpwww.example.com/qZnusterY
一个请求的 key 能在缓存中找到则返回缓存内容。
ttl TTL
定义 key 的失效时间,可以使用 d
, h
, m
and s
。默认3600
秒. 如果不希望失效则设为 0
code CODE1,CODE2…
默认只缓存 200 的响应,如果需要缓存其他的则可以添加,all
会缓存任何状态码。
cache-rule only200 cache-rule 200and404 code 200,404 cache-rule all code all
if|unless condition
定义 ACL 条件 详见HAProxy configuration的7. Using ACLs and fetching samples
常见问题
如何调试?
在global
添加debug
, 或者带-d
启动haproxy
缓存相关的调试信息以[CACHE]
开头
如何缓存 POST 请求?
添加option http-buffer-request
如果自定义了 key 的话需要使用body
关键字
请求 body 可能不完整,详见HAProxy configuration 的 option http-buffer-request小节
另外可以为 post 请求单独设置一个后端
配置样例
globalcache on data-size 100m#daemon## to debug cache#debug defaultsretries 3option redispatchtimeout client 30stimeout connect 30stimeout server 30s frontend web1bind *:8080mode httpacl pathPost path /searchuse_backend app1a if pathPostdefault_backend app1b backend app1abalance roundrobin# mode must be httpmode http# http-buffer-request must be enabled to cache post requestoption http-buffer-requestacl pathPost path /search# enable cache for this proxyfilter cache# cache /search for 120 seconds. Only works when POST/PUTcache-rule rpost ttl 120 if pathPostserver s1 10.0.0.10:8080 backend app1bbalance roundrobinmode httpfilter cache on# cache /a.jpg, not expireacl pathA path /a.jpgcache-rule r1 ttl 0 if pathA# cache /mypage, key contains cookie[userId], so it will be cached per useracl pathB path /mypagecache-rule r2 key method.scheme.host.path.query.cookie_userId ttl 60 if pathB# cache /a.html if response's header[cache] is yeshttp-request set-var(txn.pathC) pathacl pathC var(txn.pathC) -m str /a.htmlacl resHdrCache1 res.hdr(cache) yescache-rule r3 if pathC resHdrCache1# cache /heavy for 100 seconds if be_conn greater than 10acl heavypage path /heavyacl tooFast be_conn ge 100cache-rule heavy ttl 100 if heavypage tooFast # cache all if response's header[asdf] is fdsaacl resHdrCache2 res.hdr(asdf) fdsacache-rule resCache ttl 0 if resHdrCache1server s1 10.0.0.10:8080frontend web2bind *:8081mode httpdefault_backend app2 backend app2balance roundrobinmode http# disable cache on this proxyfilter cache offcache-rule allserver s2 10.0.0.11:8080listen web3bind *:8082mode httpfilter cachecache-rule everythingserver s3 10.0.0.12:8080
高性能缓存服务器 Nuster相关推荐
- 高性能缓存服务器Varnish详解
一.简介 Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好. Varnish 的作者Po ...
- 高性能缓存服务器Varnish架构配置
Varnish跟Squid都是一款内容加速缓存服务器,我们可以使用它们来对我们的网页内容进行缓存,以此来从某个方面提高用户体验度,提升网站整体的抗压能力. 目前自建的CDN中,有很多都是基于Squid ...
- web缓存服务器性能比较 nuster vs nginx vs varnish
简单比较了web缓存服务器nuster, nginx和varnish的缓存性能,结果显示nuster的RPS(每秒请求数)单进程模式下大概是nginx的3倍,多进程下是nginx的2倍,varnish ...
- web 缓存服务器 HTTP2 性能测试: nuster vs nginx
简单的用 h2load测试了nuster和nginx的http/2下的缓存性能,结果显示RPS(每秒请求数)nuster差不多是nginx的3倍 https://github.com/jiangwen ...
- Memcached:高性能的分布式内存缓存服务器
Memcached:高性能的分布式内存缓存服务器 特征: u 协议简单: n 基于文本行的协议 u 基于libevent的事件处理: n 程序库,能实现连接数的增加,O(1)性能 u 内置内存存储方式 ...
- memcached 缓存服务器
Memcached 缓存服务器 Memcached 是高性能的分布式内存缓存服务器. 一般的使用目的是,通过缓存数据库查询结果,减少数据库访问次数,以提高动态web应用的速度.提高可扩展性. 主要特点 ...
- iot架构 mqtt netty_Netty实现高性能IOT服务器(Groza)之手撕MQTT协议篇上
前言 诞生及优势 MQTT由Andy Stanford-Clark(IBM)和Arlen Nipper(Eurotech,现为Cirrus Link)于1999年开发,用于监测穿越沙漠的石油管道.目标 ...
- 《高性能Linux服务器构建实战》——2.1节初识Varnish
2.1 初识Varnish 2.1.1 Varnish概述 Varnish是一款高性能且开源的反向代理服务器和HTTP 加速器,它的开发者Poul-Henning Kamp是FreeBSD核心的开发人 ...
- LEMP构建高性能WEB服务器(第三版)
LEMP 自动化编译脚本下载:http://docs.linuxtone.org/autoinstall/ (定期更新,欢迎多测试,找bug) 介绍参考:http://bbs.linuxtone.or ...
最新文章
- 编程中的一个易错点:判断某个点是否超出棋盘边界
- 1131 Subway Map (30 分)【难度: 难 / Dijkstra最短路】
- Toast的功能和用法
- GPU(CUDA)学习日记(十一)------ 深入理解CUDA线程层次以及关于设置线程数的思考
- knn人脸识别判断_测试使用K-最近邻(kNN)算法的30个问题
- webpack使用教程
- 好用的平板电脑_支架里的变形金刚让手机、电脑、平板更好用!6种角度,1秒切换...
- [转载] python之路《第二篇》Python基本数据类型
- linux 添加重定向域名,Linux系统中Nginx的安装并进行域名认证和重定向
- 用Lambda表达式进行函数式编程
- OO Summary Ⅲ
- C++ ---------- map的使用
- 一个优秀的Android应用从建项目开始
- mask rcnn 召回率_搜索推荐召回amp;amp;粗排相关性优化最新进展—2020
- arcgis 属性表 汇总_ArcGIS之属性表编辑与字段添加
- 2008年度江苏地税纳税百强企业名单
- 如何升级php到最新版本_如何将PHP升级到最新版本
- 【网络技术联盟站】瑞哥教你如何使用 Console 接口管理设备
- 回炉STM32入新坑cubemx
- python语义分析_Python - Sentiment Analysis
热门文章
- php根据循环条件切换图片,thinkphp 循环显示图片问题!!!~~~~
- 华人开发世界最小电池,直径细如灰尘,可集成在芯片上供电10小时
- 只是pip安装输错字母,你就可能中了挖矿病毒
- 用GAN创造新蛋白只需几周,大幅缩短制药周期 | Nature子刊
- 2019中国人工智能年度评选启幕,3大奖项,锁定AI Top玩家
- 安卓错误Emulator: error: x86 emulation currently......
- System.Security.Cryptography.CryptographicException: 用户的配置文件是临时配置文件 解决方案...
- Java多线程初学者指南(10):使用Synchronized关键字同步类方法
- 科大讯飞陶晓东:人工智能时代的医学影像 | CCF-GAIR 2017
- MyEclipse修改jsp模板文件