forked from OpenTSDB/opentsdb.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvarnish.html
155 lines (141 loc) · 5.68 KB
/
varnish.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Load balancing with Varnish - OpenTSDB - A Distributed, Scalable Monitoring System</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<!--[if lte IE 8]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen"/>
<![endif]-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18339382-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<header><div id="headerbar">
<h1><a href="index.html">OpenTSDB</a></h1>
<nav><ul id="navbar">
<li><a href="overview.html">Overview</a></li>
<li><a href="getting-started.html">Getting Started</a></li>
<li><a href="manual.html">Manual</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul></nav>
</div></header>
<!--[if lte IE 8]>
<div class="iesucks">Warning: You're using an unsupported, archaic browser.
Get a better, modern browsing experience with
<a href="http://www.google.com/chrome">Chrome</a> or
<a href="http://www.mozilla.com/firefox">Firefox</a>.</div>
<![endif]-->
<section id="content">
<section id="varnish">
<h2>Load balancing with Varnish</h2>
<a href="http://www.varnish-cache.org/">Varnish</a> is a powerful HTTP load
balancer (reverse proxy), which is also very good at caching. When running
multiple TSDs, Varnish comes in handy to distribute the HTTP traffic across
the TSDs. Bear in mind that write traffic doesn't use the HTTP protocol by
default, and as such you can only use Varnish for read queries. Using Varnish
will help you easily scale the amount of read capacity of your TSD cluster.
<p>
The following is a sample Varnish configuration recommended for use with
OpenTSDB. It uses a slightly custom load balancing strategy to achieve
optimal cache hit rate at the TSD level. This configuration requires at least
Varnish 2.1.0 to run, but using Varnish 3.0 or above is strongly recommended.
<p>
This sample configuration is for 2 backends, named <code>foo</code> and
<code>bar</code>. You need to substitute at least the host names.
<div class="code"># VCL configuration for OpenTSDB.
backend foo {
.host = "foo";
.port = "4242";
.probe = {
.url = "/version";
.interval = 30s;
.timeout = 10s;
.window = 5;
.threshold = 3;
}
}
backend bar {
.host = "bar";
.port = "4242";
.probe = {
.url = "/version";
.interval = 30s;
.timeout = 10s;
.window = 5;
.threshold = 3;
}
}
# The `client' director will select a backend based on `client.identity'.
# It's normally used to implement session stickiness but here we abuse it
# to try to send pairs of requests to the same TSD, in order to achieve a
# higher cache hit rate. The UI sends queries first with a "&json" at the
# end, in order to get meta-data back about the results, and then it sends
# the same query again with "&png". If the second query goes to a different
# TSD, then that TSD will have to fetch the data from HBase again. Whereas
# if it goes to the same TSD that served the "&json" query, it'll hit the
# cache of that TSD and produce the PNG directly without using HBase.
#
# Note that we cannot use the `hash' director here, because otherwise Varnish
# would hash both the "&json" and the "&png" requests identically, and it
# would thus serve a cached JSON response to a "&png" request.
director tsd client {
{ .backend = foo; .weight = 100; }
{ .backend = bar; .weight = 100; }
}
sub vcl_recv {
set req.backend = tsd;
# Make sure we hit the same backend based on the URL requested,
# but ignore some parameters before hashing the URL.
set client.identity = regsuball(req.url, "&(o|ignore|png|json|html|y2?range|y2?label|y2?log|key|nokey)\b(=[^&]*)?", "");
}
sub vcl_hash {
# Remove the `ignore' parameter from the URL we hash, so that two
# identical requests modulo that parameter will hit Varnish's cache.
hash_data(regsuball(req.url, "&ignore\b(=[^&]*)?", ""));
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}
</div>
<p>
On many Linux distros (including Debian and Ubuntu), you need to put the
configuration above in <code>/etc/varnish/default.vcl</code>. We also
recommend tweaking the command-line parameters of <code>varnishd</code>
in order to use a memory-backed cache of about 1GB if you can afford it.
On Debian/Ubuntu systems, this is done by editing
<code>/etc/default/varnish</code> to make sure that <code>-s malloc,1G</code>
is passed to <code>varnishd</code>.
<p>
Read more about Varnish:
<ul>
<li><a href="http://www.varnish-cache.org/docs/trunk/reference/vcl.html">The
VCL configuration language</a></li>
<li><a href="http://www.varnish-cache.org/trac/wiki/BackendPolling">Health
checking backends</a></li>
<li><a href="http://www.varnish-cache.org/trac/wiki/LoadBalancing">Tweaking
the load balancing strategy</a></li>
</ul>
<p>
Note: if you're using Varnish 2.x (which is not recommended as we would
strongly encourage you to migrate to 3.x) you have to replace each function
call <code>hash_data(foo);</code> to <code>set req.hash += foo;</code> in the
VCL configuration above.
</section>
<footer>
© 2010–2013 The OpenTSDB Authors.
</footer>
</section></body></html>