+NoSQL-infoq ppt v2(郭理靖)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

郭理靖@snda;guolijing@gmail.com;MongoDB在盛大大数据量下的应用11年10月19日星期三SectionsBasicintroductiontoMongoDBMonitorMongoDBBackupandRollbackofMongoDBCaseStudy11年10月19日星期三What’sMongoDBMongoDB(fromhumongous)isascalable,high-performance,opensource,document-orienteddatabase.Currentversion:2.0.011年10月19日星期三What’sMongoDBMongoDB=JSON+Indexes11年10月19日星期三PhilosophyOfMongoDB11年10月19日星期三FeaturesDocument-orientedstorage(JSON)FullIndexSupport(Indexes)Replication&HighavailabilityRichDocument-basedQueriesandUpdatesMap/ReduceAuto-ShardingandGridFS11年10月19日星期三TerminologyRDBMSMongoDBTableCollectionView/Row(s)JSONDocumentColumnnameFieldnameIndexIndexJoinEmbedding&LinkingPartitionShardPartitionKeyShardKey11年10月19日星期三db.runCommand({mapreduce:DenormAggCollection,query:{filter1:{'$in':['A','B']},filter2:'C',filter3:{'$gt':123}},map:function(){emit({d1:this.Dim1,d2:this.Dim2},{msum:this.measure1,recs:1,mmin:this.measure1,mmax:this.measure2100?this.measure2:0});},reduce:function(key,vals){varret={msum:0,recs:0,mmin:0,mmax:0};for(vari=0;ivals.length;i++){ret.msum+=vals[i].msum;ret.recs+=vals[i].recs;if(vals[i].mminret.mmin)ret.mmin=vals[i].mmin;if((vals[i].mmax100)&&(vals[i].mmaxret.mmax))ret.mmax=vals[i].mmax;}returnret;},finalize:function(key,val){val.mavg=val.msum/val.recs;returnval;},out:'result1',verbose:true});db.result1.find({mmin:{'$gt':0}}).sort({recs:-1}).skip(4).limit(8);SELECTDim1,Dim2,SUM(Measure1)ASMSum,COUNT(*)ASRecordCount,AVG(Measure2)ASMAvg,MIN(Measure1)ASMMinMAX(CASEWHENMeasure2100THENMeasure2END)ASMMaxFROMDenormAggTableWHERE(Filter1IN(’A’,’B’))AND(Filter2=‘C’)AND(Filter3123)GROUPBYDim1,Dim2HAVING(MMin0)ORDERBYRecordCountDESCLIMIT4,81234517612345Groupeddimensioncolumnsarepulledoutaskeysinthemapfunction,reducingthesizeoftheworkingset.Measuresmustbemanuallyaggregated.Aggregatesdependingonrecordcountsmustwaituntilfinalization.Measurescanuseprocedurallogic.FiltershaveanORM/ActiveRecord-lookingstyle.6Aggregatefilteringmustbeappliedtotheresultset,notinthemap/reduce.7Ascending:1;Descending:-1Revision4,Created2010-03-06RickOsborne,rickosborne.orgmySQLMongoDB11年10月19日星期三IndexesUniqueIndexesorDuplicateValuesIndexesIndexofSingleKey(Embeddedkey,Documentkey).Defaultindex,‘_id’:MongoID(GUID)IndexofCompoundKeys(db.user.ensureIndex({credit:-1,name:1}))SparseIndex.(Asparseindexcanonlyhaveonefield)//after1.7511年10月19日星期三GeoIndexesGeospatialindexsupported(goodnewsforLBS)db.c.find({a:[50,50]})usingindex{a:’2d’}db.c.find({a:{$near:[50,50]}})usingindex{a:’2d’}Resultsaresortedclosest-farthestdb.c.find({a:{$within:{$box:[[40,40],[60,60]]}}})usingindex{a:’2d’}11年10月19日星期三AtomicOperations$set$unset$inc$push-appendavaluetoanarray$pushAll-appendseveralvaluestoanarray$pull-removeavalue(s)fromanexistingarray$pullAll-removeseveralvalue(s)fromanexistingarray$bit-bitwiseoperations11年10月19日星期三TipsUpdaterequiresawritelock.Writelockis“greedy”rightnowUpdateinbigcollectionisslowandblockotherwritesduringtheupdateQueryitfirstthenupdateitwillreducethelocktime11年10月19日星期三Replication11年10月19日星期三ReplicasetReplicasetsarebasicallymaster/slavereplication,addingautomaticfailoverandautomaticrecoveryofmembernodes.AReplicaSetconsistsoftwoormorenodesthatarecopiesofeachother.(i.e.:replicas)TheReplicaSetautomaticallyelectsaPrimary(master)ifthereisnoprimarycurrentlyavailable.11年10月19日星期三ReplicasetAutomatedfail-overDistributereadloadSimplifiedmaintenanceAReplicaSetcanhavepassivemembersthatcannotbecomeprimary(forreadingandbackup)AReplicaSetcanhavedelayednodes(incaseofusererror)11年10月19日星期三stepdownprimaryIfyoustepdownprimarymanuallywhenprimaryisheavy,thereplicasetmaycannotelectnewprimary.(itisfixedin1.8.0)Maylosedatawhenstepdownprimarymanually.(sometimes,nottestin1.8.0yet)Clientsmaynotknowwhathappened.11年10月19日星期三What’shappenedwhenprimaryisdown?Replicasetwillelectnewprimary,buthow?what’sarbiter?operatortimevotesprioritymaylosedatawhenprimaryisdown11年10月19日星期三Auto-Sharding11年10月19日星期三MonitoringandDiagnosticsQueryProfilerHttpConsolemongostatdb.stat()db.serverStatus()11年10月19日星期三DatabaseProfilerdb.setProfilingLevel(1,20){was:0,slowms:100,ok:1}db.getProfilingStatus()//after1.7x{was:1,slowms:20}11年10月19日星期三DatabaseProfilerdb.system.profile.find(){ts:ThuJan29200915:19:32GMT-0500(EST),info:querytest.$cmdntoreturn:1reslen:66nscanned:0brquery:{profile:2}nreturned:1bytes:50,millis:0}db.system.profile.find().sort({$natural:-1})//Toseenewestinformationfirst11年10月19日星期三mongostat11年10月19日星期三mongostatinserts/s-#ofinsertspersecondquery/s-#ofqueriespersecondupdate/s-#ofupdatesperseconddelete/s-#ofdeletespersecondgetmore/s-#ofgetmores(cursorbatch)persecond11年10月19日星期三mongostatcommand/s-#ofcommandspersecondflushes/s-#offsyncflushespersecondmapped-amountofdatammaped(totaldatasize)megabytesvisze-virtualsizeofprocessinmegabytesres-residentsizeofprocessinmegabytes11年10月19日星期三mongostatfaults/s-#ofpagesfaults/sec(linuxonly)locked-percentoftimeinglobalwritelockidxmiss-percentofbtreepagemisses(sampled)qt|r|w-lockqueuelengths(total|read|write)conn-numberofopenconnections11年10月19日星期三AdminUIs11年10月19日星期三

1 / 44
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功