SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
50 Tips & Tricks for
  MongoDB Developers
         TIPS: 7~13
           charsyam@naver.com
TIP 7: 미리 만들 수 있는 것은 만들어 놓자.
• Insert 비용 보다 Update 비용이 싸다.
  – 공간 할당이 필요가 없으므로
• 어디에 쓸 것이냐?
  – 통계 페이지 처럼 시간마다 같은 크기에 값만 바뀌는 경우
     • 그런데 적은 용량이면 insert나 update가 큰 차이가 없을듯…
TIP 7: 미리 만들 수 있는 것은 만들어 놓자.
TIP 8: 가능하면 공간을 미리 할당하라.
• Tip 7과 같은 내용
• 미리 만들어두고 당장 안쓰는 정보는 $unset 해 두자.
TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면
            배열에 저장하라.
• 식별자
                abilities.str
                Abilities.con

                식별자를 쓴다는 것은 이름
                을 안다는 것!
TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면
            배열에 저장하라.

                MongoDB 의 특징이
                Schemaless 하므로 다
                양한 아이템을 넣을 수 있
                다.

                하지만 damage가 20이
                넘는 것만 검색하려면?
TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면
            배열에 저장하라.

                배열로 만들어서 검색
TIP 10: 문서가 자급자족할 수 있도록 설계하라.
• MongoDB는 똑똑하지 않다.
TIP 10: 문서가 자급자족할 수 있도록 설계하라.
• MongoDB는 똑똑하지 않다.
TIP 10: 문서가 자급자족할 수 있도록 설계하라.
• findAndModify를 이용한 Locking을 이용한 방법
TIP 11: 자바스크립트보다는 제한자를 사용하라
• $where는 강력하다.



• 그러나 느리다!
  – 제한자의 경우 BSON으로 전달 후 데이터도 BSON 이므로 파싱 없이 처리
  – $where 조건의 경우 모든 데이터를 자바스크립트 객체로 생성하고 자바스크
    립트를 실행해야 함
TIP 11: 자바스크립트보다는 제한자를 사용하라
• 조금 더 빠르게!!!
TIP 12: 집계는 다른 작업과 함께 처리한다.
TIP 13: 데이터 무결성 문제에 대처하는 코드를 작성하라.
• 데이터 일관성을 어플리케이션에서 유지
• Cron 등의 주기적 작업이 필요
  – Consistency Fixer
  – Pre-Populater
  – Aggregator
• 다른 유용한 Script
  – Schema checker
  – Backup Job

Mais conteúdo relacionado

Mais de DaeMyung Kang

How to use redis well
How to use redis wellHow to use redis well
How to use redis wellDaeMyung Kang
 
The easiest consistent hashing
The easiest consistent hashingThe easiest consistent hashing
The easiest consistent hashingDaeMyung Kang
 
How to name a cache key
How to name a cache keyHow to name a cache key
How to name a cache keyDaeMyung Kang
 
Integration between Filebeat and logstash
Integration between Filebeat and logstash Integration between Filebeat and logstash
Integration between Filebeat and logstash DaeMyung Kang
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advanceDaeMyung Kang
 
Massive service basic
Massive service basicMassive service basic
Massive service basicDaeMyung Kang
 
Data Engineering 101
Data Engineering 101Data Engineering 101
Data Engineering 101DaeMyung Kang
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better EngineerDaeMyung Kang
 
Kafka timestamp offset_final
Kafka timestamp offset_finalKafka timestamp offset_final
Kafka timestamp offset_finalDaeMyung Kang
 
Kafka timestamp offset
Kafka timestamp offsetKafka timestamp offset
Kafka timestamp offsetDaeMyung Kang
 
Data pipeline and data lake
Data pipeline and data lakeData pipeline and data lake
Data pipeline and data lakeDaeMyung Kang
 
webservice scaling for newbie
webservice scaling for newbiewebservice scaling for newbie
webservice scaling for newbieDaeMyung Kang
 

Mais de DaeMyung Kang (20)

Count min sketch
Count min sketchCount min sketch
Count min sketch
 
Redis
RedisRedis
Redis
 
Ansible
AnsibleAnsible
Ansible
 
Why GUID is needed
Why GUID is neededWhy GUID is needed
Why GUID is needed
 
How to use redis well
How to use redis wellHow to use redis well
How to use redis well
 
The easiest consistent hashing
The easiest consistent hashingThe easiest consistent hashing
The easiest consistent hashing
 
How to name a cache key
How to name a cache keyHow to name a cache key
How to name a cache key
 
Integration between Filebeat and logstash
Integration between Filebeat and logstash Integration between Filebeat and logstash
Integration between Filebeat and logstash
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advance
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
Data Engineering 101
Data Engineering 101Data Engineering 101
Data Engineering 101
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better Engineer
 
Kafka timestamp offset_final
Kafka timestamp offset_finalKafka timestamp offset_final
Kafka timestamp offset_final
 
Kafka timestamp offset
Kafka timestamp offsetKafka timestamp offset
Kafka timestamp offset
 
Data pipeline and data lake
Data pipeline and data lakeData pipeline and data lake
Data pipeline and data lake
 
Redis acl
Redis aclRedis acl
Redis acl
 
Coffee store
Coffee storeCoffee store
Coffee store
 
Scalable webservice
Scalable webserviceScalable webservice
Scalable webservice
 
Number system
Number systemNumber system
Number system
 
webservice scaling for newbie
webservice scaling for newbiewebservice scaling for newbie
webservice scaling for newbie
 

50 tips & tricks for mongo db developers

  • 1. 50 Tips & Tricks for MongoDB Developers TIPS: 7~13 charsyam@naver.com
  • 2. TIP 7: 미리 만들 수 있는 것은 만들어 놓자. • Insert 비용 보다 Update 비용이 싸다. – 공간 할당이 필요가 없으므로 • 어디에 쓸 것이냐? – 통계 페이지 처럼 시간마다 같은 크기에 값만 바뀌는 경우 • 그런데 적은 용량이면 insert나 update가 큰 차이가 없을듯…
  • 3. TIP 7: 미리 만들 수 있는 것은 만들어 놓자.
  • 4. TIP 8: 가능하면 공간을 미리 할당하라. • Tip 7과 같은 내용 • 미리 만들어두고 당장 안쓰는 정보는 $unset 해 두자.
  • 5. TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면 배열에 저장하라. • 식별자 abilities.str Abilities.con 식별자를 쓴다는 것은 이름 을 안다는 것!
  • 6. TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면 배열에 저장하라. MongoDB 의 특징이 Schemaless 하므로 다 양한 아이템을 넣을 수 있 다. 하지만 damage가 20이 넘는 것만 검색하려면?
  • 7. TIP 9: 데이터를 내장할 때 식별자 없이 검색하려면 배열에 저장하라. 배열로 만들어서 검색
  • 8. TIP 10: 문서가 자급자족할 수 있도록 설계하라. • MongoDB는 똑똑하지 않다.
  • 9. TIP 10: 문서가 자급자족할 수 있도록 설계하라. • MongoDB는 똑똑하지 않다.
  • 10. TIP 10: 문서가 자급자족할 수 있도록 설계하라. • findAndModify를 이용한 Locking을 이용한 방법
  • 11. TIP 11: 자바스크립트보다는 제한자를 사용하라 • $where는 강력하다. • 그러나 느리다! – 제한자의 경우 BSON으로 전달 후 데이터도 BSON 이므로 파싱 없이 처리 – $where 조건의 경우 모든 데이터를 자바스크립트 객체로 생성하고 자바스크 립트를 실행해야 함
  • 12. TIP 11: 자바스크립트보다는 제한자를 사용하라 • 조금 더 빠르게!!!
  • 13. TIP 12: 집계는 다른 작업과 함께 처리한다.
  • 14. TIP 13: 데이터 무결성 문제에 대처하는 코드를 작성하라. • 데이터 일관성을 어플리케이션에서 유지 • Cron 등의 주기적 작업이 필요 – Consistency Fixer – Pre-Populater – Aggregator • 다른 유용한 Script – Schema checker – Backup Job