kvsの性能、rdbmsのインデックス、更にmapreduceを併せ持つall-in-one nosql: mongodb

128
1 楽天株式会社 開発部 アーキテクトG 窪田 博昭 | 2012年1月18日 KVSの性能 RDBMSのインデックス 更にMapReduceを併せ持つ All-in-one NoSQL

Upload: rakuten-inc

Post on 24-May-2015

4.423 views

Category:

Technology


4 download

DESCRIPTION

窪田 博昭、楽天株式会社 『Mongo Tokyo 2012』講演資料 Rakuten MongoDBの特徴、それを活かした使い方などを楽天・インフォシークニュースの事例などを通じて紹介します。 また機能、性能の検証結果、運用ノウハウ、弱点!の共有。PHPドライバのパッチなども公開します。

TRANSCRIPT

Page 1: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

1 楽天株式会社 開発部 アーキテクトG 窪田 博昭 | 2012年1月18日

KVSの性能

RDBMSのインデックス

更にMapReduceを併せ持つ

All-in-one NoSQL

Page 2: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

2

• Introduction

• How to use mongo on the news.infoseek.co.jp

Agenda

Introduction

Page 3: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

3

Introduction

Page 4: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

4

Who am I ?

Page 5: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

5

Name: 窪田 博昭 Hiroaki Kubota

Company: Rakuten Inc.

Unit: ACT = Development Unit Architect Group

Mail: [email protected]

Hobby: Futsal , Golf

Recent: My physical power has gradual declined...

twitter : crumbjp

github: crumbjp

Profile

Introduction

Page 6: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

6

How to take advantages of the Mongo

for the infoseek news

Page 7: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

7

For instance of our page

Page 8: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

8

Page structure

Page 9: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

9

Layout / Components

Layout Components

Page 10: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

10

Albatross structure

Internet

WEB

API

ContentsDB MongoDB

ReplSet

Gat page layout

Request LayoutDB

MongoDB

ReplSet Call APIs

Retrieve data

Get components

SessionDB

MongoDB

ReplSet

Memcache

Page 11: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

11

CMS

Developer

Albatross structure

API servers

ContentsDB MongoDB

ReplSet

Set page layout HTML markup

&

API settings

LayoutDB

MongoDB

ReplSet

Deploy API

Set components

Batch servers

Insert Data

Page 12: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

12

CMS

Layout editor

Page 13: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

13

CMS

Page 14: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

14

CMS

Page 15: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

15

MapReduce

Page 16: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

16

We have never used MapReduce as regular operation.

However, We have used it for some irreglar case.

• To search the invalid articles that should be removed because of someone’s mistakes...

• To analyze the number of new articles posted a day.

• To analyze the updated number an article.

• We get start considering to use it regularly for the social data analyzing before long ...

Our usage

MapReduce

Page 17: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

17

Structure & Performance

Page 18: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

18

Structure

• Intel(R) Xeon(R) CPU X5650 2.67GHz 1core!!

• 4GB memory

• 50 GB disk space ( iScsi )

• CentOS5.5 64bit

• mongodb 1.8.0

– ReplicaSet 5 nodes ( + 1 Arbiter)

– Oplog size 1.2GB

– Average object size 1KB

We are using very poor machine (Virtual machine) !!

Page 19: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

19

Structure

We’ve also researched following environments...

• Virtual machine 1 core

– 1kb data , 6,000,000 documents

– 8kb data , 200,000 documents

• Virtual machine 3 core

– 1kb data , 6,000,000 documents

– 8kb data , 200,000 documents

• EC2 large instance

– 2kb data , 60,000,000 documents. ( 100GB )

Researched environment

Page 20: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

20

Performance

1~8 kb documents + 1 unique index

C = Number of CPU cores (Xeon 2.67 GHz)

DD = Score of ‘dd’ command (byte/sec)

S = Document size (byte)

• GET qps = 4500 × C

• SET(fsync) bytes/s = 0.05×DD ÷ S

• SET(nsync) qps = 4500 BUT...

have chance of STALE

I found the formula for making a rough estimation of QPS

Page 21: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

21

Performance example (on EC2 large)

Page 22: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

22

Performance example (on EC2 large)

Data-type

{

shop: 'someone',

item: 'something',

description: 'item explanation sentences...‘

}

EC2 large instance

– 2kb data , 60,000,000 documents. ( 100GB )

– 1 unique index

Environment and amount of data

Page 23: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

23

Performance example (on EC2 large)

Batch insert (1000 documents) fsync=true

17906 sec (=289 min) (=3358 docs/sec)

Ensure index (background=false)

4049 sec (=67min)

1. primary 2101 sec (=35min)

2. secondary 1948 sec (=32min)

Page 24: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

24

Performance example (on EC2 large)

Add one node

5833sec (=97min)

1. Get files 2GB×48 2120 sec (=35min)

2. _id indexing 1406 sec (=23min)

3. uniq indexing 2251 sec (=38min)

4. other processes 56 sec (=1 min)

Page 25: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

25

Performance example (on EC2 large)

Group by

• Reduce by unique index & map & reduce

– 368 msec

db.data.group({ key: { shop: 1},

cond: { shop: 'someone' },

reduce: function ( o , p ) { p.sum++; },

initial: { sum: 0 } });

Page 26: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

26

Performance example (on EC2 large)

MapReduce

• Scan all data 3116sec (=52min)

– number of key = 39092

db.data.mapReduce(

function(){ emit(this.shop,1); },

function(k,v){

var ret=0;

v.forEach( function (value){ ret+=value; });

return ret; },

{ query: {}, inline: 1, out: 'Tmp' } );

Page 27: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

27

Major problems...

Page 28: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

28

Indexing

Page 29: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

29

Index probrem

Indexing is lock operation in default.

Indexing operation can run as background

on the primary. But...

It CANNOT run as background on the secondary

Moreover the all secondary’s indexing run

at the same time !!

Result in above...

All slave freezes ! orz...

Online indexisng is completely useless even if last version (2.0.2)

Page 30: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

30

Present indexing ( default )

Page 31: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

31

Index probrem

Present indexing ( default )

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary save

Page 32: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

32

Index probrem

Present indexing ( default )

ensureIndex Primary

Lock

Indexing

Secondary

Secondary Secondary

Client Client Client Client Client

Batch Cannot write

Page 33: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

33

Index probrem

Present indexing ( default )

Cannot read !!

SYNC SYNC SYNC

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Client Client Client Client Client

Primary

Complete Batch

finished

Page 34: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

34

Index probrem

Ideal indexing ( default )

Secondary

Complete

Secondary

Complete

Secondary

Complete

Client Client Client Client Client

Primary

Complete Batch

Page 35: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

35

Present indexing ( background )

Page 36: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

36

Index probrem

Present indexing ( background )

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary save

Page 37: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

37

Index probrem

Present indexing ( background )

Primary

Slowdown

Indexing

Secondary

Secondary Secondary

Client Client Client Client Client

Batch ensureIndex(background) Slow down...

Page 38: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

38

Index probrem

Present indexing ( background )

Cannot read !!

SYNC SYNC SYNC

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Client Client Client Client Client

Primary

Complete Batch

finished

Page 39: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

39

Index probrem

Present indexing ( background )

Cannot read !!

SYNC SYNC SYNC

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Client Client Client Client Client

Primary

Complete Batch

finished

Background indexing don’t work

on the secondaries

Page 40: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

40

Index probrem

Present indexing ( background )

Cannot read !!

SYNC SYNC SYNC

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Secondary

Lock

Indexing

Client Client Client Client Client

Primary

Complete Batch

finished

Page 41: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

41

Index probrem

Ideal indexing ( background )

Secondary

Complete

Secondary

Complete

Secondary

Complete

Client Client Client Client Client

Primary

Complete Batch

Page 42: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

42

Probable 2.1.X indexing

Page 43: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

43

Index probrem

But not released formally.

So I checked out the source code up to date.

Certainlly it’ll be fixed !

Moreover it sounds like it’ll run as foreground

when slave status isn’t SECONDARY

(it means RECOVERING )

Accoding to mongodb.org this probrem will fix in 2.1.0

Page 44: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

44

Index probrem

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary save

Probable 2.1.X indexing

Page 45: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

45

Index probrem

Probable 2.1.X indexing

Secondary

Secondary Secondary

ensureIndex(background)

Client Client Client Client Client

Batch

Primary

Slowdown

Indexing

Slow down...

Page 46: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

46

SYNC

Index probrem

Slow down...

SYNC SYNC

Secondary

Slowdown

Indexing

Secondary

Slowdown

Indexing

Secondary

Slowdown

Indexing

Probable 2.1.X indexing

Client Client Client Client Client

Primary

Complete Batch

finished

Page 47: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

47

Index probrem

Secondary

Complete

Secondary

Complete

Secondary

Complete

Client Client Client Client Client

Primary

Complete

Probable 2.1.X indexing

Batch

Page 48: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

48

Index probrem

But I think it’s not enough.

I think it can be fatal for the system that

the all secondaries slowdown at the same time !!

So...

Background indexing 2.1.X

Page 49: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

49

Ideal indexing

Page 50: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

50

Index probrem

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary save

Ideal indexing

Page 51: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

51

Index probrem

Ideal indexing

Secondary

Secondary Secondary

ensureIndex(background)

Client Client Client Client Client

Batch

Primary

Slowdown

Indexing

Slow down...

Page 52: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

52

Index probrem

Ideal indexing

ensureIndex

Recovering

Indexing

Secondary

Secondary

Client Client Client Client Client

finished Primary

Complete Batch

Page 53: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

53

Index probrem

Ideal indexing

ensureIndex

Secondary

Complete

Recovering

Indexing

Secondary

Client Client Client Client Client

Batch

Primary

Complete

Page 54: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

54

Index probrem

Ideal indexing

ensureIndex

Secondary

Complete

Secondary

Complete

Recovering

Indexing

Client Client Client Client Client

Batch

Primary

Complete

Page 55: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

55

Index probrem

Ideal indexing

Secondary

Complete

Secondary

Complete

Secondary

Complete

Client Client Client Client Client

Primary

Complete Batch

Page 56: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

56

Index probrem

It would be great if I can operate indexing manually

at each secondaries

But ... I easilly guess it’s difficult to apply for current Oplog

Page 57: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

57

I suggest Manual indexing

Page 58: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

58

Index probrem

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary save

Manual indexing

Page 59: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

59

Index probrem

Manual indexing

Secondary

Secondary Secondary

Client Client Client Client Client

Batch

Primary

Slowdown

Indexing

Slow down... ensureIndex(manual,background)

Page 60: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

60

Index probrem

Manual indexing

finished Primary

Complete Batch

Secondary

Secondary

Secondary

Client Client Client Client Client

Page 61: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

61

Index probrem

Manual indexing

finished Primary

Complete Batch

Secondary

Secondary

Secondary

Client Client Client Client Client

The secondaries don’t sync

automatically

Page 62: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

62

Index probrem

Manual indexing

finished Primary

Complete Batch

Secondary

Secondary

Secondary

Client Client Client Client Client

Page 63: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

63

Index probrem

Manual indexing

Recovering

Indexing

Secondary

Secondary

Client Client Client Client Client

ensureIndex(manual)

Primary

Complete Batch

Page 64: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

64

Index probrem

Manual indexing

Secondary

Complete

Recovering

Indexing

Secondary

Client Client Client Client Client

ensureIndex(manual)

Primary

Complete Batch

Page 65: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

65

Index probrem

Manual indexing

Secondary

Complete

Secondary

Complete

Secondary

Slowdown

Indexing

Client Client Client Client Client

ensureIndex(manual,background)

Primary

Complete Batch

Page 66: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

66

Index probrem

Manual indexing

Secondary

Complete

Secondary

Complete

Secondary

Slowdown

Indexing

Client Client Client Client Client

ensureIndex(manual,background)

Primary

Complete Batch

It needs to support

background operation

Just in case,if the ReplSet has only

one Secondary

Page 67: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

67

Index probrem

Manual indexing

Secondary

Complete

Secondary

Complete

Secondary

Slowdown

Indexing

Client Client Client Client Client

ensureIndex(manual,background)

Primary

Complete Batch

Page 68: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

68

Index probrem

Manual indexing

Secondary

Complete

Secondary

Complete

Secondary

Complete

Client Client Client Client Client

Primary

Complete Batch

Page 69: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

69

That’s all about Indexing problem

Page 70: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

70

Struggle to control the sync

Page 71: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

71

STALE

Page 72: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

72

Unknown log & Out of control the ReplSet

• Secondaries change status repeatedly in a moment

between Secondary and Recovering (1.8.0)

• Then we found the strange line in the log...

[rsSync] replSet error RS102 too stale to catch up

We often suffered from going out of control the Secondaries...

Page 73: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

73

What’s Stale ?

• 〈食品・飲料などが〉新鮮でない(⇔fresh);

• 気の抜けた, 〈コーヒーが〉香りの抜けた,

• 〈パンが〉ひからびた, 堅くなった,

• 〈空気・臭(にお)いなどが〉むっとする,

• いやな臭いのする

stale [stéil] (レベル:社会人必須 ) powered by goo.ne.jp

Page 74: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

74

What’s Stale ?

• 〈食品・飲料などが〉新鮮でない(⇔fresh);

• 気の抜けた, 〈コーヒーが〉香りの抜けた,

• 〈パンが〉ひからびた, 堅くなった,

• 〈空気・臭(にお)いなどが〉むっとする,

• いやな臭いのする

どうも非常によろしくないらしい・・・

stale [stéil] (レベル:社会人必須 ) powered by goo.ne.jp

Page 75: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

75

Mechanizm of being stale

Page 76: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

76

ReplicaSet

Primary

Database Oplog

Client

Secondary

Database

mongod mongod

Oplog

Page 77: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

77

Replication (simple case)

Page 78: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

78

ReplicaSet

Primary

Database Oplog

Client

Secondary

Database

mongod mongod

Oplog

Page 79: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

79

Insert & Replication 1

Primary

Database Oplog

Client

Secondary

Database

Insert A

A

A

Insert

mongod mongod

Oplog

Page 80: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

80

Insert & Replication 1

Primary

Database Oplog

Client

Secondary

Database

Insert A

A A

Oplog

Insert A

Sync

Page 81: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

81

Replication (busy case)

Page 82: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

82

Stale

Primary

Database Oplog

Client

Secondary

Database

Insert A

A A

Oplog

Insert A

mongod mongod

Page 83: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

83

Insert & Replication 2

Primary

Database Oplog

Client

Secondary

Database

Insert A

B

A

Insert

B

Insert B

A

Oplog

Insert A

Page 84: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

84

Insert & Replication 2

Primary

Database Oplog

Client

Secondary

Database

Insert A

C

A

Insert

B

Insert B

A

C

Insert C

Oplog

Insert A

Page 85: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

85

Insert & Replication 2

Primary

Database Oplog

Client

Secondary

Database

Insert A

A

A

Update

B

Insert B

A

C

Insert C

Update A

Oplog

Insert A

Page 86: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

86

Insert & Replication 2

Primary

Database Oplog

Client

Secondary

Database

Insert A

A

B

Insert B

A

C

Insert C

Update A

Oplog

Insert A

Check Oplog

Page 87: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

87

Insert & Replication 2

Primary

Database Oplog

Client

Secondary

Database

Insert A

A

B

Insert B C

Insert C

Update A

Oplog

Insert A

Sync

Insert B

Insert C

Update A

A

B

C

Page 88: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

88

Replication (more busy)

Page 89: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

89

Stale

Primary

Database Oplog

Client

Secondary

Database

Insert A

A A

Oplog

Insert A

mongod mongod

Page 90: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

90

Stale

Primary

Database Oplog

Client

Secondary

Database

Insert A

B

A

Insert

B

Insert B

A

Oplog

Insert A

Page 91: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

91

Stale

Primary

Database Oplog

Client

Secondary

Database

Insert A

C

A

Insert

B

Insert B

A

C

Insert C

Oplog

Insert A

Page 92: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

92

Stale

Primary

Database Oplog

Client

Secondary

Database

Insert A

A

A

Update

B

Insert B

A

C

Insert C

Update A

Oplog

Insert A

Page 93: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

93

Stale

Primary

Database

Client

Secondary

Database

C

A

Update

B

A

C

Oplog

Insert A

Oplog

Insert A

Insert B

Insert C

Update A

Update C

Page 94: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

94

Stale

Primary

Database

Client

Secondary

Database

D

A

Insert

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Page 95: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

95

Stale

Primary

Database

Client

Secondary

Database

A

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Check Oplog

[Inset A]

not found !!

Insert A

Page 96: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

96

Stale

Primary

Database

Client

Recovering

Database

A

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Check Oplog

[Inset A]

not found !!

It cannot get

infomation about

[Insert B].

So cannot sync !!

It’s called STALE Insert A

Page 97: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

97

Stale

We can specify the oplog size as one of the command line option

Only at the first time per the dbpath

that is also specified as a command line.

Also we cannot change the oplog size

without clearing the dbpath.

Be careful !

We have to understand the importance of adjusting oplog size

Page 98: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

98

Replication (Join as a new node)

Page 99: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

99

InitialSync

Primary

Database

Client

A

B

C

D

Oplog

Insert C

Update A

Update C

Insert D

mongod

Page 100: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

100

InitialSync

Primary

Database

Client

Startup

Database

A

B

C

Oplog

D

Oplog

Insert C

Update A

Update C

Insert D

mongod mongod

Page 101: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

101

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Insert C

Update A

Update C

Insert D

Get last Oplog

Insert D

Page 102: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

102

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Insert C

Update A

Update C

Insert D

Cloning DB

Insert D

A

B

C

D

Page 103: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

103

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Insert C

Update A

Update C

Insert D

Cloning DB

Insert D A

A

B

C

D

Page 104: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

104

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Insert C

Update A

Update C

Insert D

Cloning DB

Insert D A

A

B

C

D E

Insert

E Insert E

B

Page 105: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

105

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Update A

Update C

Insert D

Cloning DB complete

Insert D

A

B

C

D

B

Update

E

Insert E

Update B

Page 106: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

106

InitialSync

Primary

Database

Client

Recovering

Database

A

B

C

Oplog

D

Oplog

Update C

Insert D

Check Oplog

Insert D

A

B

C

D

E

Insert E

Update B

Page 107: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

107

InitialSync

Primary

Database

Client

Secondary

Database

A

B

C

Oplog

D

Oplog

Update C

Insert D

Sync

Insert D

E

Insert E

Update B

Insert E

Update B

A

B

C

D

E

Page 108: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

108

Additional infomation

Secondary will try to sync from other Secondaries

when it cannot reach the Primary or

might be stale against the Primary.

There is a bit of chance that sync problem not occured if the

secondary has old Oplog or larger Oplog space than Primary

From source code. ( I’ve never examed these... )

Page 109: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

109

Sync from another secondary

Primary

Database

Client

Secondary

Database

A

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Secondary

Database

A

B

C

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Page 110: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

110

Sync from another secondary

Primary

Database

Client

Secondary

Database

A

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Secondary

Database

A

B

C

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Check Oplog

[Inset A]

not found !!

Page 111: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

111

Sync from another secondary

Primary

Database

Client

Secondary

Database

A

B

A

C

Oplog

Insert A

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Secondary

Database

A

B

C

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Check Oplog

But found at the other secondary

So it’s able to sync

Page 112: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

112

Sync from the other secondary

Primary

Database

Client

Secondary

A

B

C

D

Insert C

Update A

Update C

Insert D

Secondary

Database

A

B

C

D

Insert B

Insert C

Update A

Update C

Insert D

Insert A

Sync

But found at the other secondary

So it’s able to sync

Database

A

B

C

D

Insert C

Update A

Update C

Insert D

Insert B

Insert A

Insert B

Insert A

Page 113: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

113

That’s all about sync

Page 114: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

114

Others...

Page 115: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

115

Disk space

Page 116: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

116

Disk space

Data fragment into any DB files sparsely...

We met the unfavorable circumstance in our DBs

This circumstance appears at some of our collections

around 3 months after we launched the services

db.ourcol.storageSize() = 16200727264 (15GB)

db.ourcol.totalSize() = 16200809184

db.ourcol.totalIndexSize() = 81920

db.outcol.dataSize() = 2032300 (2MB)

What’s happen to them !!

Page 117: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

117

Disk space

Data fragment into any DB files sparsely...

It’s seems like to be caused by the specific operation

that insert , update and delete over and over.

Anyway we have to shrink the using disk space regularly

just like PostgreSQL’s vacume.

But how to do it ?

Page 118: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

118

Disk space

Shrink the using disk spaces

MongoDB offers some functions for this case.

But couldn’t use in our case !

repairdatabase:

Only runable on the Primary.

It needs long time and BLOCK all operations !!

compact:

Only runable on the Secondary.

Zero-fill the blank space instead of shrink disk spaces.

So cannot shrink...

Page 119: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

119

Disk space

Our measurements

For temporary collection:

To issue drop-command regularly.

For other collections:

1. Get rid of one secondary from the ReplSet.

2. Shut down this.

3. Remove all DB files.

4. Join to the ReplSet.

5. Do these operations one after another.

6. Step down the Primary. (Change Primary node)

7. At last, do 1 – 4 operations on prior Primary.

Page 120: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

120

PHP client

Page 121: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

121

PHP client

We tried 1.4.4 and 1.2.2

1.4.4:

There is some critical bugs around connection pool.

We struggled to invalidate the broken connection.

I think, you should use 1.2.X instead of 1.4.X

1.2.2:

It seems like to be fixed around connection pool.

But there are 2 critical bugs !

– Socket handle leak

– Useless sleep

However, This version is relatively stable

as long as to fix these bugs

Page 122: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

122

PHP client

We tried 1.4.4 and 1.2.2

https://github.com/crumbjp/Personal

- mongo1.2.2.non-wait.patch

- mongo1.2.2.sock-leak.patch

Page 123: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

123

PHP client

Page 124: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

124

Closing

Page 125: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

125

Closing

What’s MongoDB ?

It has very good READ performance.

We can use mongo instead of memcached.

if we can allow the limited write performance.

Die hard !

MongoDB have high availability even if under a severe stress..

Can use easilly without deep consideration

We can manage to do anything after getting start to use.

Let’s forget any awkward trivial things that have bothered us.

How to treat the huge data ?

How to put in the cache system ?

How to keep the availablity ?

And so on ....

Page 126: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

126

Closing

Keep in mind

Sharding is challenging...

It’s last resort !

It’s hard to operate. In particular, to maintain config-servers.

[Mongos] is also difficult to keep alive.

I want the way to failover Mongos.

Mongo is able to run on the poor environment but...

You should ONLY put aside the large diskspace

Huge write is sensitive

Adjust the oplog size carefully

Indexing function has been unfinished

Cannot apply index online

Page 127: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

127

All right, Have fun !!

Page 128: KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB

128

Thank you for your listening