mongodb - egloospds24.egloos.com/pds/201209/02/09/mongodb_20110601b.pdf · 2012-09-01 · 2011년...
TRANSCRIPT
MongoDB 적용사례Daum Communications
미디어개발팀박성인
12011년 7월 6일 수요일
NoSQL
22011년 7월 6일 수요일
Using JavaJava VM, GC
Low Scalability
Using CWrite speed
Auto ShardingHigh Scalability
Using Erlang
Read/Update MapReduce
Cassandra Good Very Good
MongoDB Good Poor but Scalable
R/U MR
Cassandra 153% 112%
MongoDB 145% 211%
32011년 7월 6일 수요일
42011년 7월 6일 수요일
52011년 7월 6일 수요일
MongoDB ?
62011년 7월 6일 수요일
MyAgora
72011년 7월 6일 수요일
2011-01 2011-02 2011-03 2011-04 2011-05 2011-08 2012-01
4,596,4098,445,415
13,605,034
18,925,573
24,350,302
32,445,415
52,445,41560,000K
45,000K
30,000K
15,000K
최신글
0 ... ...
82011년 7월 6일 수요일
Needs NoSQL!!
Legacy의 한계
Too many inserts
Short period
92011년 7월 6일 수요일
Insert Select Update Delete
MySQL 249.39 sec 354.82 sec 316.82 sec 310.37 sec
MongoDB 59.37 sec 293.99 sec 153.39 sec 123.34 sec
1,000,000건 Data Insert/Select/Update/Delete Performance
$mysql->query("ALTER TABLE test ADD INDEX idx_id(id)"); $col->ensureIndex(array("id"=>1))
for($i = 0 ; $i < $limit ; $i++) { $q = "insert into test values($i,'$i')"; $mysql->query($q);}
for($i = 0 ; $i < $limit ; $i++) { $col->insert(array("id"=>$i,"value"=>"$i"));}
for($i = 0 ; $i < $limit ; $i++) { $q = "select * from test where id = $i"; if ($result = $mysql->query($q)) while ($row = $result->fetch_assoc()) {}}
for($i = 0 ; $i < $limit ; $i++) { $c = $col->find(array("id"=>$i))->hint(array("id"=>-1))->limit(1); foreach($c as $a) {}}
for($i = 0 ; $i < $limit ; $i++) { $q = "update test set value = '$i$i' where id = $i"; $mysql->query($q);}
for($i = 0 ; $i < $limit ; $i++) { $col->update(array("id"=>$i), array('$set'=>array("value"=>"$i$i")));}
for($i = 0 ; $i < $limit ; $i++) { $q = "delete from test where id = $i"; $mysql->query($q);}
for($i = 0 ; $i < $limit ; $i++) { $col->remove(array("id"=>$i));}
102011년 7월 6일 수요일
���
��� ��
��
����
��
��
����
My ��
112011년 7월 6일 수요일
MyAgora
���
��� ��
��
����
��
��
�������
��
122011년 7월 6일 수요일
Mongo DB
Mongo DBMongo DB
DiskDisk
MYSQL
MyAgora
Agora
Agent
2011-02-07 205,8742011-02-08 220,9092011-02-09 184,568
132011년 7월 6일 수요일
Backup & Recovery
142011년 7월 6일 수요일
Backup
fsync and lock Data dumping(mongodump)
Shutdownbackup
Data export(mongoexport)
152011년 7월 6일 수요일
Mongo DB
Mongo DBMongo DB
Latest
Daily
Weekly
Monthly
Backup Server
04:00AM
162011년 7월 6일 수요일
All
Master
Backup fileMongorestore
Server 정상화 Slave Server Sync
Master 서버정상화
Slave to Master
Slaves Server 정상화
복구완료
172011년 7월 6일 수요일
Practical Tips
182011년 7월 6일 수요일
Index
Data Modeling
Performance
192011년 7월 6일 수요일
Join
Schemaless
Application
Mashup
RDB Data
202011년 7월 6일 수요일
Index
212011년 7월 6일 수요일
B-tree
1 Query - 1 Index
hint()
Wrong/No index
High disk IO
Need Sharding
Too big indexMemory Size
Compound index
222011년 7월 6일 수요일
find(query).hint(index).limit(1)
findOne(query)
1
10
100
1000
10000
5 / 6.64G 4 / 4.84G 3 / 3.74G 2 / 2.1G 1 / 1.38G
findOne find.hint
5.493
0.032
3.443
0.030
3.494
0.025 0.0300.015
3.970 3.610
Log Scale
232011년 7월 6일 수요일
Performance
242011년 7월 6일 수요일
Connection
Singleton Pattern
Connection Pooling
slaveOk()
252011년 7월 6일 수요일
[ERROR] 2010-11-17 14:19:24 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:253)-Servlet.service() for servlet dispatcher threw exceptioncom.mongodb.MongoInternalException: can't find a master at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:327) at com.mongodb.Mongo.<init>(Mongo.java:215) at com.mongodb.Mongo.<init>(Mongo.java:200)
Caused by: com.mongodb.MongoException$Network: can't call something at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:210) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:208) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:208) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:256) at com.mongodb.DBCollection.findOne(DBCollection.java:467) at com.mongodb.DBCollection.findOne(DBCollection.java:456)
262011년 7월 6일 수요일
private static MongoDBConnection instance = null; private static Mongo m = null;
private MongoDBConnection() { try { List<ServerAddress> mongodbHosts = getMongodbHosts(); if (mongodbHosts.size() == 1) { m = new Mongo(mongodbHosts.get(0)); } else { m = new Mongo(mongodbHosts); } m.slaveOk(); } catch (UnknownHostException e) { e.printStackTrace(); } }
private static List<ServerAddress> getMongodbHosts() throws UnknownHostException { String hostsPop = mongodbProp.getString(KEY_MONGODB_HOSTS); String [] hostsArray = StringUtils.split(hostsPop, ","); String port = getMongodbPort(); List<ServerAddress> hosts = new LinkedList<ServerAddress>(); for (String host : hostsArray) { hosts.add(new ServerAddress(host.concat(":").concat(port))); } return hosts; }
272011년 7월 6일 수요일
CursorTimeout Exception
batchSize
count() vs cursor.size()
count() 0.537 seccursor.size() 0.158 sec
282011년 7월 6일 수요일
$batchSize = 1000;$cursor = $relationshipsCollection->find()->hint();$cursor = $cursor->batchSize($batchSize);
while($cursor->hasNext()){$relationShip = $cursor->getNext();
}
$cursor =$relationshipCollection->find()->limit()->hint();
while($cursor->hasNext()){ $relationShip = $cursor->getNext();}
$cursor->limit(30)->batchSize(7)// if we iterate through 28 items, the next call to getNext() will contact the// database and request a batch of 2 documents
292011년 7월 6일 수요일
Update
update() 0.387 sec
update($set) 0.032 sec
Object update
Reindexing
Atomic update
302011년 7월 6일 수요일
public void updateMy(My my, String intro) { BasicDBObject query = new BasicDBObject(); query.put(KEY_DAUM_ID, my.daumId); query.put(KEY_CP_CODE, my.cpCode); DBCollection col = MongoDBUtil.getProfileCollection(); DBObject dbo = MongoDBUtil.toDB(my); col.update(query , new BasicDBObject("$set", new BasicDBObject("intro", intro)));}
public void updateMy(My my, String intro) { BasicDBObject query = new BasicDBObject(); query.put(KEY_DAUM_ID, my.daumId); query.put(KEY_CP_CODE, my.cpCode);
my.intro = intro; DBObject dbo = MongoDBUtil.toDB(my); DBCollection col = MongoDBUtil.getProfileCollection(); col.update(query, dbo); }
312011년 7월 6일 수요일
Data file
64mb -> 128mb -> 256mb -> 512mb -> 1.0gb -> 2.0gb
1. 현재 Data파일 크기가 30GB라고 가정2. 모든 Data 삭제 => Data파일 크기는 30GB3. Data Insert => If(inserted Data > 30GB) then Data파일 크기 증가
db.repairDatabase()
322011년 7월 6일 수요일
DB Profiling
Slow Query
system.profile
Only latest operations
332011년 7월 6일 수요일
> db.system.profile.find({millis : { $gt : 5 }}){"ts" : "Thu Jan 29 2009 15:21:27 GMT-0500 (EST)" , "info" : "query test.foo ntoreturn:0 exception bytes:53" , "millis" : 88}
Level Setting0 off1 log slow operations2 log all operations
> use admin switched to db admin> db.setProfilingLevel(2);{ "was" : 0, "slowms" : 50, "ok" : 1 }> db.setProfilingLevel(1, 200);{ "was" : 2, "slowms" : 50, "ok" : 1 }
342011년 7월 6일 수요일
Full table scan
mongodb.conf
count()
> db.articles.find({"className":""});error: { "$err" : "table scans not allowed:test.articles", "code" : 10111 }
logpath=/daum/logs/mongodb.loglogappend=truereplSet=mongoset1notablescan=true
Wrong Index
352011년 7월 6일 수요일
OR Mapper
Morphia
@preLoad
@postLoad
@notSaved
(JB)Son <-> Object
362011년 7월 6일 수요일
Tools
372011년 7월 6일 수요일
Rock Mongo
382011년 7월 6일 수요일
Rock Mongo
392011년 7월 6일 수요일
mongostat
402011년 7월 6일 수요일
mongostat
412011년 7월 6일 수요일
MongoDB
CompatibleLight Transaction
Log type data
Area미디어다음 로그분석스포츠 응원방/댓글
MoreData Modeling
Sharding
422011년 7월 6일 수요일
432011년 7월 6일 수요일