Slide 1

Slide 1 text

Ordered List John Nunemaker MongoChi 2011 October 18, 2011 MongoDB for Analytics A loving conversation with @jnunemaker

Slide 2

Slide 2 text

Background As presented through interpretive dance

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

~1 month Of evenings and weekends

Slide 7

Slide 7 text

~4 dog years Since public launch

Slide 8

Slide 8 text

~6 tiny servers 2 web, 2 app, 2 db

Slide 9

Slide 9 text

~1-2 Million Page views per day

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Implementation Imma show you how we do what we do baby

Slide 13

Slide 13 text

Doing It Live No aggregate querying

Slide 14

Slide 14 text

get('/track.gif') do Hit.record(...) TrackGif end

Slide 15

Slide 15 text

class Hit def record site.atomic_update(site_updates) Resolution.record(self) Technology.record(self) Location.record(self) Referrer.record(self) Content.record(self) Search.record(self) Notification.record(self) View.record(self) end end

Slide 16

Slide 16 text

class Resolution def record(hit) query = {'_id' => "..."} update = {'$inc' => {}} update['$inc']["sx.#{hit.screenx}"] = 1 update['$inc']["bx.#{hit.browserx}"] = 1 update['$inc']["by.#{hit.browsery}"] = 1 collection(hit.created_on) .update(query, update, :upsert => true) end end end

Slide 17

Slide 17 text

Pros

Slide 18

Slide 18 text

Pros Space

Slide 19

Slide 19 text

Pros Space RAM

Slide 20

Slide 20 text

Pros Space RAM Reads

Slide 21

Slide 21 text

Pros Space RAM Reads Live

Slide 22

Slide 22 text

Cons

Slide 23

Slide 23 text

Cons Writes

Slide 24

Slide 24 text

Cons Writes Constraints

Slide 25

Slide 25 text

Cons Writes Constraints More Forethought

Slide 26

Slide 26 text

Cons Writes Constraints More Forethought No raw data

Slide 27

Slide 27 text

Time Frame Minute, hour, month, day, year, forever?

Slide 28

Slide 28 text

# of Variations One document vs many

Slide 29

Slide 29 text

Single Document Per Time Frame

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

{ "t" => 336381, "u" => 158951, "2011" => { "02" => { "18" => { "t" => 9, "u" => 6 } } } }

Slide 32

Slide 32 text

{ '$inc' => { 't' => 1, 'u' => 1, '2011.02.18.t' => 1, '2011.02.18.u' => 1, } }

Slide 33

Slide 33 text

Single Document For all ranges in time frame

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

{ "_id" =>"...:10", "bx" => { "320" => 85, "480" => 318, "800" => 1938, "1024" => 5033, "1280" => 6288, "1440" => 2323, "1600" => 3817, "2000" => 137 }, "by" => { "480" => 2205, "600" => 7359,

Slide 36

Slide 36 text

"600" => 7359, "768" => 4515, "900" => 3833, "1024" => 2026 }, "sx" => { "320" => 191, "480" => 179, "800" => 195, "1024" => 1059, "1280" => 5861, "1440" => 3533, "1600" => 7675, "2000" => 1279 } }

Slide 37

Slide 37 text

{ '$inc' => { 'sx.1440' => 1, 'bx.1280' => 1, 'by.768' => 1, } }

Slide 38

Slide 38 text

Many Documents Search terms, content, referrers...

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

[ { "_id" => ":", "t" => "ruby class variables", "sid" => BSON::ObjectId(''), "v" => 352 }, { "_id" => ":", "t" => "ruby unless", "sid" => BSON::ObjectId(''), "v" => 347 }, ]

Slide 41

Slide 41 text

Writes {'_id' => "#{site_id}:#{hash}"}

Slide 42

Slide 42 text

Reads [['sid', 1], ['v', -1]]

Slide 43

Slide 43 text

Growth The best laid plans of mice and men

Slide 44

Slide 44 text

Partition Hot Data Currently using collections for time frames

Slide 45

Slide 45 text

Bigger, Faster Server More CPU, RAM, Disk Space

Slide 46

Slide 46 text

Users Sites Content Referrers Terms Engines Resolutions Locations Users Sites Content Referrers Terms Engines Resolutions Locations

Slide 47

Slide 47 text

Partition by Function Spread writes across a few servers

Slide 48

Slide 48 text

Users Sites Content Referrers Terms Engines Resolutions Locations

Slide 49

Slide 49 text

Partition by Server Spread writes across a ton of servers, way down the road, not worried yet

Slide 50

Slide 50 text

Ordered List Thank you! [email protected] John Nunemaker MongoChi 2011 October 18, 2011 @jnunemaker