Mongo DB in No SQLs Mongo DB No
Mongo. DB in No. SQLs - 왜 Mongo. DB를 선택했는가?
No. SQL • No. SQL = No SQL? no no. . . • No. SQL = Not Only SQL!!! Relational Graph Data Column Key-Value Documen t Mongo. DB 기반 Twitter Stream 저장과 탐사 6
왜 No. SQL 인가? Relational DBMS No. SQL • ACID Transactions • Massive Data • 안전성, 완전성 중심 • Complex Data • 성능과 보호의 절충 Web, Big. Data • Schema Free • 구현의 복잡성 • One Insert/Many Read • Many Insert/Many Update • 성능과 안전 • 구현의 단순성 Mongo. DB 기반 Twitter Stream 저장과 탐사 7
No. SQL for Big. Data http: //blog. kissmetrics. com/twitter-statistics/? wide=1 Mongo. DB 기반 Twitter Stream 저장과 탐사 8
No. SQL Stack Apache Hadoop Google Hadoop Map. Reduce Distributed Programming Model Map. Reduce HBase Distributed Databases Big. Table Hadoop Distributed File System(HDFS) Distributed File System Google File System(GFS) Cluster Mongo. DB 기반 Twitter Stream 저장과 탐사 9
No. SQL의 종류 • Key-value stores – Amazon’s Dynamo – Cassandra – Big. Table, Berkeley. DB • Document Database – Mongo. DB, Couch. DB • Column stores – Hadoop/HBase, Google Big. Table, Cassandra • Graph databases – Flock. DB, Neo 4 J Mongo. DB 기반 Twitter Stream 저장과 탐사 10
No. SQL : Document Database • Couch. DB, Mongo. DB JSON Twitter 에서 JSON 으로 데이터 제공 Mongo. DB 기반 Twitter Stream 저장과 탐사 11
Mongo. DB • Document Oriented Database – Data is stored in documents, not tables / relations – JSON -> BSON : BSON is a binary representation of JSON • Mongo. DB is Implemented in C++ – best performance – Platforms 32/64 bit Windows Linux, Mac OS-X, Free. BSD, Solaris • Language drivers for: – – – Ruby / Ruby-on-Rails Java C# Java. Script C / C++ Erlang Python, Perl others. . . Mongo. DB 기반 Twitter Stream 저장과 탐사 12
Mongo. DB Data and Queries • JSON : Example location 1 = { name: "10 gen HQ”, address: "17 West 18 th Street 8 th Floor”, city: "New York”, zip: "10011”, latlong: [40. 0, 72. 0], tags: [“business”, “cool place”], tips: [ {user: "nosh", time: 6/26/2010, tip: "stop by for office from 4 -6 pm"}, {. . . }, ] } Mongo. DB 기반 Twitter Stream 저장과 탐사 13
Mongo. DB Data and Queries • Creating your indexes – db. locations. ensure. Index({tags: 1}) – db. locations. ensure. Index({name: 1}) – db. locations. ensure. Index({latlong: ” 2 d”}) • Finding places: – db. locations. find({latlong: {$near: [40, 70]}}) • With regular expressions: – db. locations. find({name: /^typeaheadstring/) • By tag: – db. locations. find({tags: “business”}) Mongo. DB 기반 Twitter Stream 저장과 탐사 14
Twitter 데이터의 수집과 저장 - Streamming API와 Mongo. DB
Twitter Streamming API • Twitter Streamming API – public streams : follow, track, locations, count, with – user streams – site streams Mongo. DB 기반 Twitter Stream 저장과 탐사 Twitter 4 J 16
Twitter Streamming API https: //stream. twitter. com/1. 1/statuses/filter. json? locations =-122. 75, 36. 8, - 121. 75, 37. 8 { "text": "Time for the States to fight back !!! Tenth Amendment Movement: Taking On the Feds http: //bit. ly/14 t 1 RV #teaparty”, "created_at": "Tue Nov 17 21: 08: 39 +0000 2009", "geo": -74. 5, 40. 25, "id": 5806348114, "in_reply_to_screen_name": null, "in_reply_to_status_id": null, #tcot "user": { "screen_name": "TPO_News", "created_at": "Fri May 15 04: 16: 38 +0000 2009", "description": "Child of God - Married - Gun carrying NRA Conservative - Right Winger hard Core Anti Obama (Pro America), Parrothead - www. ABold. Step. Back. com #tcot #nra #i. Phone", "followers_count": 10470, "friends_count": 11328, "name": "Tom O'Halloran", "profile_background_color": "f 2 f 5 f 5", "profile_image_url": "http: //a 3. twimg. com/profile_images/295981637/TPO_Balcony_normal. jpg", "protected": false, "statuses_count": 21147, "location": "Las Vegas, Baby!!", "time_zone": "Pacific Time (US & Canada)", "url": "http: //www. tpo. net/1 dollar", "utc_offset": -28800, } } Mongo. DB 기반 Twitter Stream 저장과 탐사 17
Twitter Stream의 수집과 저장 SNS data collector Media Stream API (Media. Collector Account) Internet Tweets from following Insert Collected data JSON Tweet collector Tweet raw Data. Base (Mongo. DB) Abstraction by Lucene Tweet Word Vector Databases(Mongo. DB Mentions from anonymous users(selected based on location) • Tweet collector: – Streaming API 기반 트윗 수집, 중복성 검사, 저장 • Abstraction Processing: – Full Text Tweet을 Lucene 을 이용하여 Word Vector화 Mongo. DB 기반 Twitter Stream 저장과 탐사 18
Twitter Stream의 수집과 저장 • Tweet. Stream. Collector Twitter 4 J void start( String db. Name ) { db. Manager = new Mongo. DBManager( db. Name ); Twitter. Stream stream = new Twitter. Stream. Factory(). get. Instance(); stream. add. Listener( this ); Filter. Query query = make. Filter(); stream. filter( query ); ensure. Index (); } Mongo. DB 기반 Twitter Stream 저장과 탐사 19
Twitter Stream의 수집과 저장 • Twitter 4 J의 Streamming Listener 구현 public void on. Status(Status status) { JSONObject media. Data = make. Json. Media. Data( status ); db. Manager. insert. Data( Mongo. DBManager. MEDIADATA_COLLECTION, media. Data. to. String() ); String media. Data. Id = (String)media. Data. get("Media. Data. ID"); JSONArray word. Array = (JSONArray)media. Data. get( "Term. Vector"); JSONObject abstracted. Data = make. Json. Abstracted ( media. Data. Id, status, word. Array ); db. Manager. insert. Data( Mongo. DBManager. ABSRACTED_COLLECTION, abstracted. Data. to. String()); } Mongo. DB 기반 Twitter Stream 저장과 탐사 20
Twitter Stream의 수집과 저장 • Syntactic parser: 문장에서 분석을 위한 어휘소 추출 • Stopword filter: 의미 없는 분석 결과 배제를 위한 필터링 by LUCENE Tweet raw Data. Base (Mongo. DB) Tweet word set Data. Base (Mongo. DB) Text analyzer Syntactic parser Word Dictionary Stopword filter Spam manager 소셜 미디어 스트림에서의 공간 지식 탐색 21
Twitter Stream의 수집과 저장 • Term Vector의 생성 JSONArray make. Json. Term. Vector( String text ) throws Exception { Tag. Magnitude. Vector tmv = tweet. Analyzer. analyze( text ); JSONObject json. Tag = null; List<Tag. Magnitude> tml = tmv. get. Tag. Magnitudes(); //분석 데이터를 담을 JSONArray 생성 JSONArray json. Term. Vector = new JSONArray(); for( Tag. Magnitude tm : tml ) { //단일 분석 데이터 생성 json. Tag = new JSONObject(); json. Tag. put("Display. Text", tm. get. Display. Text()); json. Tag. put("Stemmed. Text", tm. get. Stemmed. Text()); json. Tag. put("Magnitude", tm. get. Magnitude()); } } //분석 데이터 삽입 json. Term. Vector. put(json. Tag); return json. Term. Vector; Mongo. DB 기반 Twitter Stream 저장과 탐사 22
지식탐사와 Sliding Window Caching
공간지식 : 연관규칙 & co-location Answers: and Spatial Databases : A Tour Mongo. DB 기반 Twitter Stream 저장과 탐사 26
공간지식 : 연관규칙 & co-location Spatial Databases : A Tour Mongo. DB 기반 Twitter Stream 저장과 탐사 27
공간지식 : Spatial Clustering/Flock Density-based Clustering For Real-time Stream Data Mongo. DB 기반 Twitter Stream 저장과 탐사 28
공간지식 : Outlier Detection • Traffic Outlier Detection Mongo. DB 기반 Twitter Stream 저장과 탐사 29
공간지식 : Outlier Detection Mongo. DB 기반 Twitter Stream 저장과 탐사 30
Twitter Mining Mongo. DB 기반 Twitter Stream 저장과 탐사 32
Twitter Mining Mongo. DB 기반 Twitter Stream 저장과 탐사 33
Twitter Mining Mongo. DB 기반 Twitter Stream 저장과 탐사 34
Problems • Massive Data – Storage – Caching • Knowledge – Association Rule – Clustering Mongo. DB 기반 Twitter Stream 저장과 탐사 35
Caching for Twitter Streams • Stream Caching and Analysis Twitter Stream Sliding Window Caching Stream Analysis Twitter Collector Twitter Mongo. DB Twitter Raw. Data Mongo. DB Twitter Abstracted Data Mongo. DB 기반 Twitter Stream 저장과 탐사 36
Caching for Twitter Streams • Stream. Storage – Twitter Stream Sliding Window Caching New Arrival Tweet Streams sliding window query Mongo. DB 기반 Twitter Stream 저장과 탐사 37
메모리 관리 방안 • 패턴 노드 테이블 – Pattern node ID(nid)를 메모리에 저장 – SCi : Bi에서 발생한 규칙에 대한 support count – Hash를 통해 FP-tree의 패턴 노드 테이블(memory or disk)에 접근 Hash table for Pattern-node Time-sensitive Sliding-window B 1 B 2 B 3 B… SCi B 1 10 B 2 15 B 5 20 B i-2 B i-1 Bi transaction Pattern-node table nid : 0010 Bi B i-3 Root b a b nid 0010 d nid : 0010 c c d c Mongo. DB 기반 Twitter Stream 저장과 탐사 d f 40
메모리 관리 방안 • LRU 구조 이용 – 메모리와 Disk의 Hybrid 저장 구조 지원 – pattern tree를 구성하는 항목들에 대한 time window 메타정보를 관리 – 특정 시간(threshold value) 이상 접근되지 않을 경우 Disk로 저장 or 삭제 t(B i) t(B i+1 ) New rules LRU Structure nid 0010 threshold value nid : 0010 Bi SCi B 1 10 B 2 15 B 5 20 nid 0010 Past Mongo. DB 기반 Twitter Stream 저장과 탐사 41
구현 // long time. Unit, long slide. Time, long window. Time, long stop. Time, min. Support, number of rules exp 1. exp. DSTree( 10*MINUTE , 20*MINUTE, 2*HOUR, start. Time, stop. Time, 1000); [Total Nodes : 115196: Created: 18379: Deleted: 17555 : x 0 [Frequency. List Size : 42923 attr. Node. List Size : 42923: Slided Out Items : 5008 stream. Line. Size : [0: 2078][1: 1994][2: 2064][3: 2110][4: 2133][5: 2160][6: 2131][7: 2173][8: 2129][9: 2211 ][10: 2186][11: 2133][12: 2205] stream Transaction Sum: 27707 stream Items Total Sum: 158901 [Total Nodes : 116292: Created: 18799: Deleted: 17703 : x 0 [Frequency. List Size : 43653 attr. Node. List Size : 43653: Slided Out Items : 4971 stream. Line. Size : [0: 2064][1: 2110][2: 2133][3: 2160][4: 2131][5: 2173][6: 2129][7: 2211][8: 2186][9: 2133 ][10: 2205][11: 2144][12: 2277] stream Transaction Sum: 28056 stream Items Total Sum: 160736 Mongo. DB 기반 Twitter Stream 저장과 탐사 43
- Slides: 44