Skip to content

Commit a7bec3f

Browse files
author
Ciprian Manea
committed
adding Varnish configs
1 parent 9122c1c commit a7bec3f

File tree

4 files changed

+263
-0
lines changed

4 files changed

+263
-0
lines changed

README.mkd

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ If you have installed riak on the standard port this will be [http://127.0.0.1:8
3131
## Known Issues
3232
* Editing a riak value does not retain 2i index information.
3333
* Lots of list buckets, lots of list keys.
34+
* As listing buckets/keys is quite expensive, you should install Varnish to offload Rekon (see the included ./varnish directory)

varnish/README.mkd

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Rekon+Varnish
2+
3+
A Varnish configuration tuned to speed up Rekon in development environments
4+
5+
Rekon should ***NOT*** be used on a production cluster ***EVER***.
6+
7+
8+
## Installing Varnish
9+
10+
### Quick Install
11+
12+
Use your favourite package manager to install varnish3, then
13+
14+
$ sudo rsync -b ./etc-default-varnish /etc/default/varnish
15+
$ sudo rsync -b ./etc-varnish-default.vcl /etc/varnish/default.vcl
16+
17+
Make sure no other (web)service runs on port 80 and start Varnish
18+
19+
$ sudo /etc/init.d/varnish start
20+
21+
22+
## Usage
23+
24+
Once installed navigate to http://varnish-node-addr/buckets/rekon/keys/go.
25+
26+
27+
## Notes
28+
29+
Varnish will use 1GB RAM, and a (re)director employing hashing as its load balancing policy
30+
Certain (Rekon) operations will be cached differently: buckets for 1 week, keys for 1 day

varnish/etc-default-varnish

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Configuration file for varnish
2+
#
3+
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
4+
# to be set from this shell script fragment.
5+
#
6+
# Note: If systemd is installed, this file is obsolete and ignored. You will
7+
# need to copy /lib/systemd/system/varnish.service to /etc/systemd/system/ and
8+
# edit that file.
9+
10+
# Should we start varnishd at boot? Set to "no" to disable.
11+
START=yes
12+
13+
# Maximum number of open files (for ulimit -n)
14+
NFILES=131072
15+
16+
# Maximum locked memory size (for ulimit -l)
17+
# Used for locking the shared memory log in memory. If you increase log size,
18+
# you need to increase this number as well
19+
MEMLOCK=82000
20+
21+
# Default varnish instance name is the local nodename. Can be overridden with
22+
# the -n switch, to have more instances on a single server.
23+
# You may need to uncomment this variable for alternatives 1 and 3 below.
24+
# INSTANCE=$(uname -n)
25+
26+
# This file contains 4 alternatives, please use only one.
27+
28+
## Alternative 1, Minimal configuration, no VCL
29+
#
30+
# Listen on port 6081, administration on localhost:6082, and forward to
31+
# content server on localhost:8080. Use a 1GB fixed-size cache file.
32+
#
33+
# This example uses the INSTANCE variable above, which you need to uncomment.
34+
#
35+
# DAEMON_OPTS="-a :6081 \
36+
# -T localhost:6082 \
37+
# -b localhost:8080 \
38+
# -u varnish -g varnish \
39+
# -S /etc/varnish/secret \
40+
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
41+
42+
43+
## Alternative 2, Configuration with VCL
44+
#
45+
# Listen on port 6081, administration on localhost:6082, and forward to
46+
# one content server selected by the vcl file, based on the request.
47+
#
48+
DAEMON_OPTS="-a :80 \
49+
-T localhost:6082 \
50+
-f /etc/varnish/default.vcl \
51+
-S /etc/varnish/secret \
52+
-s malloc,1024m"
53+
54+
55+
## Alternative 3, Advanced configuration
56+
#
57+
# This example uses the INSTANCE variable above, which you need to uncomment.
58+
#
59+
# See varnishd(1) for more information.
60+
#
61+
# # Main configuration file. You probably want to change it :)
62+
# VARNISH_VCL_CONF=/etc/varnish/default.vcl
63+
#
64+
# # Default address and port to bind to
65+
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
66+
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
67+
# VARNISH_LISTEN_ADDRESS=
68+
# VARNISH_LISTEN_PORT=6081
69+
#
70+
# # Telnet admin interface listen address and port
71+
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
72+
# VARNISH_ADMIN_LISTEN_PORT=6082
73+
#
74+
# # The minimum number of worker threads to start
75+
# VARNISH_MIN_THREADS=1
76+
#
77+
# # The Maximum number of worker threads to start
78+
# VARNISH_MAX_THREADS=1000
79+
#
80+
# # Idle timeout for worker threads
81+
# VARNISH_THREAD_TIMEOUT=120
82+
#
83+
# # Cache file location
84+
# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
85+
#
86+
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
87+
# # or in percentage of available disk space using the % suffix.
88+
# VARNISH_STORAGE_SIZE=1G
89+
#
90+
# # File containing administration secret
91+
# VARNISH_SECRET_FILE=/etc/varnish/secret
92+
#
93+
# # Backend storage specification
94+
# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
95+
#
96+
# # Default TTL used when the backend does not specify one
97+
# VARNISH_TTL=120
98+
#
99+
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
100+
# # sure you update this section, too.
101+
# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
102+
# -f ${VARNISH_VCL_CONF} \
103+
# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
104+
# -t ${VARNISH_TTL} \
105+
# -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
106+
# -S ${VARNISH_SECRET_FILE} \
107+
# -s ${VARNISH_STORAGE}"
108+
#
109+
110+
111+
## Alternative 4, Do It Yourself
112+
#
113+
# DAEMON_OPTS=""

varnish/etc-varnish-default.vcl

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# This is a basic VCL configuration file for varnish. See the vcl(7)
2+
# man page for details on VCL syntax and semantics.
3+
#
4+
# Default backend definition. Set this to point to your content
5+
# server.
6+
7+
backend riak1 {
8+
.host = "127.0.0.1";
9+
.port = "8098";
10+
11+
# bucket and key listings are heavy/slow operations, lets not 503s them
12+
.first_byte_timeout = 300s;
13+
}
14+
15+
#backend riak2 {
16+
# .host = "127.0.0.2";
17+
# .port = "8098";
18+
# .first_byte_timeout = 300s;
19+
#}
20+
21+
#backend riak3 {
22+
# .host = "127.0.0.3";
23+
# .port = "8098";
24+
# .first_byte_timeout = 300s;
25+
#}
26+
27+
#backend riak4 {
28+
# .host = "127.0.0.4";
29+
# .port = "8098";
30+
# .first_byte_timeout = 300s;
31+
#}
32+
33+
#backend riak5 {
34+
# .host = "127.0.0.5";
35+
# .port = "8098";
36+
# .first_byte_timeout = 300s;
37+
#}
38+
39+
director default hash {
40+
41+
{
42+
.backend = riak1;
43+
.weight = 1;
44+
}
45+
46+
# {
47+
# .backend = riak2;
48+
# .weight = 1;
49+
# }
50+
51+
# {
52+
# .backend = riak3;
53+
# .weight = 1;
54+
# }
55+
56+
# {
57+
# .backend = riak4;
58+
# .weight = 1;
59+
# }
60+
61+
# {
62+
# .backend = riak5;
63+
# .weight = 1;
64+
# }
65+
}
66+
67+
68+
sub vcl_fetch {
69+
70+
# cache buckets=true URIs for 1 week
71+
72+
if (req.url ~ "buckets\?buckets=true$") {
73+
/* Remove Expires from backend, it's not long enough */
74+
unset beresp.http.expires;
75+
76+
/* Set the clients TTL on this object */
77+
set beresp.http.cache-control = "max-age=900";
78+
79+
/* Set how long Varnish will keep it */
80+
set beresp.ttl = 1w;
81+
82+
/* marker for vcl_deliver to reset Age: */
83+
set beresp.http.magicmarker = "1";
84+
}
85+
86+
# cache keys=true URIs for 1 day
87+
88+
if (req.url ~ "keys\?keys=true$") {
89+
/* Remove Expires from backend, it's not long enough */
90+
unset beresp.http.expires;
91+
92+
/* Set the clients TTL on this object */
93+
set beresp.http.cache-control = "max-age=90";
94+
95+
/* Set how long Varnish will keep it */
96+
set beresp.ttl = 1d;
97+
98+
/* marker for vcl_deliver to reset Age: */
99+
set beresp.http.magicmarker = "1";
100+
}
101+
}
102+
103+
sub vcl_deliver {
104+
if (resp.http.magicmarker) {
105+
/* Remove the magic marker */
106+
unset resp.http.magicmarker;
107+
108+
/* By definition we have a fresh object */
109+
set resp.http.age = "0";
110+
}
111+
112+
# add HIT/MISS markers to help with troubleshooting
113+
114+
if (obj.hits > 0) {
115+
set resp.http.X-Cache = "HIT";
116+
} else {
117+
set resp.http.X-Cache = "MISS";
118+
}
119+
}

0 commit comments

Comments
 (0)