Your SlideShare is downloading. ×
0
Who am I?<br />
what is<br />?<br />
Application<br />Perl<br />Apache<br />Linux<br />
Application<br />Perl<br />Database<br />Apache<br />Linux<br />
Application<br />Perl<br />Apache<br />Windows<br />
Application<br />Perl<br />Apache<br />Linux<br />
Application<br />Perl<br />Apache<br />Linux<br />
Application<br />Perl<br />Apache<br />Linux<br />
Application<br />The world's most<br />popular open source<br />database<br />Perl<br />Apache<br />Linux<br />
Application<br />Perl<br />Apache<br />Linux<br />The world's most<br />advanced open source<br />database<br />
databases<br />contain tables <br />contain rows<br />
schema<br />databases<br />contain tables <br />contain rows<br />
schema<br />databases<br />contain tables <br />contain rows<br />joins<br />
schema<br />databases<br />contain tables <br />contain rows<br />joins<br />
Application<br />Perl<br />Apache<br />Linux<br />
getting  started<br />
www.mongodb.org<br />
cpan -i MongoDB<br />
$conn = MongoDB::Connection->new;<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />NO ADMINISTRATION<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$table = $db->bar;<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$table = $db->bar;<br />
server<br />
server<br />databases<br />
server<br />databases<br />contain tables <br />
server<br />databases<br />contain tables <br />
server<br />databases<br />collections<br />contain tables <br />
server<br />databases<br />collections<br />contain tables <br />contain rows<br />
server<br />databases<br />collections<br />contain tables <br />contain rows<br />
server<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />
server<br />schema<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />
server<br />schema<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />joins<br />
server<br />databases<br />contain collections <br />contain documents<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$collection = $db->bar;<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$collection = $db->bar;<br />NO ADMINISTRATION<br />
$conn = MongoDB::Connection->new;<br />$db = $conn->foo<br />$collection = $db->bar;<br />$doc = {"name" => "kristina",<br...
$conn = MongoDB::Connection->new;<br />$db = $conn->foo<br />$collection = $db->bar;<br />$doc = {"name" => "kristina",<br...
mongo is type-sensitive <br />and type-rich<br />
<ul><li>null
boolean
integer
double
string
array
hash
qr/fobar/i
$bindata
DateTime
MongoDB::OID
MongoDB::Code
MongoDB::MinKey
MongoDB::MaxKey</li></li></ul><li>$collection->find_one({<br />    "name" => "kristina"});<br />
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
$collection->find_one({<br />    "name" => "kristina"});<br />$collection->find_one({<br />    "contact.twitter" => "@kcho...
while (my $doc = $cursor->next) {<br />    # ... <br />}<br />my @results = $cursor->all;<br />
x < 3<br />{"x" => {'$lt' => 3}}<br />
$gt<br />$lte<br />$ne<br />$mod<br />$exists<br />$type<br />...<br />
$collection->update(<br />  {"name" => "kristina"},<br />
$collection->update(<br />  {"name" => "kristina"},<br />  {'$set' => <br />
$collection->update(<br />  {"name" => "kristina"},<br />  {'$set' => <br />    {"contact.website" => <br />      "snailin...
updates are...<br /><ul><li>atomic
in-place (when possible)
able to create and delete fields
able to create documents</li></li></ul><li>$collection->update(<br />  {"url" => "example.com"},<br />  {'$inc' => {"pagev...
$set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
$set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
$set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
$set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
"$gte"<br />
"<null>"<br />
""<br />
'$gte' or "$gte"<br />
Or define your own!<br />":gte"<br />"=gte"<br />"?gte"<br />
Or define your own!<br />" gte"<br />
Or define your own!<br />" gte"<br />" ♕ gte"<br />
Or define your own!<br />" gte"<br />" ♕ gte"<br />"xgte"<br />
features<br />
I suddenly have a deep love for stored procedures<br />
I suddenly have a deep love for stored procedures<br />now with stored procedures!<br />
$db->system->js->insert({<br />    "_id" => "x",<br />    "value" => 3});<br />$db->system->js->insert({<br />    "_id" =>...
my $log = <<<LOG<br />function(msg, level) {<br />var date = "[" + new Date() + "] ";<br />varlvl = level ? level+" " : ""...
$db->eval("log('all your base are<br />  belong to us', 'FATAL');");<br />
$db->eval("log('all your base are<br />  belong to us', 'FATAL');");<br />[Fri May 19 18:34:57] FATAL all your<br />   bas...
J<br />J<br />J<br />J<br />J<br />J<br />J<br />J<br />J<br />
$metadata = {<br />    "_id" => "  " <br />    "date" => DateTime->now<br />    "downloads" => 0,<br />    "user" => $user...
$grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />
$grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />$file = $grid->find_one({<br /> "filename" => qr/rickroll/i...
$grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />$file = $grid->find_one({<br />  "filename" => qr/rickroll/...
Benefits:<br /><ul><li> Automatic backups
Unlimited metadata
Millions of files per directory
Random access
Better disk locality</li></li></ul><li>Geospatial Indexes<br />
$coll->insert({location => (-40, 78)});<br />
$coll->insert({location => (-40, 78)});<br />$coll->find({location => { <br />    '$near' => (-40, 77)}})<br />
$coll->insert({location => (-40, 78)});<br />$coll->find({location => { <br />    '$near' => (-40, 77)}})->limit(10)<br />
what doesn't it have?<br />
transactions<br />
are you practicing safe<br />data storage?<br />
Insert this.<br />Okay, got it.<br />Phew, my data's safe.<br />
Write this to disk<br />I know better than he does, I'll just let this sit in a buffer for a while.<br />All over it!<br />
?<br />I have no idea what you're talking about.<br />
trust no one!<br />...trust a bunch of ones.  Mostly.<br />
prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
prod2.example.com<br />prod1.example.com<br />
prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />?<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
?<br />prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
prod1.example.com<br />prod2.example.com<br />
primary<br />secondary<br />secondary<br />passive<br />
okay<br />
?<br />
make sure two slaves have this<br />
all set<br />
EXCEPTION<br />
EXCEPTION<br />
EXCEPTION<br />
$conn->w(3);<br />$collection->insert({"x" => 1},<br />  {"safe" => 1});<br />
scaling<br />
sometimes read-only<br />
sometimes read-only<br />sometimes inconsistent<br />
U - Z<br />K - O<br />A - E<br />F - J<br />P - T<br />
Upcoming SlideShare
Loading in...5
×

Dropping ACID with MongoDB

7,665

Published on

http://yapc2010.com/yn2010/talk/2578

Published in: Technology
1 Comment
14 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,665
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
82
Comments
1
Likes
14
Embeds 0
No embeds

No notes for slide
  • MongoDB is fast for especially k/v pair lookupFast inserts - send-and-forgetIn-place updates
  • MongoDB is fast for especially k/v pair lookupFast inserts - send-and-forgetIn-place updates
  • MongoDB is document oriented
  • Read performance
  • Transcript of "Dropping ACID with MongoDB"

    1. 1.
    2. 2. Who am I?<br />
    3. 3. what is<br />?<br />
    4. 4. Application<br />Perl<br />Apache<br />Linux<br />
    5. 5. Application<br />Perl<br />Database<br />Apache<br />Linux<br />
    6. 6. Application<br />Perl<br />Apache<br />Windows<br />
    7. 7. Application<br />Perl<br />Apache<br />Linux<br />
    8. 8. Application<br />Perl<br />Apache<br />Linux<br />
    9. 9. Application<br />Perl<br />Apache<br />Linux<br />
    10. 10. Application<br />The world's most<br />popular open source<br />database<br />Perl<br />Apache<br />Linux<br />
    11. 11. Application<br />Perl<br />Apache<br />Linux<br />The world's most<br />advanced open source<br />database<br />
    12. 12.
    13. 13. databases<br />contain tables <br />contain rows<br />
    14. 14. schema<br />databases<br />contain tables <br />contain rows<br />
    15. 15. schema<br />databases<br />contain tables <br />contain rows<br />joins<br />
    16. 16. schema<br />databases<br />contain tables <br />contain rows<br />joins<br />
    17. 17.
    18. 18.
    19. 19.
    20. 20.
    21. 21. Application<br />Perl<br />Apache<br />Linux<br />
    22. 22. getting started<br />
    23. 23. www.mongodb.org<br />
    24. 24. cpan -i MongoDB<br />
    25. 25. $conn = MongoDB::Connection->new;<br />
    26. 26. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />
    27. 27. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />NO ADMINISTRATION<br />
    28. 28. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$table = $db->bar;<br />
    29. 29. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$table = $db->bar;<br />
    30. 30. server<br />
    31. 31. server<br />databases<br />
    32. 32. server<br />databases<br />contain tables <br />
    33. 33. server<br />databases<br />contain tables <br />
    34. 34. server<br />databases<br />collections<br />contain tables <br />
    35. 35. server<br />databases<br />collections<br />contain tables <br />contain rows<br />
    36. 36. server<br />databases<br />collections<br />contain tables <br />contain rows<br />
    37. 37. server<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />
    38. 38. server<br />schema<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />
    39. 39. server<br />schema<br />databases<br />collections<br />contain tables <br />documents<br />contain rows<br />joins<br />
    40. 40. server<br />databases<br />contain collections <br />contain documents<br />
    41. 41. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$collection = $db->bar;<br />
    42. 42. $conn = MongoDB::Connection->new;<br />$db = $conn->foo;<br />$collection = $db->bar;<br />NO ADMINISTRATION<br />
    43. 43. $conn = MongoDB::Connection->new;<br />$db = $conn->foo<br />$collection = $db->bar;<br />$doc = {"name" => "kristina",<br /> "contact info" => {<br /> "twitter" => "@kchodorow",<br /> "email" => "kristina@10gen.com"<br /> },<br /> "friends" => 400232,<br /> "pic" => $file_str,<br /> "member since" => DateTime->now};<br />
    44. 44. $conn = MongoDB::Connection->new;<br />$db = $conn->foo<br />$collection = $db->bar;<br />$doc = {"name" => "kristina",<br /> "contact info" => {<br /> "twitter" => "@kchodorow",<br /> "email" => "kristina@10gen.com"<br /> },<br /> "friends" => 400232,<br /> "pic" => $file_str,<br /> "member since" => DateTime->now};<br />$collection->insert($doc);<br />
    45. 45. mongo is type-sensitive <br />and type-rich<br />
    46. 46. <ul><li>null
    47. 47. boolean
    48. 48. integer
    49. 49. double
    50. 50. string
    51. 51. array
    52. 52. hash
    53. 53. qr/fobar/i
    54. 54. $bindata
    55. 55. DateTime
    56. 56. MongoDB::OID
    57. 57. MongoDB::Code
    58. 58. MongoDB::MinKey
    59. 59. MongoDB::MaxKey</li></li></ul><li>$collection->find_one({<br /> "name" => "kristina"});<br />
    60. 60. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />
    61. 61. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />$collection->find({<br /> "member since" => {<br /> '$gt' => $yesterday,<br /> '$lt' => $now<br />}});<br />
    62. 62. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />$collection->find({<br /> "member since" => {<br /> '$gt' => $yesterday,<br /> '$lt' => $now<br />}})->sort({"friends" => 1});<br />
    63. 63. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />$collection->find({<br /> "member since" => {<br /> '$gt' => $yesterday,<br /> '$lt' => $now<br />}})->sort({"friends" => 1})->limit(10);<br />
    64. 64. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />$collection->find({<br /> "member since" => {<br /> '$gt' => $yesterday,<br /> '$lt' => $now<br />}})->sort({"friends" => 1})->limit(10)<br /> ->skip(100);<br />
    65. 65. $collection->find_one({<br /> "name" => "kristina"});<br />$collection->find_one({<br /> "contact.twitter" => "@kchodorow"});<br />$cursor = $collection->find({<br /> "member since" => {<br /> '$gt' => $yesterday,<br /> '$lt' => $now<br />}})->sort({"friends" => 1})->limit(10)<br /> ->skip(100);<br />
    66. 66. while (my $doc = $cursor->next) {<br /> # ... <br />}<br />my @results = $cursor->all;<br />
    67. 67. x < 3<br />{"x" => {'$lt' => 3}}<br />
    68. 68. $gt<br />$lte<br />$ne<br />$mod<br />$exists<br />$type<br />...<br />
    69. 69. $collection->update(<br /> {"name" => "kristina"},<br />
    70. 70. $collection->update(<br /> {"name" => "kristina"},<br /> {'$set' => <br />
    71. 71. $collection->update(<br /> {"name" => "kristina"},<br /> {'$set' => <br /> {"contact.website" => <br /> "snailinaturtleneck.com"<br />}});<br />
    72. 72. updates are...<br /><ul><li>atomic
    73. 73. in-place (when possible)
    74. 74. able to create and delete fields
    75. 75. able to create documents</li></li></ul><li>$collection->update(<br /> {"url" => "example.com"},<br /> {'$inc' => {"pageviews" => 1}},<br /> {"upsert" => 1}<br />);<br />
    76. 76.
    77. 77.
    78. 78. $set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
    79. 79. $set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
    80. 80. $set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
    81. 81. $set<br />$inc<br />$push<br />$pop<br />$pull<br />...<br />
    82. 82. "$gte"<br />
    83. 83. "<null>"<br />
    84. 84. ""<br />
    85. 85. '$gte' or "$gte"<br />
    86. 86. Or define your own!<br />":gte"<br />"=gte"<br />"?gte"<br />
    87. 87. Or define your own!<br />" gte"<br />
    88. 88. Or define your own!<br />" gte"<br />" ♕ gte"<br />
    89. 89. Or define your own!<br />" gte"<br />" ♕ gte"<br />"xgte"<br />
    90. 90. features<br />
    91. 91. I suddenly have a deep love for stored procedures<br />
    92. 92. I suddenly have a deep love for stored procedures<br />now with stored procedures!<br />
    93. 93. $db->system->js->insert({<br /> "_id" => "x",<br /> "value" => 3});<br />$db->system->js->insert({<br /> "_id" => "y",<br /> "value" => 4});<br />$db->eval("return x+y");<br />
    94. 94. my $log = <<<LOG<br />function(msg, level) {<br />var date = "[" + new Date() + "] ";<br />varlvl = level ? level+" " : "";<br /> print(date + lvl + msg);<br />}<br />LOG;<br />$db->system->js->insert({<br /> "_id" => "log",<br /> "value" => $log});<br />
    95. 95. $db->eval("log('all your base are<br /> belong to us', 'FATAL');");<br />
    96. 96. $db->eval("log('all your base are<br /> belong to us', 'FATAL');");<br />[Fri May 19 18:34:57] FATAL all your<br /> base are belong to us<br />
    97. 97.
    98. 98.
    99. 99. J<br />J<br />J<br />J<br />J<br />J<br />J<br />J<br />J<br />
    100. 100.
    101. 101. $metadata = {<br /> "_id" => " " <br /> "date" => DateTime->now<br /> "downloads" => 0,<br /> "user" => $userId,<br /> "filename" => "rickroll.flv"<br />}<br />J<br />
    102. 102. $grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />
    103. 103. $grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />$file = $grid->find_one({<br /> "filename" => qr/rickroll/i<br />});<br />
    104. 104. $grid = $db->get_gridfs;<br />$grid->put($fh, $metadata);<br />$file = $grid->find_one({<br /> "filename" => qr/rickroll/i<br />});<br />$file->print($fh2);<br />
    105. 105. Benefits:<br /><ul><li> Automatic backups
    106. 106. Unlimited metadata
    107. 107. Millions of files per directory
    108. 108. Random access
    109. 109. Better disk locality</li></li></ul><li>Geospatial Indexes<br />
    110. 110.
    111. 111. $coll->insert({location => (-40, 78)});<br />
    112. 112. $coll->insert({location => (-40, 78)});<br />$coll->find({location => { <br /> '$near' => (-40, 77)}})<br />
    113. 113. $coll->insert({location => (-40, 78)});<br />$coll->find({location => { <br /> '$near' => (-40, 77)}})->limit(10)<br />
    114. 114. what doesn't it have?<br />
    115. 115. transactions<br />
    116. 116. are you practicing safe<br />data storage?<br />
    117. 117.
    118. 118. Insert this.<br />Okay, got it.<br />Phew, my data's safe.<br />
    119. 119. Write this to disk<br />I know better than he does, I'll just let this sit in a buffer for a while.<br />All over it!<br />
    120. 120.
    121. 121. ?<br />I have no idea what you're talking about.<br />
    122. 122. trust no one!<br />...trust a bunch of ones. Mostly.<br />
    123. 123. prod1.example.com<br />prod2.example.com<br />
    124. 124. prod1.example.com<br />prod2.example.com<br />
    125. 125. prod1.example.com<br />prod2.example.com<br />
    126. 126. prod2.example.com<br />prod1.example.com<br />
    127. 127.
    128. 128. prod1.example.com<br />prod2.example.com<br />
    129. 129. prod1.example.com<br />prod2.example.com<br />
    130. 130. prod1.example.com<br />?<br />prod2.example.com<br />
    131. 131. prod1.example.com<br />prod2.example.com<br />
    132. 132. ?<br />prod1.example.com<br />prod2.example.com<br />
    133. 133. prod1.example.com<br />prod2.example.com<br />
    134. 134. prod1.example.com<br />prod2.example.com<br />
    135. 135. primary<br />secondary<br />secondary<br />passive<br />
    136. 136.
    137. 137.
    138. 138.
    139. 139.
    140. 140. okay<br />
    141. 141. ?<br />
    142. 142. make sure two slaves have this<br />
    143. 143.
    144. 144.
    145. 145.
    146. 146. all set<br />
    147. 147.
    148. 148.
    149. 149. EXCEPTION<br />
    150. 150. EXCEPTION<br />
    151. 151. EXCEPTION<br />
    152. 152.
    153. 153. $conn->w(3);<br />$collection->insert({"x" => 1},<br /> {"safe" => 1});<br />
    154. 154. scaling<br />
    155. 155.
    156. 156. sometimes read-only<br />
    157. 157. sometimes read-only<br />sometimes inconsistent<br />
    158. 158. U - Z<br />K - O<br />A - E<br />F - J<br />P - T<br />
    159. 159. U - Z<br />K - O<br />A - E<br />F - J<br />P - T<br />
    160. 160. U - Z<br />K - O<br />A - E<br />F - J<br />P - T<br />
    161. 161.
    162. 162. mongod<br />mongod<br />mongod<br />config<br />mongos<br />
    163. 163. mongod<br />mongod<br />mongod<br />mongos<br />I want posts from April 2009 - June 2009<br />
    164. 164. mongod<br />mongod<br />mongod<br />April and May is on #2. June is on #3.<br />mongos<br />
    165. 165. mongod<br />mongod<br />mongod<br />mongos<br />
    166. 166. mongod<br />mongod<br />mongod<br />mongos<br />
    167. 167. mongod<br />mongod<br />mongod<br />mongos<br />Add this post for <br />March 26, 2010.<br />
    168. 168. mongod<br />mongod<br />mongod<br />#3 hold June 2009-present<br />mongos<br />
    169. 169. mongod<br />mongod<br />mongod<br />config<br />So, what's going on?<br />mongos<br />
    170. 170. mongod<br />mongod<br />mongod<br />config<br />mongos<br />
    171. 171. $conn = MongoDB::Connection->new;<br /># ...<br />
    172. 172.
    173. 173. try.mongodb.org<br />
    174. 174. www.mongodb.org<br />
    175. 175. thank you!<br />@kchodorow<br />http://www.snailinaturtleneck.com<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×