-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
582 lines (522 loc) · 19.5 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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Metaprogramming Python for Big Data</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<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/beige.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<style>
.reveal table tbody th{
font-weight: bold;
}
.reveal table tbody th h4{
font-weight: normal;
}
.reveal .deliroll{
color: #00aff0; /* rgba(0, 0, 255, 0.7); */
}
.reveal .redshift{
color: rgba(240, 67, 0, 1.0);
}
.reveal .deliroll-bg{
padding-right: 10px;
padding-left: 10px;
font-size: 80%;
color: white;
text-align: right;
background: #00aff0; /* rgba(0, 0, 255, 0.7); */
}
.reveal .redshift-bg{
padding-right: 10px;
padding-left: 10px;
font-size: 80%;
color: white;
text-align: right;
background: rgba(240, 67, 0, 1.0);
}
.reveal .benchmark h3{
text-transform: none;
}
.reveal .benchmark table thead{
padding-bottom: 50px;
}
.reveal .quote{
line-height: 5em;
}
.reveal code{
font-size: 80%;
}
.reveal section img{
border: 0px;
box-shadow: none;
vertical-align: middle;
}
.reveal .archbox{
width: 60%;
margin-left: auto;
margin-right: auto;
font-size: 70%;
border-radius: 5px;
border: 1px solid rgba(0, 0, 0, 0.4);
background: rgba(0, 0, 0, 0.05);
line-height: 1.8em;
}
.reveal .architecture{
line-height: 1em;
}
.reveal .highlight{
background: rgba(0, 175, 240, 0.4);
}
.reveal a{
font-size: 60%;
}
.reveal iframe {
overflow: hidden;
scrolling: no;
max-width: 200%;
max-height: 200%;
}
.section .framediv{
top: 0px;
width: 600px;
height: 600px;
}
.logoroll{
top: -300px;
right: 300px;
}
.reveal .title-slide{
text-align: left;
}
</style>
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</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 data-transition="cube" data-background-position="90% 0%" data-background="adroll-rolls.png" data-background-size="250px" class="title-slide">
<h3 style="margin-top: 200px">A billion rows per second</h3>
<h2>Metaprogramming Python for Big Data</h2>
<h3 class="deliroll">
<br>
Ville Tuulos<br>
<span style="color: #999">Principal Engineer @ AdRoll</span>
</h4>
<span style="color: #666; font-size: 80%">ville.tuulos@adroll.com</span>
</section>
<section data-transition="fade">
<h4>We faced the key technical challenge of modern Business Intelligence:</h4>
<h3 class="fragment">How to query tens of billions of events interactively?</h3>
</section>
<section data-transition="fade">
<h3>Our solution, <span class="deliroll">DeliRoll</span>, is implemented in Python</span>.</h3>
<h3 class="fragment">Everyone knows that Python is SLOW.</h3>
<h3 class="fragment redshift">You can't handle big data with low latency in Python!</h3>
</section>
<section data-transition="linear">
<h1>Small Benchmark</h1>
</section>
<section data-transition="fade">
<ul>
<li>Data: 1.5 billion rows, 400 columns - 660GB.</li>
<li>Smaller execution time is better.</li>
<li>Fastest result chosen from 10 consecutive runs.</li>
<li>Queries are cached, results are not.</li>
</ul>
</section>
<section data-transition="fade">
<h2>Setup</h2><br>
<table width="100%">
<thead>
<tr>
<th width="35%"></th>
<th><h3 class="deliroll">DeliRoll</h3></th>
<th><h3 class="redshift">Amazon Redshift</h3></th>
</tr>
</thead>
<tbody>
<tr><th>Instance type</th><td>cr1.8xlarge</td><td>Redshift 8XL<td></tr>
<tr><th>Instances</th><td>1</td><td>3</td></tr>
<tr><th>Cores</th><td>16</td><td>32</td></tr>
<tr><th>RAM</th><td>244GB</td><td>240GB</td></tr>
<tr class="fragment"><th>Cost / Month</th><td>$2,520</td><td>$9,792</td></tr>
</tbody>
</table>
<div style="margin-top: 70px" class="fragment">
<h4>Compare: Redshift is reported to be 10x faster than Hive</h4>
<a href="http://www.slideshare.net/Hapyrus/amazon-redshift-is-10x-faster-and-cheaper-than-hadoop-hive">
http://www.slideshare.net/Hapyrus/amazon-redshift-is-10x-faster-and-cheaper-than-hadoop-hive
</a><br>
<a href="http://blog.aggregateknowledge.com/2013/05/16/aws-redshift-how-amazon-changed-the-game/">
http://blog.aggregateknowledge.com/2013/05/16/aws-redshift-how-amazon-changed-the-game
</a>
<a href="http://nerds.airbnb.com/redshift-performance-cost/">
http://nerds.airbnb.com/redshift-performance-cost
</a>
</div>
</section>
<section class="benchmark" data-transition="fade">
<h3>Aggregate One Column</h3>
<code>SELECT sum(column) FROM table</code><br><br>
<table width="90%">
<tbody>
<tr>
<th width="10%"><h4 class="redshift">Redshift</h4></th>
<td width="90%"><div class="redshift-bg" style="width: 200px;">1.9s</div></td>
</tr>
<tr>
<th><h4 class="deliroll">DeliRoll</h4></th>
<td><div class="deliroll-bg" style="width: 63px;">0.6s</div></td>
</tr>
</tbody>
</table>
</section>
<section class="benchmark" data-transition="fade">
<h3>Group by Dimension</h3>
<code>SELECT sum(column) FROM table GROUP BY dimension</code><br><br>
<table width="90%">
<tbody>
<tr>
<th width="10%"><h4 class="redshift">Redshift</h4></th>
<td width="90%"><div class="redshift-bg" style="width: 700px;">21.6s</div></td>
</tr>
<tr>
<th><h4 class="deliroll">DeliRoll</h4></th>
<td><div class="deliroll-bg" style="width: 562px;">17.4s</div></td>
</tr>
</tbody>
</table>
</section>
<section class="benchmark" data-transition="fade">
<h3>Aggregate 7 Columns</h3>
<code>SELECT sum(col1),sum(col2),...,sum(col7) FROM table</code><br><br>
<table width="90%">
<tbody>
<tr>
<th width="10%"><h4 class="redshift">Redshift</h4></th>
<td width="90%"><div class="redshift-bg" style="width: 500px;">4.8s</div></td>
</tr>
<tr>
<th><h4 class="deliroll">DeliRoll</h4></th>
<td><div class="deliroll-bg" style="width: 73px;">0.7s</div></td>
</tr>
</tbody>
</table>
</section>
<section class="benchmark" data-transition="fade">
<h3>Aggregate 250 Columns</h3>
<code>SELECT sum(col1),sum(col2),...,sum(col250) FROM table</code><br><br>
<table width="90%">
<tbody>
<tr>
<th width="10%"><h4 class="redshift">Redshift</h4></th>
<td width="90%"><div class="redshift-bg" style="width: 800px;">...8 minutes!</div></td>
<!--<div class="redshift-bg" style="width: 300px; float: left;"> </div><div class="redshift-bg" style="width: 2px; float: left; margin-left: 2px; margin-right: 2px;"> </div><div class="redshift-bg" style="width: 200px; float: left">4.8s</div></td>-->
</tr>
<tr>
<th><h4 class="deliroll">DeliRoll</h4></th>
<td><div class="deliroll-bg" style="width: 73px;">1.9s</div></td>
</tr>
</tbody>
</table>
</section>
<section>
<h1>Unpossible!</h1>
</section>
<section data-transition="fade">
<h3>DeliRoll Architecture</h3>
<div class="architecture">
<div class="archbox">Frontend (e.g. Tableau)</div>
⬇
<div class="archbox">PostgreSQL</div>
⬇
<div class="archbox highlight">Multicorn</div>
⬇
<div class="archbox">DeliRoll Server</div>
⬇
<div class="archbox">DeliRoll Worker</div>
⬇
<div class="archbox highlight">Numba</div>
⬇
<div class="archbox">LLVM</div>
⬇
<div class="archbox highlight">Densely-encoded data</div>
</div>
</section>
<section data-transition="linear">
<blockquote>
<p>Bad programmers worry about the code.</p>
<p>Good programmers worry about</p>
<p><h2 style="padding-top: 30px; padding-bottom: 20px" class="deliroll">data structures</h2></p>
<p>and their relationships.</p>
<p><br><strong>Linus Torvalds</strong></p>
</blockquote>
</section>
<section data-transition="fade">
<h2>Raw Data: Homogeneous Events</h2>
<br>
<table>
<tr><td>{"cookie_set":</td><td><em>true</em></td><td>,"country":</td><td><em>"Sweden"</em></td><td>,"cost":</td><td><em>840</em></td><td>}</td></tr>
<tr><td>{"cookie_set":</td><td><em>false</em></td><td>,"country":</td><td><em>"UK"</em></td><td>,"cost":</td><td><em>23</em></td><td>}</td></tr>
<tr><td>{"cookie_set":</td><td><em>true</em></td><td>,"country":</td><td><em>"China"</em></td><td>,"cost":</td><td><em>11</em></td><td>}</td></tr>
</table>
</section>
<section data-transition="fade">
<h2>Remove Redundant Field Names</h2>
<br>
<table>
<tr><td style="visibility: hidden">{"cookie_set":</td><td><em>true</em></td><td style="visibility: hidden">,"country":</td><td><em>"Sweden"</em></td><td style="visibility: hidden">,"cost":</td><td><em>840</em></td><td style="visibility: hidden">}</td></tr>
<tr><td style="visibility: hidden">{"cookie_set":</td><td><em>false</em></td><td style="visibility: hidden">,"country":</td><td><em>"UK"</em></td><td style="visibility: hidden">,"cost":</td><td><em>23</em></td><td style="visibility: hidden">}</td></tr>
<tr><td style="visibility: hidden">{"cookie_set":</td><td><em>true</em></td><td style="visibility: hidden">,"country":</td><td><em>"China"</em></td><td style="visibility: hidden">,"cost":</td><td><em>11</em></td><td style="visibility: hidden">}</td></tr>
</table>
</section>
<section data-transition="fade">
<h2>Encode Values in Binary</h2>
<br>
<table>
<tr>
<td style="visibility: hidden">{"cookie_set":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"country":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"cost":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">}</td>
</tr>
<tr>
<td style="visibility: hidden">{"cookie_set":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"country":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"cost":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">}</td>
</tr>
<tr>
<td style="visibility: hidden">{"cookie_set":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"country":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">,"cost":</td>
<td class="redshift-bg">integer</td>
<td style="visibility: hidden">}</td>
</tr>
</table>
</section>
<section data-transition="fade" data-iframe="data/matrix0.html">
<h3>Trick #0: Sparse Matrix</h3>
<h4>100% of the original size</h4>
<div class="framediv">
<iframe scrolling='no' width='600' height='600' src=''></iframe>
</div>
</section>
<section data-transition="fade" data-iframe="data/matrix1.html">
<h3>Trick #1: Typed Columns</h3>
<h4>50% of the original size</h4>
<div class="framediv">
<iframe scrolling='no' width='600' height='600' src=''></iframe>
</div>
</section>
<section data-transition="fade" data-iframe="data/matrix2.html">
<h3>Trick #2: Sort Dimensions</h3>
<h4>50% of the original size</h4>
<div class="framediv">
<iframe scrolling='no' width='600' height='600' src=''></iframe>
</div>
</section>
<section data-transition="fade" data-iframe="data/matrix3.html">
<h3>Trick #3: Merge Dimensions</h3>
<h4>20% of the original size</h4>
<div class="framediv">
<iframe scrolling='no' width='600' height='600' src=''></iframe>
</div>
</section>
<section data-transition="fade" data-iframe="data/matrix4.html">
<h3>Trick #4: Dense Encoding</h3>
<h4>15% of the original size</h4>
<div class="framediv">
<iframe scrolling='no' width='600' height='600' src=''></iframe>
</div>
</section>
<section>
<h2>Why Compressed Data Structure?</h2>
<p style="margin-top: 40px;">
Compression ratio dropped from 11:1 to 1.5:1</p>
<h3 class="deliroll">Less redundancy</h3>
<p style="margin-top: 40px;">
The dense encoding results to faster computation</p>
<h3 class="deliroll">L1/L2 cache efficiency</h3>
<p style="margin-top: 40px;">
The dense encoding is partially</p>
<h3 class="deliroll">self-indexing</h3>
</section>
<section data-transition="linear">
<img src="numba-logo.png" style="border: 0px">
<p>Numba is a just-in-time specializing compiler which compiles annotated Python and NumPy code to LLVM.</p>
<br>
<pre><code data-trim contenteditable>
from numba import autojit
@autojit
def sum2d(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
</code></pre>
</section>
<section data-transition="fade">
<h4>Python generates a Python function based on the query</h4>
<pre><code data-trim contenteditable>
with self.DEF([(m, types[m]) for m in args]):
self.INIT_SPARSEVAR(score_metrics)
with self.FOR_ALL_ROWS(has_row_filter):
with self.ROW_MATCHES(flags, where_expr, score_metrics, partitioned):
self.ASSIGN_METRICS(score_metrics)
</code></pre>
<div class="fragment">
<h4>which compiles to Numba-compatible low-level Python</h4>
<pre><code data-trim contenteditable>
while (_indptr_idx < _indptr_len):
while (True):
_byte = _indptr[_indptr_idx]
if (_byte & 1):
_indptr_row += (_byte >> 1) + 1
_indptr_val |= (_byte >> 1) << _shift
</code></pre>
</div>
<div class="fragment">
<h4>which compiles to LLVM</h4>
<pre><code data-trim contenteditable>
while_condition_20:15:
%_shift_2 = phi i32
%_indptr_idx_3 = phi i64
while_body_21:12:
%81 = mul i64 %_indptr_idx_3, %29
%82 = add i64 0, %81
%83 = getelementptr i8* %21, i64 %82
</code></pre>
</div>
<div class="fragment">
<h4>which compiles to optimized machine code, on the fly.</h4>
</div>
</section>
<section data-transition="linear">
<img src="multicorn-logo.png">
<p>Multicorn allows you to access any data source in your PostgreSQL database in Python.</p>
</section>
<section data-transition="fade">
<h4>In Postgres, create a new Foreign Data Table using Multicorn</h4>
<pre><code data-trim contenteditable>
CREATE FOREIGN TABLE constanttable (
test character varying, test2 character varying
) server multicorn_srv options (
wrapper 'myfdw.ConstantForeignDataWrapper'
)
SELECT * from constanttable;
</code></pre>
<div class="fragment">
<h4>SQL query gets forwarded to our Python class by Postgres</h4>
<pre><code data-trim contenteditable>
class ConstantForeignDataWrapper(ForeignDataWrapper):
def execute(self, quals, columns):
for index in range(4):
line = {}
for column_name in self.columns:
line[column_name] = '%s %s' % (column_name, index)
yield line
</code></pre>
</div>
<div class="fragment">
<h4>Query is evaluated and results are returned back to Postgres</h4>
<pre><code data-trim contenteditable>
test | test2
---------+----------
test 0 | test2 0
test 1 | test2 1
test 2 | test2 2
test 3 | test2 3
</code></pre>
</div>
</section>
<section data-transition="linear">
<h2 class="redshift">Cheating?</h2>
<div class="fragment">
<p><br>That's the whole point.</p><br>
<p>You can use a high-level language to <strong><span class="deliroll">quickly</span></strong> implement
<strong><span class="deliroll">domain-specific</span></strong> solutions that
<strong><span class="deliroll">outperform</span></strong> generic solutions, regardless of the language they use.
</p>
</div>
</section>
<section data-transition="fade">
<h3>And, most importantly,</h3>
<blockquote style="font-size: 120%; line-height: 1.5em;">
You dare to do things<br>
that would be too painful to do<br>
with a lower-level language.
</blockquote>
</section>
<section data-transition="linear">
<h2>Thank You!</h2><br>
<p>
<img width="300px" src="logo.png"/><h3>is Hiring</h3>
</p>
<br>
<p><em>Python, Erlang, Big Data, AWS</em></p>
<br><h4>Fastest Growing Advertising Company Two Years in a Row</h4>
</section>
</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
// 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; } }
]
});
Reveal.addEventListener("slidechanged", function(ev){
var slide = Reveal.getCurrentSlide();
var framesrc = slide.getAttribute("data-iframe");
if (framesrc){
var all = window.document.getElementsByClassName("framediv");
for (i = 0; i < all.length; i++)
all[i].innerHTML = "<iframe width='600' height='600' src=''></iframe>";
html = "<iframe scrolling='no' width='600' height='600' src='" +
framesrc + "'></iframe>";
slide.getElementsByClassName("framediv")[0].innerHTML = html;
}
});
</script>
</body>
</html>