-
Notifications
You must be signed in to change notification settings - Fork 0
/
20100217-hadoop-bay-area.tex
477 lines (402 loc) · 10.5 KB
/
20100217-hadoop-bay-area.tex
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
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamerfont*{frametitle}{size=\normalsize,series=\bfseries}
\setbeamertemplate{navigation symbols}{}
%\usefonttheme{professionalfonts}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{ulem}
\usepackage{listings}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{hyperref}
% adds the \MongoLogo command to put the logo on a slide
\usepackage[absolute,overlay]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}
\newcommand{\MongoLogo}{
\begin{textblock}{14}(2.0,0.7)
\includegraphics[height=0.8cm]{logo-mongodb-ondark.png}
\end{textblock}
}
\pgfdeclareimage[height=2in]{featuregraph}{featuresPerformance.png}
\pgfdeclareimage[height=2in]{sharding}{sharding.png}
\title{MongoDB}
\subtitle{Or how I learned to stop worrying and love the database}
\author{Mathias Stearn}
\institute{10gen}
\date{Bay Area Hadoop Meetup -- February 17, 2010}
\AtBeginSection[]
{
\begin{frame}<beamer>{}
\tableofcontents[currentsection]
\end{frame}
}
\begin{document}
\begin{frame}
\MongoLogo
\titlepage
\end{frame}
\begin{frame}
\MongoLogo
\begin{quote}
The resulting [MongoDB] application has literally changed the way the
pharma company conducts business. Whereas in the past, patient queries
could take minutes to hours, results are now essentially real-time.
\end{quote}
\small \url{http://news.cnet.com/8301-13846_3-10451248-62.html}
\begin{quote}
Why bother [with] memcached for caching HTTP sessions when you have an
authoritative MongoDB? The performance is there.
\end{quote}
\small Carl Byström, @cgbystrom on twitter
\end{frame}
\begin{frame}
\MongoLogo
\begin{quote}
Compared to hadoop, Mongo's speed and startup time make developing new
queries much easier; what took us two weeks to get working on hadoop was
done in two days on mongo.
\end{quote}
\small Emmett Shear, CTO (and developer) at Justin.tv
\begin{quote}
It took me half a day to go from not touching MongoDB to writing some
fairly good functionality against it. It makes setting up, configuring, and
interfacing with MySQL look archaic -- ridiculously archaic.
\end{quote}
\small \url{http://geekaustin.org/2010/01/31/mongodb-day-geek-austin-data-series}
\end{frame}
%\begin{frame}
%\MongoLogo
%\begin{center}
%\includegraphics[height=7cm]{featuresPerformance.png}
%\end{center}
%\end{frame}
\begin{frame}
\MongoLogo
\tableofcontents
\end{frame}
\section{What is MongoDB?}
\subsection{Document Oriented}
\begin{frame}[fragile]
\MongoLogo
\begin{itemize}
\item Document Oriented
\item Organized into Databases and Collections (like Tables)
\item JSON-like (BSON)
\item Schemaless
\item Dynamic, Strong Typing
\item Database can ``reach into'' objects
\end{itemize}
\begin{small}
\begin{verbatim}
db.people.insert({
_id: "mstearn",
name: "Mathias Stearn",
karma: 42,
active: true,
birthdate: new Date(517896000000),
interests: ["MongoDB", "Python", "Üñíçøđĕ"],
subobject: {foo: "bar"}
});
\end{verbatim}
\end{small}
\end{frame}
\subsection{JavaScript Enabled}
\begin{frame}[fragile]
\MongoLogo
JavaScript used for:
\begin{itemize}
\item Shell and Documentation
\item (Very) Advanced Queries
\item ``Group By'' Queries
\item MapReduce
\end{itemize}
\begin{verbatim}
db.users.find({$where: "this.a + this.b >= 42"});
db.posts.group(
{ key: "user"
, initial: {count:0, comments:0}
, reduce: function(doc,out){
out.count++;
out.comments += doc.comments.length; }
, finalize: function(out){
out.avg = out.comments / out.count; }
});
\end{verbatim}
\end{frame}
\subsection{Fast, Scalable, Available, and Reliable}
\begin{frame}{Fast, Scalable, Available, and Reliable}
\MongoLogo
\begin{itemize}
\item Master-Slave replication for Availability and Reliability
\begin{itemize}
\item Replica-Pairs support auto-negotiation for master
\end{itemize}
\item Auto-Sharding for Horizontal Scalability
\begin{itemize}
\item Distributes based on specified field
\item Currently alpha
\end{itemize}
\item MMAP database files to automatically use available RAM
\item Asynchronous modifications
\end{itemize}
\end{frame}
\begin{frame}
\MongoLogo
\center
\pgfuseimage{sharding}
\end{frame}
\section{What Makes Mongo Special?}
\subsection{Native Language Integration}
\begin{frame}
\MongoLogo
\begin{block}{Official}
\begin{itemize}
\item Java/JVM
\item Python
\item Ruby
\item C/C++
\item Perl
\item PHP
\end{itemize}
\end{block}
\begin{block}{Community Supported}
Closure,
Scala,
C\#,
Haskell,
Erlang,
{\it and More}
\end{block}
\end{frame}
\subsection{Rich Data Types}
\begin{frame}[fragile]
\MongoLogo
\begin{block}{JSON}
\begin{itemize}
\item String (UTF8)
\item Double
\item Object (hash/map/dict)
\item Array
\item Bool
\item Null / Undefined
\end{itemize}
\end{block}
\begin{block}{Extras}
\begin{itemize}
\item Date
\item Int32 / Int64
\item ObjectID (12 bytes: timestamp + host + pid + counter)
\item Binary (with type byte)
\end{itemize}
\end{block}
\end{frame}
\subsection{Atomic Modifiers}
\begin{frame}[fragile]
\MongoLogo
\begin{itemize}
\item \$set
\item \$inc
\item \$multiply (soon)
\item \$push / \$pushAll
\item \$pull / \$pullAll
\end{itemize}
\begin{small}
\begin{verbatim}
db.posts.update({_id:SOMEID}, {$push:{tags:"mongodb"}})
db.tags.update({_id:"mongodb"}, {$inc:{count:1}},
{upsert:true}})
\end{verbatim}
\end{small}
\end{frame}
\subsection{Dynamic Queries}
\begin{frame}[fragile]
\frametitle{Simple}
\MongoLogo
\begin{verbatim}
db.posts.findOne({ user: "mstearn" });
var cursor = db.posts.find({ user: "mstearn" });
cursor.forEach(function(){
doSomething(this.text);
});
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sorted}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn" }
).sort({timestamp:-1})
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Paginated}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn" }
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Simple Tag Search}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: "mongo"
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Complex Tag Search}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: {$in: ["mongo", "mongodb"]}
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Nested Objects}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: {$in: ["mongo", "mongodb"]}
, comments.user: "mdirolf"
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Regular Expressions}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: {$in: ["mongo", "mongodb"]}
, comments.user: "mdirolf"
, text: /windows/i
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Ranges}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: {$in: ["mongo", "mongodb"]}
, comments.user: "mdirolf"
, text: /windows/i
, points: {$gt: 10, $lt: 100}
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Arbitrary JavaScript}
\MongoLogo
\begin{verbatim}
db.posts.find(
{ user: "mstearn"
, tags: {$in: ["mongo", "mongodb"]}
, comments.user: "mdirolf"
, text: /windows/i
, points: {$gt: 10, $lt 100}
, $where: "this.a + this.b >= 42"
}
).sort({timestamp:-1}).skip(10).limit(10);
\end{verbatim}
\end{frame}
\section{MapReduce}
\subsection{Built-In MapReduce}
\begin{frame} [fragile]
\MongoLogo
\begin{small}
\begin{verbatim}
db.posts.mapReduce(
function() {
this.comments.forEach(c){
emit(c.user,
{count:1, words:c.text.split().length; } }
, function(key, values){
for (var i=1; i<values.length; i++){
values[0].count += values[i].count;
values[0].words += values[i].words; }
return values[0]; }
, { finalize: function(out){
out.avg = out.words / out.count;
return out; }
, query: {posted: {$gt: new Date(2010,0,1)}}
, out: 'posts.comment_stats'
}
});
\end{verbatim}
\end{small}
\end{frame}
\subsection{Easy Hadoop-Mongo Integration}
\begin{frame}{Easy Hadoop-Mongo Integration}
\MongoLogo
\begin{itemize}
\item mongoexport can export to JSON/CSV/TSV
\begin{itemize}
\item Can also easily use a custom script
\end{itemize}
\item Process in Hadoop
\item Use mongoimport to get data back into MongoDB
\end{itemize}
\end{frame}
\subsection{Better Hadoop-Mongo Integration}
\begin{frame} {Better Hadoop-Mongo Integration}
\MongoLogo
\begin{itemize}
\item mongodump writes a stream of BSON to a file
\item Write an InputFilter and RecordReader to read BSON
\item Write a BSONWriter class to directly use the data
\begin{itemize}
\item Just added two methods to driver to make this easier
\end{itemize}
\item Process the data with the Java/Scala/Closure driver
\item Write a custom RecordWriter to either:
\begin{itemize}
\item Dump to a file and use mongorestore
\item Dump the output directly to MongoDB
\end{itemize}
\item Optional: use renameCollection to mimic our MapReduce
\end{itemize}
\end{frame}
\section{}
\begin{frame}{Upcoming events}{}
\MongoLogo
\begin{itemize}
\item NoSQL Live! from Boston (March 11)
\item MongoDB Training in San Francisco (March 25)
\item San Fransisco MySQL Meetup (April 12)
\end{itemize}
\end{frame}
\begin{frame}{Links}{}
\MongoLogo
\begin{itemize}
\item http://mongo.kylebanker.com (Try mongo in your browser)
\item http://www.mongodb.org
\item \#mongodb on irc.freenode.net
\item mongodb-user on google groups
\end{itemize}
\begin{itemize}
\item [email protected]
\item @mathias\_mongo on twitter
\end{itemize}
\end{frame}
\end{document}
% vim: set softtabstop=2