-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
437 lines (384 loc) · 14.7 KB
/
index.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Varnish 101</title>
<meta name="description" content="An introduction to caching, Varnish, and .vcl files.">
<meta name="author" content="James Fuller">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<!-- For my custom styles -->
<link rel="stylesheet" href="css/custom.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Varnish 101</h1>
<h3>An introduction to caching, Varnish, and .vcl files.</h3>
<p>
<small>James Fuller<br />Web Application Developer<br />University of Iowa - ITS<br />d.o: <a href="https://www.drupal.org/user/849572">fullerja</a></small>
</p>
<p><small>Follow along at: <strong><a href="http://rawgit.com/jwfuller/varnish101/master/index.html#/">http://rawgit.com/jwfuller/varnish101/master/index.html#/</a></strong></small></p>
</section>
<section>
<h2>What is Varnish?</h2>
<ul>
<li class="fragment">“A web application accelerator also known as a caching HTTP reverse proxy.”</li>
<li class="fragment">A piece of software that makes dynamic websites really really really fast.</li>
<li class="fragment">It sits between the client and the webserver and caches webpages.</li>
</ul>
</section>
<section>
<h2>Drupal with out any caching</h2>
<p class="fragment">~ 3 mph</p>
<img src="assets/smallTrain.jpg" />
<small><a href="http://s0.geograph.org.uk/photos/06/39/063959_49f25f81.jpg">http://s0.geograph.org.uk/photos/06/39/063959_49f25f81.jpg</a></small>
</section>
<section>
<h2>Drupal with core caching</h2>
<p class="fragment">~ 80 mph</p>
<img src="assets/medTrain.jpg" />
<small><a href="http://upload.wikimedia.org/wikipedia/commons/2/2d/390017_Rugby_station.jpg">http://upload.wikimedia.org/wikipedia/commons/2/2d/390017_Rugby_station.jpg</a></small>
</section>
<section>
<h2>Drupal with Varnish</h2>
<p class="fragment">~ 357.2 mph</p>
<img src="assets/bulletTrain.jpg" />
<small><a href="https://c2.staticflickr.com/2/1242/1385598849_303b87f58c_z.jpg?zz=1">https://c2.staticflickr.com/2/1242/1385598849_303b87f58c_z.jpg?zz=1</a></small>
</section>
<section>
<h2>Loading a webpage from Drupal</h2>
</section>
<section>
<h2>Plain ol' Drupal</h2>
<ol>
<li class="fragment">User requests a URL.</li>
<li class="fragment">Web server (Apache/Nginx/IIS) sends it to Drupal.</li>
<li class="fragment">Drupal bootstraps and initializes the database, sessions etc.</li>
<li class="fragment">Maps the path to a callback function, which gets the primary content.</li>
<li class="fragment">Modules can hook into the process and extend functionality and alter the content.</li>
<li class="fragment">The Theme System generates the HTML and applies styles it to.</li>
<li class="fragment">Drupal returns a fully formed HTML page to the browser.</li>
<li class="fragment">The browser renders the HTML page for the user.</li>
</ol>
</section>
<section>
<h2>Drupal with core caching</h2>
<ol>
<li class="fragment">User requests a URL.</li>
<li class="fragment">Web server (Apache/Nginx/IIS) sends it to Drupal.</li>
<li class="fragment">Drupal bootstraps and initializes the database, sessions etc.</li>
<div class="fragment"><s>
<li>Maps the path to a callback function, which gets the primary content.</li>
<li>Modules can hook into the process and extend functionality and alter the content.</li>
<li>The Theme System generates the HTML and applies styles it to.</li>
</s></div>
<li class="fragment">Drupal returns a fully formed HTML page to the browser.</li>
<li class="fragment">The browser renders the HTML page for the user.</li>
</ol>
</section>
<section>
<h2>Drupal (Now with Varnish!)</h2>
<ol>
<li class="fragment">User requests a URL</li>
<div class="fragment"><s>
<li>Web server (Apache/Nginx/IIS) sends it to Drupal.</li>
<li>Drupal bootstraps and initializes the database, sessions etc.</li>
<li>Maps the path to a callback function, which gets the primary content.</li>
<li>Modules can hook into the process and extend functionality and alter the content.</li>
<li>The Theme System generates the HTML and applies styles it to.</li>
<li>Drupal returns a fully formed HTML page to the browser.</li>
</s></div>
<li class="fragment">The browser renders the HTML page for the user.</li>
</ol>
</section>
<section>
<h2>How does Varnish do this?</h2>
<ol>
<li class="fragment">A request is recieved</li>
<li class="fragment">Varnish determines if it should Lookup, Pass, Pipe or Error.
<ul class="fragment"><small>
<li>Lookup = Request that could be cached</li>
<li>Pass = Request cannot be cached (cookies) or should not be cached (configuration)</li>
<li>Pipe = Request should be mainlined to the server (POST or similar transmition of data that should not be interupted)</li>
<li>Error = Backend is down or varnish is configured to error</li>
</small></ul>
</li>
<li class="fragment">Assuming a Lookup, Varnish sends the request to Drupal.</li>
<li class="fragment">Drupal does the long look up and responds.</li>
<li class="fragment">Varnish caches a copy of that response.
<ul><small>
<li>This can be from RAM or disk, RAM is <strong>highly</strong> recommended.</li>
</small></ul>
</li>
<li class="fragment">Request is made for the same thing</li>
<li class="fragment">Varnish does a Lookup
<ul><small>
<li>Checks to make sure the cache lifetime has not expired</li>
</ul></small>
</li>
<li class="fragment">Responds with its copy from RAM. (Skipping Drupal entirely)</li>
</ol>
</section>
<section>
<h2>Installation</h2>
<h3>(20,000 ft view)</h3>
<ol>
<li class="fragment">Download and install Varnish
<ul>
<li>(apt-get, yum, make/install)</li>
</ul>
</li>
<li class="fragment">Swap Apache off port 80 and put Varnish on</li>
<li class="fragment">Adjust your configuration in the .vcl file</li>
<li class="fragment">Install the Drupal Varnish module
<ul>
<li>(including editing your settings.php file)</li>
</ul>
</li>
<li class="fragment">Adjust your Performance settings</li>
</ol>
</section>
<section>
<h2>Anatomy of a VCL</h2>
</section>
<section>
<h2>Backend Probe</h2>
<pre><code>
# Define the health check for Drupal Servers.
probe drupal_healthcheck {
.url = "/health_check.php";
.interval = 5s;
.timeout = 1s;
.window = 5;
.threshold = 3;
.expected_response = 200;
}
</code></pre>
</section>
<section>
<h2>Backend Definitions</h2>
<pre><code>
# Define the list of backends (web servers).
# Port 80 Backend Servers
backend web1 {
.host = "192.10.0.1”;
.probe = drupal_healthcheck;
}
backend web2 {
.host = "192.10.0.2”;
.probe = drupal_healthcheck;
}
# Port 443 Backend Servers for SSL
backend web1_ssl {
.host = "192.10.0.1”;
.port = "443”;
.probe = drupal_healthcheck;
}
backend web2_ssl {
.host = "192.10.0.2”;
.port = "443”;
.probe = drupal_healthcheck;
}
</code></pre>
</section>
<section>
<h2>Directors</h2>
<pre><code>
# Define the director that determines how to distribute incoming requests.
director default_director round-robin {
{ .backend = web1; }
{ .backend = web2; }
}
director ssl_director round-robin {
{ .backend = web1_ssl; }
{ .backend = web2_ssl; }
}
</code></pre>
</section>
<section>
<h2>Basic Receiver Sub Routine</h2>
<pre><code>
# Respond to incoming requests.
sub vcl_recv {
# Set the director to cycle between the web servers.
if (server.port == 443) {
set req.backend = ssl_director;
}
else {
set req.backend = default_director;
}
}
</code></pre>
</section>
<section>
<h2>Basic Fetch Sub Routine</h2>
<pre><code>
sub vcl_fetch {
# Don’t allow static files to set cookies.
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js)(\?[a-z0-9]+)?$") {
unset beresp.http.set-cookie;
}
# Allow items to be stale if needed.
set beresp.grace = 1h;
}
</code></pre>
</section>
<section>
<h2>Deliver Sub Routine</h2>
<pre><code>
# Set a header to track a cache HIT/MISS.
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
</code></pre>
</section>
<section>
<h2>Varnish can’t do everything</h2>
<img src="assets/Varnish.png" />
</section>
<section>
<h2>Varnish is not great with</h2>
<ul>
<li class="fragment">Forms</li>
<li class="fragment">Authenticated Users</li>
<li class="fragment">Things that really need cookies</li>
</ul>
<p></p>
<p class="fragment">But you can do some stuff to help</p>
<p class="fragment"><small>Checkout ESI (Edge Side Includes)</small></p>
</section>
<section>
<h2>Metrics</h2>
<h3>What should you measure?</h3>
<ul>
<li>Time to First Byte</li>
<li>Number of requests per second</li>
</ul>
</section>
<section>
<h2>Metrics</h2>
<h3>How can you measure it?</h3>
<ul>
<li class="fragment">Time to First Byte
<ul>
<li class="fragment">For publically accessible web servers - <strong>www.webpagetest.org</strong></li>
<li class="fragment">For local development or web servers – <strong>Chrome Dev Tools</strong></li>
</ul>
</li>
<li class="fragment">Number of Request per second
<ul>
<li class="fragment">Load testing tools – <strong>JMeter, BlazeMeter, Siege, Apache Benchmark</strong></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>How about some Data</h2>
<ul>
<li class="fragment">Drupal
<ul>
<li>8130 ms</li>
<li>~10 concurrent requests</li>
</ul>
</li>
<li class="fragment">Drupal w/ core caching
<ul>
<li>2090 ms</li>
<li>~100 concurrent requests</li>
</ul>
</li>
<li class="fragment">Drupal w/ Varnish
<ul>
<li>68 ms</li>
<li>2000+ concurrent requests</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Additional Resources</h2>
<ul>
<li>VCL files
<ul>
<li>4Kitchens<br /><small><a href="https://fourkitchens.atlassian.net/wiki/display/TECH/Configure+Varnish+3+for+Drupal+7">https://fourkitchens.atlassian.net/wiki/display/TECH/Configure+Varnish+3+for+Drupal+7</a></small></li>
<li>Lullabot<br /><small><a href="https://www.lullabot.com/sites/lullabot.com/files/default_varnish3.vcl_.txt">https://www.lullabot.com/sites/lullabot.com/files/default_varnish3.vcl_.txt</a></small></li>
</ul>
</li>
<li>Caching Deep Drive – DrupalCon Austin<br /><small><a href="https://austin2014.drupal.org/session/caching-deep-dive">https://austin2014.drupal.org/session/caching-deep-dive</a></small></li>
<li>Sweet VM for playing with courtesy of:<br /><a href="https://ohthehugemanatee.org/downloads/drupal/varnish101.zip">https://ohthehugemanatee.org/downloads/drupal/varnish101.zip</a>
<ul>
<li><strong>Campbell Vertesi</strong> - Technical Architect</li>
<li><strong>Earnest Berry</strong> - Senior Developer at The Economist</li>
<li><strong>Jason Ford</strong> - CTO of BlackMesh Managed Hosting</li>
</ul>
</li>
<li><a href="http://www.isvarnishworking.com">http://www.isvarnishworking.com</a></li>
</ul>
</section>
<section>
<h2>Modules to help with caching and cache clearing</h2>
<ul>
<li>https://www.drupal.org/project/varnish</li>
<li>https://www.drupal.org/project/expire</li>
<li>https://www.drupal.org/project/entitycache</li>
<li>https://www.drupal.org/project/advagg</li>
<li>https://www.drupal.org/project/views_cache_bully</li>
<li>https://www.drupal.org/project/panels_hash_cache</li>
<li>https://www.drupal.org/project/authcache</li>
</ul>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>