Contenu connexe
Similaire à 视觉中国的MongoDB应用实践(QConBeijing2011) (20)
视觉中国的MongoDB应用实践(QConBeijing2011)
- 1. QCon beijing 2011
MongoDB
: http://czone.chinavisual.com/art/4b4501548f47e8ef73699a0c.html
- 2. About.me
• ( nightsailer)
• @nightsailer //twitter,sina,linkedin,
github ...
• nightsailer # gmail.com
• http://nightsailer.com/
- 4. App
MMM
• MySQL Percona
Mysql(Master-Master)
Master-Master-Slaves
• HA:MMM
Mysql(M1) Mysql(M2)
Slave Slave
- 6. MySQL
* JSON
• schema
•
*
• schema
• query
- 7. App
MMM/vdb11
KV
KV1
KV2
Mysql(M1) Mysql(M2)
Slave Slave
- 9. • PHP/Perl
• Memcached
•
•
•
- 14. MongoDB
• Redis
• Document
• Redis
• MySQL ,
• MySQL
- 15. MySQL MongoDB
• MySQL MongoDB
• MySQL <=> MongoDB
•
- 17. •
•1 1 90%
• 35 table => 10 collection
• happy!
- 20. 1
•
comments:{
_id:ObjectId(‘xxx’),
art_id:2,
content: ‘ ...’,
replied_on: 12233
created_on: 12222
replies: [{
_id: ObjectId(‘xxx’),
content: ‘ , ...’,
replies:[]
}]}
- 21. 2
/ :
•
•
•
/ /
...)
•
- 23. 2
feed
•
• follower
collection
• embed list
- 24. 3:
1: Regex
•
2: Sphinx
• xml
•
- 25. 3:
3: Array/List ($all)
•
• PHP-SCWS
• :
• oplog
- 27. • MongoDB( ICC
COMMON_CXXFLAGS='-fp-model source -unroll2 -axSSE4.1,SSE4.2 -xSSE3 -
static-intel -fpic -fno-strict-aliasing'
CXXFLAGS="-O3 -ipo -static-libgcc $COMMON_CXXFLAGS"
scons --release --static --extrapath=/opt/local --cxx=$CXX --icc --
extralib='tcmalloc_minimal' --icc-cxxflags="$CXXFLAGS" --icc-
cppflags="$CPPFLAGS" -c $BIN_SERVER
scons -j4 --release --static --extrapath=/opt/local --cxx=$CXX --icc
--extralib='tcmalloc_minimal' --icc-cxxflags="$CXXFLAGS" --icc-
cppflags="$CPPFLAGS" $BIN_SERVER
- 29. • Raid10
•
• XFS
• Ext4 (?)
- 30. PHP-FPM
2009/6, 0.9/1.0
• 1 Master + 2 slaves
Nginx
Mongod Master)
Gearman-workers • 1m
• 20g
Mongod Slave)
Gearman-workers
• Dell 2850/4g(Master) 2*Dell
2950/4g(
- 31. * Slave
•
* lvm snapshot
•
• fsync & lock db
* mongodump
•
- 32. • mongostat / vmstat / iostat
• collectd
• : json-rest+perl plugin
• Munion / Nagios ...
- 33. MongoDB
• CPU
• 4G
• IO
:http://czone.chinavisual.com/art/4c7918b74979590970b80000.html
- 36. 0:
1:
•
• 2
2:
•
driver
• driver
- 37. 1:50x
502 Bad Gateway
* GridFS
• Perl Plack
Starman/Plack Nginx
Proxy store
MongoDB
Disk Cache
* GridFS
• Nginx proxy_store
•
- 39. 1:50x
3
• XFS pre-allocation FS
•
for i in {1..50}
do
echo $i
head -c 2146435072 /dev/zero > $db.$i
done
- 41. •
• 10
• MongoDB
• Repair 5
•
• 10
: http://czone.chinavisual.com/art/4cad0e08497959d621a10000.html
- 43. 1
• --syndelay
• 60s(default) => 15~30s
• IO
• fsync
•
- 44. 2
• 1.6.3, Master-Slaves RelicaSets
• 1 Primary + 2 Secondary
• 4g-8g
• w=2
•
- 48. 4: RS fail-over
• 2 Arbitor
• $ mongod --bind_ip 127.0.0.1,192.168.8.10 --
replSet rs10 --oplogSize 1 ...
• > rs.addArb(‘192.168.8.10:27020’)
• ...
- 49. 4: RS fail-over
6: ReplicaSet
• 1 Primary + 2 Secondary + n Arbitor
•
•
- 50. •6 “ ”
• ;-(
•
• ReplicaSet fail-over
secondary
• Primary ,
•
- 51. 1.8
• 1.8
• journaling file
• mongod -dur
• crash repairDatabase
•
- 53. • GridFS
• Nginx proxy_store
• MongoDB
• ,Plack app
• prefork
- 54. • GridFS
•
• slaveOK
• Plack app Twiggy AnyEvent
- 55. Starman workers/PSGI
Starman
RS02
Nginx
Gearman
127.0.0.1:9001
127.0.0.1:9002
127.0.0.1:9003
127.0.0.1:9004 Twiggy/PSGI
RS01
(slaveOK)
Sencondary
- 57. Primary
• Slave only
IDC
Secondary1
MongoD
Secondary2
ReplicaSet1
• priority 0
VPN
• VPN 2
IDC
Slave1
- 59. • MongoDB
• snapshot
•
• local.oplog.rs ( tailable cursor)
•
• replay oplog
- 61. • VPN
• GridFS
•
• BSON HTTP
• mongod
- 62. 7
•
•
•
• unix
: http://czone.chinavisual.com/art/4c05e7be4979596b7e570000.html
- 64. • Shard_key
• shard key chunk
• 4sq
• shard_key
• counting
• chunk
• balancer
- 65. •
• shard
• shard
•
• 1.8
- 67. MongoDB
• MySQL Web
• Schema free
• Geo
• MySQL
• GridFS
• sharding
• Auto-sharding shared_key balancing
1.8/2.0
- 68. • mongostat
• idx missing, faults,global locked
• db.serverStatus & rs.status
- 69. • Replication
• oplogsize //
slave clone
• --fastsync + snapshot
• --maxConns
• --replSet=<set_name>/<seed list>
• seed list 1 arbitor
- 71. • GridFS
• :Write once, Read many.
• fs.files _id ETag
• file content hash
• gc
• * Node.js
- 72. • Update/Delete
• ,Schema padding
• In-place update
• Mark delete remove
•
• remove() , drop
- 73. • Group
• 4Mb MR
• db.eval & Javascript
• db
• scope
•
- 75. Question?
:http://czone.chinavisual.com/art/4b45015461be3def730e6351.html