Juggling Chainsaws: Perl and MongoDB

119
Juggling Chainsaws David Golden Senior Engineer, MongoDB YAPC::NA 2015

Transcript of Juggling Chainsaws: Perl and MongoDB

Page 1: Juggling Chainsaws: Perl and MongoDB

Juggling Chainsaws

David GoldenSenior Engineer, MongoDB

YAPC::NA 2015

Page 2: Juggling Chainsaws: Perl and MongoDB

I lead theMongoDB Perldriver project

Page 3: Juggling Chainsaws: Perl and MongoDB
Page 4: Juggling Chainsaws: Perl and MongoDB
Page 5: Juggling Chainsaws: Perl and MongoDB

Do I need to explain what MongoDB is?

Page 6: Juggling Chainsaws: Perl and MongoDB
Page 7: Juggling Chainsaws: Perl and MongoDB

NoSQL

Page 8: Juggling Chainsaws: Perl and MongoDB

Not NoSQL

Page 9: Juggling Chainsaws: Perl and MongoDB

Not NoSQL

Page 10: Juggling Chainsaws: Perl and MongoDB

DocumentsAuto-shardingNative replicationPluggable storage enginesAggregation framework queriesComprehensive secondary indexesMultiple geospatial indexes and text searchACID guarantees available at the document levelFault tolerance and disaster recovery through automated failoverEnterprise-version has extensive capabilities for authentication, authorization, auditing and encryptionOps Manager and MMS provide continuous incremental backup, point-in-time recover y of replica sets and consistent snapshots of sharded cluster s.

Page 11: Juggling Chainsaws: Perl and MongoDB

DocumentsAuto-shardingNative replicationPluggable storage enginesAggregation framework queriesComprehensive secondary indexesMultiple geospatial indexes and text searchACID guarantees available at the document levelFault tolerance and disaster recovery through automated failoverEnterprise-version has extensive capabilities for authentication, authorization, auditing and encryptionOps Manager and MMS provide continuous incremental backup, point-in-time recover y of replica sets and consistent snapshots of sharded cluster s.

Page 12: Juggling Chainsaws: Perl and MongoDB

"Troll" © S.L.M Roma https://flic.kr/p/4uRvNc (CC BY-NC-SA)

Page 13: Juggling Chainsaws: Perl and MongoDB

"chainsaws are fun" © Ryan Kathleen https://flic.kr/p/5zY75A (CC BY)

Page 14: Juggling Chainsaws: Perl and MongoDB

"London Juggler" © Leon Benjamin https://flic.kr/p/cmTzL (CC BY)

Page 15: Juggling Chainsaws: Perl and MongoDB

"London Juggler" © Leon Benjamin https://flic.kr/p/cmTzL (CC BY)

Page 16: Juggling Chainsaws: Perl and MongoDB

Perl and MongoDB are surprisingly similar

Page 17: Juggling Chainsaws: Perl and MongoDB

ster·e·o·typenoun

a widely held but fixed and oversimplified image or idea of a particular person or thing

Page 18: Juggling Chainsaws: Perl and MongoDB

Trolls love stereotypes

Page 19: Juggling Chainsaws: Perl and MongoDB

Trolls

Perl and MongoDB♥

Page 20: Juggling Chainsaws: Perl and MongoDB

Trolls

Perl and MongoDB💩

Page 21: Juggling Chainsaws: Perl and MongoDB

Let's playGuess the meme!

Page 22: Juggling Chainsaws: Perl and MongoDB

"___ is dead"

Page 23: Juggling Chainsaws: Perl and MongoDB

"Dead camel" © Nick Brooks https://flic.kr/p/ivZdP (CC BY-NC-SA)

Page 24: Juggling Chainsaws: Perl and MongoDB

"___ is web scale"

Page 25: Juggling Chainsaws: Perl and MongoDB

"MongoDB is web Scale" © gar1t http://www.mongodb-is-web-scale.com/

Page 26: Juggling Chainsaws: Perl and MongoDB

"___ is line noise"

Page 27: Juggling Chainsaws: Perl and MongoDB

$_='ev al("seek\040D ATA,0, 0;");foreach(1..3) {<DATA>;}my @camel1hump;my$camel; my$Camel ;while( <DATA>){$_=sprintf("%-6 9s",$_);my@dromedary 1=split(//);if(defined($ _=<DATA>)){@camel1hum p=split(//);}while(@dromeda ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif t(@dromedary1 ))&&/\S/){$camel1hump+=1<<$CAMEL;} $CAMEL--;if(d efined($_=shift(@dromedary1))&&/\S/){ $camel1hump+=1 <<$CAMEL;}$CAMEL--;if(defined($_=shift( @camel1hump))&&/\S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if( defined($_=shift(@camel1hump))&&/\S/){$camel1hump+=1<<$CAME L;;}$camel.=(split(//,"\040..m`{/J\047\134}L^7FX"))[$camel1h ump];}$camel.="\n";}@camel1hump=split(/\n/,$camel);foreach(@ camel1hump){chomp;$Camel=$_;y/LJF7\173\175`\047/\061\062\063\ 064\065\066\067\070/;y/12345678/JL7F\175\173\047`/;$_=reverse; print"$_\040$Camel\n";}foreach(@camel1hump){chomp;$Camel=$_;y /LJF7\173\175`\047/12345678/;y/12345678/JL7F\175\173\0 47`/; $_=reverse;print"\040$_$Camel\n";}';;s/\s*//g;;eval; eval ("seek\040DATA,0,0;");undef$/;$_=<DATA>;s/\s*//g;( );;s ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__ \124 \1 50\145\040\165\163\145\040\157\1 46\040\1 41\0 40\143\141 \155\145\1 54\040\1 51\155\ 141 \147\145\0 40\151\156 \040\141 \163\16 3\ 157\143\ 151\141\16 4\151\1 57\156 \040\167 \151\164\1 50\040\ 120\1 45\162\ 154\040\15 1\163\ 040\14 1\040\1 64\162\1 41\144 \145\ 155\14 1\162\ 153\04 0\157 \146\ 040\11 7\047\ 122\1 45\15 1\154\1 54\171 \040 \046\ 012\101\16 3\16 3\15 7\143\15 1\14 1\16 4\145\163 \054 \040 \111\156\14 3\056 \040\ 125\163\145\14 4\040\ 167\1 51\164\1 50\0 40\160\ 145\162 \155\151

"Camel JAPH" © Erudil http://www.cpan.org/misc/japh

Page 28: Juggling Chainsaws: Perl and MongoDB

"___ will lose your data"

Page 29: Juggling Chainsaws: Perl and MongoDB
Page 30: Juggling Chainsaws: Perl and MongoDB
Page 31: Juggling Chainsaws: Perl and MongoDB

"___ is read only"

Page 32: Juggling Chainsaws: Perl and MongoDB

"fresh ramen noodle" © Kropsoq http://goo.gl/mu2fIQ (CC BY-SA)

Page 33: Juggling Chainsaws: Perl and MongoDB

"__ is unsafe by default"

Page 34: Juggling Chainsaws: Perl and MongoDB

TRICK QUESTION!

Page 35: Juggling Chainsaws: Perl and MongoDB

&

Page 36: Juggling Chainsaws: Perl and MongoDB

✓ Grief from haters

Page 37: Juggling Chainsaws: Perl and MongoDB

✓ Similar data model

Page 38: Juggling Chainsaws: Perl and MongoDB

"A hash brown patty" © Mike.lifeguard http://goo.gl/2we5ye (CC BY-SA)

Page 39: Juggling Chainsaws: Perl and MongoDB

"buy it in bottles" © Pete https://flic.kr/p/qbvaRb (CC BY)

Page 40: Juggling Chainsaws: Perl and MongoDB

perldsc

Page 41: Juggling Chainsaws: Perl and MongoDB

Data Structures Cookbok

Page 42: Juggling Chainsaws: Perl and MongoDB

HoH, AoH, HoA, AoA…

Page 43: Juggling Chainsaws: Perl and MongoDB
Page 44: Juggling Chainsaws: Perl and MongoDB
Page 45: Juggling Chainsaws: Perl and MongoDB

Perl programmers use dynamic data structures

all the time!!!

Page 46: Juggling Chainsaws: Perl and MongoDB

MongoDB♥

Data Structures

Page 47: Juggling Chainsaws: Perl and MongoDB

Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:TICK_COMIC_CON_EXTRAVAGANZA_1.jpg

Page 48: Juggling Chainsaws: Perl and MongoDB

{ name => 'The Tick', battlecry => 'Spoon!', birthday => '1973-07-16', relations => { friends => [ 'Arthur', 'Die Fledermaus', 'American Maid', ], foes => [ 'The Terror', 'Thrakkorzog', ], }

Page 49: Juggling Chainsaws: Perl and MongoDB

Sort heroes by first friend's name?

Page 50: Juggling Chainsaws: Perl and MongoDB

{ name => 'The Tick', battlecry => 'Spoon!', birthday => '1973-07-16', relations => { friends => [ 'Arthur', 'Die Fledermaus', 'American Maid', ], foes => [ 'The Terror', 'Thrakkorzog', ], }

Page 51: Juggling Chainsaws: Perl and MongoDB

# Perl using Schwartzian Transform my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, $_->{relations}{friends}[0] };

Page 52: Juggling Chainsaws: Perl and MongoDB

# MongoDB using query with sort clause my @sorted = $heroes->find( {}, { sort => [ 'relations.friends.0' => 1 ] } )->all;

Page 53: Juggling Chainsaws: Perl and MongoDB

# Perl using Schwartzian Transform my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, $_->{relations}{friends}[0] };

# MongoDB using query with sort clause my @sorted = $heroes->find( {}, { sort => [ 'relations.friends.0' => 1 ] } )->all;

Page 54: Juggling Chainsaws: Perl and MongoDB

✓ Missing things others take for granted

Page 55: Juggling Chainsaws: Perl and MongoDB

No function signatures

Page 56: Juggling Chainsaws: Perl and MongoDB

No read committed

Page 57: Juggling Chainsaws: Perl and MongoDB

No concurrency

Page 58: Juggling Chainsaws: Perl and MongoDB

No transactions

Page 59: Juggling Chainsaws: Perl and MongoDB

No (real) OO

Page 60: Juggling Chainsaws: Perl and MongoDB

No joins

Page 61: Juggling Chainsaws: Perl and MongoDB

No booleans

Page 62: Juggling Chainsaws: Perl and MongoDB

No stored procedures

Page 63: Juggling Chainsaws: Perl and MongoDB

✓ Experienced userswork around flaws

Page 64: Juggling Chainsaws: Perl and MongoDB

Non-idempotent writes

Page 65: Juggling Chainsaws: Perl and MongoDB

Strings for errors

Page 66: Juggling Chainsaws: Perl and MongoDB

Consensus read

Page 67: Juggling Chainsaws: Perl and MongoDB

Version numbers

Page 68: Juggling Chainsaws: Perl and MongoDB

Version numbers

Page 69: Juggling Chainsaws: Perl and MongoDB

Query "language"

Page 70: Juggling Chainsaws: Perl and MongoDB

Ambiguous scalar type

Page 71: Juggling Chainsaws: Perl and MongoDB

16MB doc limit

Page 72: Juggling Chainsaws: Perl and MongoDB

IO layers

Page 73: Juggling Chainsaws: Perl and MongoDB

Rollback on failover

Page 74: Juggling Chainsaws: Perl and MongoDB

✓ Vibrant, enthusiaticcommunities

Page 75: Juggling Chainsaws: Perl and MongoDB

MUGs

Perl Mongers

Page 76: Juggling Chainsaws: Perl and MongoDB

ConferencesMailing Lists

IRC

Page 77: Juggling Chainsaws: Perl and MongoDB

✓ Similar philosophies

Page 78: Juggling Chainsaws: Perl and MongoDB

ManipulexityWhipuptitude

Page 79: Juggling Chainsaws: Perl and MongoDB

Manipulexity Manipulation of complex things

— Larry Wall

Page 80: Juggling Chainsaws: Perl and MongoDB

Whipuptitude Aptitude for whipping things up

— Larry Wall

Page 81: Juggling Chainsaws: Perl and MongoDB

Tools for gettingthe job done

Page 82: Juggling Chainsaws: Perl and MongoDB

Swiss-Army knife?

Page 83: Juggling Chainsaws: Perl and MongoDB

Swiss-Army chainsaw!!!

Page 84: Juggling Chainsaws: Perl and MongoDB

Henry Spencer described the Perl scripting language as a “Swiss-Army chainsaw”, intending to convey his evaluation of the language as exceedingly powerful but ugly and noisy and prone to belch noxious fumes.

— The Jargon File

Page 85: Juggling Chainsaws: Perl and MongoDB

This had two results: (1) Perl fans adopted the epithet as a badge of pride, and (2) it entered more general usage to describe software that is highly versatile but distressingly inelegant.

— The Jargon File

Page 86: Juggling Chainsaws: Perl and MongoDB

Highly versatile but distressingly inelegant?

Page 87: Juggling Chainsaws: Perl and MongoDB

YES

Page 88: Juggling Chainsaws: Perl and MongoDB

Great at a few things

Page 89: Juggling Chainsaws: Perl and MongoDB

Good enough for many things

Page 90: Juggling Chainsaws: Perl and MongoDB

And if one is good,wouldn't two be better?

Page 91: Juggling Chainsaws: Perl and MongoDB

+

Page 92: Juggling Chainsaws: Perl and MongoDB

"Camel warning sign UAE" © Katzenmeier http://commons.wikimedia.org/wiki/File:Camel_warning_sign_UAE.jpg (PD)

Page 93: Juggling Chainsaws: Perl and MongoDB

CPAN Meta file indexing

Page 94: Juggling Chainsaws: Perl and MongoDB

META.json

Page 95: Juggling Chainsaws: Perl and MongoDB

{ "abstract" : "File path utility", "author" : [ "David Golden <[email protected]>" ], "name" : "Path-Tiny", "prereqs" : { "runtime" : { "requires" : { "Carp" : "0", "Cwd" : "0", "Digest" : "1.03", "Digest::SHA" : "5.45", ... }, }, ... }, "provides" : { "Path::Tiny" : { "file" : "lib/Path/Tiny.pm", "version" : "0.068" }, ... }, "release_status" : "stable", ... "x_contributors" : [ "Alex Efros <[email protected]>", ... ], ... }

Page 96: Juggling Chainsaws: Perl and MongoDB

Thought experiment:Rebuild CPAN?

Page 97: Juggling Chainsaws: Perl and MongoDB

Rebuilding CPAN?• Tarball storage

• Tarball processing

• Worker logs

• Index lookup

• Text search

Page 98: Juggling Chainsaws: Perl and MongoDB

# store a file open $fh, "<", $tarball_path; $gridfs = $db->get_gridfs("tarballs"); $id = $gridfs->put($fh, $metadata);

# get a file $bytes = $gridfs->get($id)->slurp;

Storage: GridFS

Page 99: Juggling Chainsaws: Perl and MongoDB

# in supervisor my $queue = MongoDBx::Queue->new(...); $queue->add_task({ tarball_id => $id });

# in worker while ( my $task = $queue->reserve_task ) { # ... process tarball ... $queue->remove_task( $task ); }

Processing: MongoDBx::Queue

Page 100: Juggling Chainsaws: Perl and MongoDB

$db->run_command([ create => "pause_log", capped => true, max => 1000, ]);

$log->find( {}, { cursorType => 'tailable' } );

Logging: capped collection

Page 101: Juggling Chainsaws: Perl and MongoDB

$packages->find( { mod => "Foo", ver => { '$gte' => $v_min, '$lte' => $v_max, }, } );

Index lookup: query language

Page 102: Juggling Chainsaws: Perl and MongoDB

$packages->find( { mod => "Foo::Bar", ver => { '$gte' => $v_min, '$lte' => $v_max, }, } );

Index lookup: query language

Page 103: Juggling Chainsaws: Perl and MongoDB

$meta->find( { '_authorized.Foo' => true 'release_status' => 'stable', } );

# sort through versions client side # with version.pm

Index lookup (take 2)

Page 104: Juggling Chainsaws: Perl and MongoDB

$meta->indexes->create_one([ abstract: "text", keywords: "text", ]);

$meta->find( { '$text' => { '$search' => "dist zilla plugin" } });

Text search: text indexes

Page 105: Juggling Chainsaws: Perl and MongoDB

Some other handy tools• Geographic indexing and search

• TTL indexes (auto-expiration)

Page 106: Juggling Chainsaws: Perl and MongoDB

"The Long Road" © Corey Leopold https://flic.kr/p/6AX7aq (CC BY)

Page 107: Juggling Chainsaws: Perl and MongoDB

Coming soon:MongoDB v1.0.0 Beta 1

Page 108: Juggling Chainsaws: Perl and MongoDB

Coming soon:MongoDB v1.0.0 Beta 1

Right after

this talk!

Page 109: Juggling Chainsaws: Perl and MongoDB

Coming soon:MongoDB v1.0.0 Beta 1

Right after

this talk! BeforeLunch

Page 110: Juggling Chainsaws: Perl and MongoDB

Coming soon:MongoDB v1.0.0 Beta 1

Right after

this talk! BeforeLunchDuring

YAPC

Page 111: Juggling Chainsaws: Perl and MongoDB

Coming soon:MongoDB v1.0.0 Beta 1

Right after

this talk! BeforeLunchDuring

YAPCRight now?

Page 112: Juggling Chainsaws: Perl and MongoDB

• Better server discovery, monitoring, failover

• Immutable config (and no more globals!)

• New CRUD and Index APIs

• Consistent error handling

• Progress towards a pure-Perl option

• BSON round-trippability

Page 113: Juggling Chainsaws: Perl and MongoDB

"Dub Dub Dub" © Owen B https://flic.kr/p/8jGEnz (CC BY-NC)

Page 114: Juggling Chainsaws: Perl and MongoDB

What I ask of you...

Page 115: Juggling Chainsaws: Perl and MongoDB

Try it out!

Page 116: Juggling Chainsaws: Perl and MongoDB

Or, try it out again!

Page 117: Juggling Chainsaws: Perl and MongoDB

Get involved!

Page 118: Juggling Chainsaws: Perl and MongoDB

• Download MongoDB

• Try the beta driver

• Find a MUG near you

• Follow my blog (dagolden.com)

• Follow me on twitter (@xdg)

• ++ the driver on MetaCPAN

• Ask questions

Page 119: Juggling Chainsaws: Perl and MongoDB

Questions?

[email protected]