Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mongo db 최범균

31,926 views

Published on

MongoDB의 주요 특징과 용도 설명한다.

  • (Unlimited)....ACCESS WEBSITE Over for All Ebooks ................ accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ..................................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Mongo db 최범균

  1. 1. MongoDB 소개<br />최 범 균 (madvirus@madvirus.net)<br />
  2. 2. 2<br />공통점?<br />
  3. 3. 3<br />NoSQL<br />
  4. 4. 4<br />NoSQL is a movement promoting a loosely defined class of non-relational data stores that break with a long history of relational databases. These data stores may<br />not require fixed table schemas, usually avoid join operations and typically scale horizontally.<br />- WIKIPEDIA<br />
  5. 5. NoSQL<br />주요 특징<br />schema-free<br />replication<br />간단한 API<br />no relation / no join<br />eventually consistency (not ACID)<br />scalable / distributed<br />NoSQL의 종류<br />Document store<br />MongoDB, CouchDB, Jackrabbit, Lotus Notes<br />Key/Value store<br />Amazon SimpleDB, MemcacheDB, …<br />Column 기반<br />Hadoop/HBase, Cassandra, Hypertable, …<br />Graph DB<br />Neo4j, HyperGraphDB, …<br />5<br />
  6. 6. 오늘의 주제: MongoDB<br />세미나의 목적<br />MongoDB의 주요 기능 & 활용 방안 소개<br />TOC<br />Document DB와 MongoDB<br />왜 MongoDB?<br />MongoDB 쓰임새<br />6<br />
  7. 7. Document DB & MongoDB<br />7<br />
  8. 8. Document<br />8<br />
  9. 9. Document: Self-Contained<br />9<br />
  10. 10. Document: Schema Free<br />10<br />
  11. 11. Document DB<br />문서 저장소<br />주요 특징<br /><key, value> 형식으로 문서 저장<br />대부분 JSON 형식 이용<br />No Join<br />Schema Free<br />No SQL<br />싼 장비, 대량 데이터, HA (replication), 분산 처리<br />주요 제품<br />MongoDB, CouchDB, Riak, ...<br />11<br />
  12. 12. Document 예시<br />{<br /> ts : “20100415110001.001”,<br /> user : {<br /> nickname: “madvirus”,<br /> id: 12345<br /> },<br /> site : {<br /> domain: “cc2.wemade.com”,<br /> uri: “/main/main”<br /> }<br />}<br />{<br /> ts : “20100415110001.005”,<br /> user : {<br /> nickname: “wemade”,<br /> id: 1<br /> },<br /> site : {<br /> domain: “cc2.wemade.com”,<br /> uri: “/main/main”<br /> },<br /> referer: {<br /> domain: “www.wemade.com”,<br /> uri: “/main/main”<br /> }<br />}<br />12<br />
  13. 13. MongoDB<br />humongous DB<br />현재 버전:1.4.0<br />특징<br />Document-oriented storage<br />index 지원<br />geospacial 인덱스 지원, multikey<br />빠른 업데이트 (no row lock, no table block)<br />Replication<br />Sharding (alpha)<br />MapReduce<br />바이너리 데이터에 대한 효과적인 저장<br />파일, 이미지 등<br />쉬운 설치, 압축만 풀면 땡!<br />언어별 드라이버 제공<br />공식 지원: C, C++, Java, Perl, PHP, Python, Ruby<br />커뮤니티 지원: C#/.NET, Erlang, Go, Groovy/Scala/Clojure<br />13<br />
  14. 14. MongoDB 레퍼런스<br />피딩 시스템의 캐시<br />내부 리포팅 어플리케이션<br />프론트 페이지, 프로젝트의<br />백엔드 스토리지<br />댓글 시스템의 백엔드 스토리지<br />사이트 데이터, 포스트, 댓글, <br />이미지 스토리지<br />서버 모니터링 솔루션<br />실시간 로그 처리&분석<br />14<br />
  15. 15. mongoDB 사용<br />15<br />
  16. 16. MongoDB의 구성요소 - Collection, Document<br />Database<br />Collection<br />RDBMS의 Table과 유사<br />Document를 포함<br />Document<br />RDBMS의 Row와 유사<br />Schema Free<br />문서마다 고유 키 값을 가짐 (“_id”)<br />지정하지 않을 경우 mongoDB가 자동 생성<br />16<br />
  17. 17. 설치 및 실행<br />http://www.mongodb.org 에서 다운로드<br />서버 시작<br />기본DB경로: /data/db (c:datadb), 포트: 27017<br />서버 중지<br />mongo 콘솔 접속후 shutdownServer() 실행<br />Ctrl+C, kill -2 PID, kill -15 PID<br />kill -9 PID 사용시 데이터 깨질 수 있음<br />$ mongod<br />$ mongod --dbpath /wemade/db --port 90912<br />$ mongod –fork –logpath /wemade/log/db/mongodb.log<br />$ mongo<br />> db.shutdownServer()<br />17<br />
  18. 18. 콘솔을 이용한 접근<br />bin/mongo 콘솔 프로그램 이용<br />자바스크립트 코드를 이용<br />$ mongo<br />> use weblog<br />switched to db weblog<br />> db.pageview_minute.find();<br />{ "_id" : ObjectId("4bbc35128319000000001984"), "hour" : "201004071632", "pageviews" : 4000, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc355d8319000000001985"), "hour" : "201004071633", "pageviews" : 601, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc35688319000000001986"), "hour" : "201004071634", "pageviews" : 3194, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc35a48319000000001987"), "hour" : "201004071635", "pageviews" : 3210, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc35e08319000000001988"), "hour" : "201004071636", "pageviews" : 2142, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc361c8319000000001989"), "hour" : "201004071637", "pageviews" : 853, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc3740831900000000198a"), "hour" : "201004071641", "pageviews" : 1026, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc3748831900000000198b"), "hour" : "201004071642", "pageviews" : 7979, "site" : "funpc.wemade.com" }<br />{ "_id" : ObjectId("4bbc3784831900000000198c"), "hour" : "201004071643", "pageviews" : 995, "site" : "funpc.wemade.com" }<br />><br />18<br />
  19. 19. 드라이버를 이용한 접근<br />각 언어별로 제공되는 드라이버 이용<br />Mongo mongo = new Mongo("localhost", 27017);<br />DB db = mongo.getDB("weblog");<br />DBCollection collection = db.getCollection("pageview_minute");<br />BasicDBObject q = new BasicDBObject();<br />SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");<br />q.put("hour", format.format(time));<br />q.put("site", site);<br />BasicDBObject o = new BasicDBObject();<br />BasicDBObject incVal = new BasicDBObject();<br />incVal.put("pageviews", new Integer(1));<br />o.put("$inc", incVal);<br />collection.update(q, o, true, true);<br />19<br />
  20. 20. DB/콜렉션 생성/삭제<br />Lazy Creation<br />실제 데이터가 생성될 때 DB/콜렉션 생성됨<br />명시적인 DB/콜렉션 생성 없음<br />콜렉션 삭제<br />db.collName.drop()<br />20<br />
  21. 21. 문서 관련 기본 API<br />문서 삽입<br />db.collName.save( {name: “mongo”} );<br />문서 조회<br />db.collName.find()<br />db.collName.find( {name: “mongo”} )<br />db.collName.find( {…}, {name: 1, ssn: 1} )<br />db.collName.find( … ).sort( {userid: 1} )<br />db.collName.find( {}, {}, 10, 20);<br />db.collName.count()<br />문서 수정<br />db.collName.update( {userid: “madvirus”}, { lastupts: val}, false );<br />문서 삭제<br />db.collName.remove( {} )<br />db.collName.remove( {userid: “madvirus”} )<br />인덱스 생성<br />db.collectionName.ensureIndex( {userid: 1, regts: 1} )<br />기타<br />group(), min(), max(), $in, $where (or 연산), <br />21<br />
  22. 22. 왜 끌렸나?<br />22<br />
  23. 23. MongoDB가 끌린 이유<br />Replication<br />Sharding<br />MapReduce<br />Atomic 값 증분<br />Capped Collection<br />Geospacial Index<br />23<br />
  24. 24. Master-Slave<br />Replication<br />서버 간 Replication 지원<br />High Availability (Failover)<br />Read Throughput 증대<br />구성<br />Replica Pair<br />Master<br />24<br />
  25. 25. Sharding<br />하나의 개념적 문서 집합을 다수의 물리적 저장소에 분할해서 보관<br />MongoDB는 인덱스 범위를 이용해서 보관<br />Shard<br />Shard<br />Shard<br />Shard<br />Chunk<br />Chunk<br />Chunk<br />Chunk<br />mongos<br />config server<br />Client<br />25<br />
  26. 26. MapReduce 지원<br />MapReduce<br />Google이 창안 <br />대량의 데이터 집합을 많은 컴퓨터로 병렬 처리<br />2단계 처리<br />Map단계 /Reduce 단계<br />응용<br />데이터 클러스터링 연산<br />Collective Intelligence<br />웹 로그 통계 생성<br />데이터 추출/필터링<br />상상하는 만큼 …<br />26<br />
  27. 27. MapReduce 동작 방식<br />27<br />발췌: http://www.slideshare.net/spirosd/mapreduce-distributed-computing-on-large-commodity-clusters<br />
  28. 28. MapReduce 예<br />태그 개수 구하기<br />{tags: [‘dog’, ‘cat’] }<br />{tags: [‘cat’] }<br />{tags: [‘mouse’, ‘cat’, ‘dog’] }<br />{tags: [] }<br />map = function() {<br /> this.tags.forEach(<br /> function(tag) {<br /> emit( tag, 1 );<br /> }<br /> );<br />};<br />{‘dog’: [1, 1] }<br />{‘cat’: [1, 1, 1] }<br />{‘mouse’: [1] }<br />reduce = function( key , values ){<br /> var total = 0;<br /> for ( var i=0; i < values.length ; i++ ) {<br /> total += values[i];<br /> }<br /> return total;<br />};<br />{ "_id" : "cat", "value" : 3 }<br />{ "_id" : "dog", "value" : 2 }<br />{ "_id" : "mouse", "value" : 1 }<br />28<br />
  29. 29. MapReduce + Sharding<br />각 Shard를 통해 데이터 처리 및 수집 <br />클러스터를 이용한 대량 데이터 처리<br />Shard 별 분산∙병렬 처리를 통한 처리 시간 단축/처리량 증가<br />대량 데이터 분석/생성에 적합<br />Shard<br />MapReduce 실행<br />각 Shard에<br />MapReduce <br />실행 요청<br />Shard<br />MapReduce <br />실행 요청<br />MapReduce 실행<br />mongos<br />Client<br />Shard<br />각 Shard의<br />Reduce 결과<br />MapReduce 실행<br />각 Shard의<br />Reduce 결과의<br />Reduce 결과<br />Shard<br />MapReduce 실행<br />29<br />
  30. 30. Atomic 값 증분<br />upsert와 $inc를 이용한 Atomic 값 증분<br />실시간 통계 데이터 생성에 적합<br />시간 당 접속자, 10분당 PV, 분당 회원 가입 수<br />c.update( { hour : "20100415100001”, site : "abc" }, <br /> { $inc : { pageviews: 1} }, <br /> { upsert : true } )<br />c.update( { hour : "20100415100001”, site : "abc" }, <br /> { $inc : { pageviews: 1} }, <br /> { upsert : true } )<br />c.update( { hour : "20100415100001”, site : "abc" }, <br /> { $inc : { pageviews: 1} }, <br /> { upsert : true } )<br />c.update( { hour : "20100415100002”, site : "abc" }, <br /> { $inc : { pageviews: 1} }, <br /> { upsert : true } )<br />데이터 삽입<br />{hour: “2010041510001”, site: “abc”,<br /> pageviews: 1 }<br />pageviews 값 증가<br />{hour: “2010041510001”, site: “abc”,<br /> pageviews: 2 }<br />pageviews 값 증가<br />{hour: “2010041510001”, site: “abc”,<br /> pageviews: 3 }<br />데이터 삽입<br />{hour: “2010041510002”, site: “abc”,<br /> pageviews: 1 }<br />30<br />
  31. 31. Capped Collection<br />개수 제한을 갖는 콜렉션<br />생성<br />db.createCollection(“mycoll”, {capped: true, size: 1000, max: 100})<br />동작 방식<br />지정된 개수만큼 차면, 새 문서를 추가 시 가장 오래된 문서 삭제<br />삽입 순서로 인덱스 자동 생성<br />제약<br />기존 문서 수정시, 기존 문서보다 클 경우 수정 실패<br />문서 삭제 불가<br />32bit 머신에서 10억 바이트 (약 950M) 크기 제한<br />64bit 머신은 시스템 자원만큼<br />활용<br />캐시<br />LRU 캐시와 유사한 효과<br />로깅<br />인덱스 없는 경우 파일시스템에 근접한 쓰기 속도<br />31<br />
  32. 32. Geospacial Index<br />2D 기반의 인덱스<br />32<br />
  33. 33. Geospacial Index<br />좌표를 이용한 인덱스 생성<br />db.position.ensureIndex( {loc: “2d”}, {min: -500, max: 500} )<br />{ loc: [30, 30] }, {loc: {x: 50, y: 30} }<br />쿼리<br />근처에 있는 것 검색 (거리 기준)<br />db.place.find( {loc : {$near: {x:50, y:30} } } )<br />db.place.find( {loc : {$near: {x:50, y:30} } } ).limit(3)<br />영역 안에 포함된 것 검색<br />db.place.find( {loc: {$within : {$box: [[0,0],[10,10]] } } } );<br />db.place.find( {loc: {$within : {$center: [ [50, 50], 20 ] } } } );<br />복합 인덱스<br />근처에 있는 자원 검색<br />db.place.ensureIndex( {loc: “2d”, cat: 1} )<br />db.place.find( {loc: {$near: [10,10] }, cat: “bank” } ).limit(10)<br />응용<br />위치(맵) 기반 연산 (웹 게임 등에서 활용)<br />데이터 클러스터링에서의 활용<br />33<br />
  34. 34. 정리<br />34<br />
  35. 35. MongoDB의 쓰임새<br />적합한 용도<br />웹 App 백엔드 스토리지<br />세션 데이터<br />회원 프로필, 이벤트, 댓글, 설문조사 등<br />실시간 분석<br />Atomic Inc을 이용한 실시간 통계 (실시간 분당/시간당 PV)<br />대용량 로그 처리 & 분석<br />Sharding & MapReduce 기반 대용량 로그 분석/데이터 처리<br />캐시<br /><key, value>, Schema Free 특징으로 캐시 구현 적합<br />Capped Collection<br />좌표 기반 데이터 처리<br />알맞지 않은 용도<br />트랜잭션이 중요한 시스템<br />예, 금융권 시스템, 빌링 시스템, 회원 테이블<br />35<br />
  36. 36. 맺으며…<br />NoSQL DB에 대한 관심 필요<br />Document 중심 사고<br />No Relation, No Join, No SQL, Schema Free<br />MapReduce 이해<br />병렬 처리, no group by<br />RDBMS와 Document DB의 알맞은 사용<br />36<br />
  37. 37. 참고자료<br />MapReduce<br />Wikipedia:http://en.wikipedia.org/wiki/MapReduce<br />MapReduce:distributed computing on large commodity clusters:http://www.slideshare.net/spirosd/mapreduce-distributed-computing-on-large-commodity-clusters<br />NoSQL<br />NoSQL 정의 : http://en.wikipedia.org/wiki/NoSQL<br />MongoDB 관련 문서<br />MongoDB 매뉴얼: http://www.mongodb.org/display/DOCS/Developer+Zone<br />Fast Updates with MongoDB:http://blog.mongodb.org/post/248614779/fast-updates-with-mongodb-update-in-place<br />MongoDB is Fatastic for Logging: http://blog.mongodb.org/post/172254834/mongodb-is-fantastic-for-logging<br />Using MongoDB for Real-time Analytics:<br />http://blog.mongodb.org/post/171353301/using-mongodb-for-real-time-analytics<br />37<br />
  38. 38. Q&A<br />38<br />

×