Introducing cache server nuster

https://github.com/jiangwenyuan/nuster

Nuster is a fast cache server.

Specifications are subject to change, so the latest one is [https://github.com/jiangwenyuan/nuster/blob/master/README.md](https://github.com/jiangwenyuan/nuster/blob/ See master / README.md).

Introduction

Nuster is a cache server developed based on HAProxy and is compatible with HAProxy. You can then use HAProxy ACLs to define detailed cache rules.

Performance

Super early

Test results 3 times better than nginx for single core, 2 times better than nginx for multi-core and 3 times better than varnish was there.

For more information here.

Installation

make TARGET=linux2628
make install

See HAProxy README (README)

How to use

Define nuster cache on in the ** global ** section and in the ** backend ** and ** listen ** sections Also define nuster-rule

Directive

cache

syntax: nuster cache on|off [share on|off] [data-size size] [dict-size size] [purge-method method]

default: none

context: global

Decide whether to use the cache.

The maximum cache size can be set with ** data-size ** in the units m, M, g and G.

The default is 1MB and the minimum is 1MB. Only the respawn content is calculated.

nuster cache

syntax: nuster cache [on|off]

default: on

context: backend, listen

Define a cache filter. You also need to define cache-rule.

It can be controlled independently by turning on and off.

If you have multiple filters, put the cache filter last.

nuster-rule

syntax: nuster-rule name [key KEY] [ttl TTL] [code CODE] [if|unless condition]

default: none

context: backend, listen

Define a cache rule. If there are multiple rules, define the order carefully. If you can match, it will stop.

acl pathA path /a.html
nuster cache
nuster-rule all ttl 3600
nuster-rule path01 ttl 60 if pathA

path01 is not executed because all cached all requests

name

Define a name

key KEY

Define the key by connecting with . with the following keywords.

The default key is method.scheme.host.path.query.body

Example

GET http://www.example.com/q?name=X&type=Y

http header:
GET /q?name=X&type=Y HTTP/1.1
Host: www.example.com
ASDF: Z
Cookie: logged_in=yes; user=nuster;

Generate the following:

ので、ディフォルトkeyはGEThttpwww.example.com/qname=X&type=Yで、 key method.scheme.host.path.header_ASDF.cookie_user.param_type is GEThttpwww.example.com/qZnusterYになる。

If the cache has the same key as the request, the cache is returned.

ttl TTL

Define a lifetime. The units are d, h, m and s, and the default is 3600 seconds. If it is 0, it will not expire.

code CODE1,CODE2...

The default caches only 200 responses, if you want to cache something else Define. In the case of ʻall`, all are cached.

nuster-rule only200
nuster-rule 200and404 code 200,404
nuster-rule all code all

if|unless condition

Use HAProxy ACL. See 7. Using ACLs and fetching samples section in HAProxy configuration

FAQ

debug method?

Set debug to global or start haproxy with -d.

Messages about the cache include [CACHE].

How to cache a POST request?

ʻSet option http-buffer-request`

Enter body for the customized key.

The POST body may be incomplete, so ** option http-buffer-request ** See section in [HAProxy configuration](doc / configuration.txt)

It may be better to install a backend for POST alone

Example

global
    nuster cache on data-size 100m
    #daemon
    ## to debug cache
    #debug
defaults
    retries 3
    option redispatch
    timeout client  30s
    timeout connect 30s
    timeout server  30s
frontend web1
    bind *:8080
    mode http
    acl pathPost path /search
    use_backend app1a if pathPost
    default_backend app1b
backend app1a
    balance roundrobin
    # mode must be http
    mode http

    # http-buffer-request must be enabled to cache post request
    option http-buffer-request

    acl pathPost path /search

    # enable cache for this proxy
    nuster cache on

    # cache /search for 120 seconds. Only works when POST/PUT
    nuster-rule rpost ttl 120 if pathPost

    server s1 10.0.0.10:8080
backend app1b
    balance     roundrobin
    mode http

    nuster cache on

    # cache /a.jpg, not expire
    acl pathA path /a.jpg
    nuster-rule r1 ttl 0 if pathA

    # cache /mypage, key contains cookie[userId], so it will be cached per user
    acl pathB path /mypage
    nuster-rule r2 key method.scheme.host.path.query.cookie_userId ttl 60 if pathB

    # cache /a.html if response's header[cache] is yes
    http-request set-var(txn.pathC) path
    acl pathC var(txn.pathC) -m str /a.html
    acl resHdrCache1 res.hdr(cache) yes
    nuster-rule r3 if pathC resHdrCache1

    # cache /heavy for 100 seconds if be_conn greater than 10
    acl heavypage path /heavy
    acl tooFast be_conn ge 100
    nuster-rule heavy ttl 100 if heavypage tooFast 

    # cache all if response's header[asdf] is fdsa
    acl resHdrCache2 res.hdr(asdf)  fdsa
    nuster-rule resCache ttl 0 if resHdrCache1

    server s1 10.0.0.10:8080

frontend web2
    bind *:8081
    mode http
    default_backend app2
backend app2
    balance     roundrobin
    mode http

    # disable cache on this proxy
    nuster cache off
    nuster-rule all

    server s2 10.0.0.11:8080

listen web3
    bind *:8082
    mode http

    nuster cache
    nuster-rule everything

    server s3 10.0.0.12:8080

Recommended Posts

Introducing cache server nuster
Build a Pypi cache server on QNAP