Professional Documents
Culture Documents
MongoDB
: http://czone.chinavisual.com/art/4b4501548f47e8ef73699a0c.html
1141
About.me
( nightsailer)
@nightsailer //twitter,sina,linkedin,
github ...
nightsailer # gmail.com
http://nightsailer.com/
1141
MongoDB
NoSQL?
Auto-shard?
No! 08
K/V
MySQL
1141
App
MySQL Percona
MMM
Slave
1141
Mysql(M2)
Mysql(Master-Master)
Mysql(M1)
Master-Master-Slaves
HA:MMM
Slave
schema
1141
MySQL
* JSON
schema
*
schema
query
1141
App
MMM/vdb11
KV
KV1
KV2
Mysql(M1)
Slave
1141
Mysql(M2)
Slave
Memcached
Memcached
KV
1141
PHP/Perl
Memcached
1141
Flare
Repcached
Redis
TC/TT
1141
10
Flare
cluster,
Memcached
1141
11
;-(
1141
12
Cassandra
CouchDB
1141
13
MongoDB
Redis
Document
Redis
MySQL,
MySQL
1141
14
MySQL MongoDB
MySQLMongoDB
1141
15
MySQL
Transaction
Joins
1141
16
1190%
35table => 10 collection
happy!
1141
17
MongoDB,
GridFS
MogileFS
1141
18
MongoDB,
SourceForge
10genmailing-list
NoSQLMongoDB
1141
19
comments:{
_id:ObjectId(xxx),
art_id:2,
content: ...,
replied_on:
12233
created_on: 12222
replies: [{
_id: ObjectId(xxx),
content: ,...,
replies:[]
}]}
1141
20
2
/:
1141
//
...)
21
db.activity_stream.feed (
db.activity_stream.user)
db.activity_stream(
1141
22
2
feed
follower
collection
embed list
1141
23
3:
1: Regex
2: Sphinx
xml
1141
24
3:
3: Array/List ($all)
PHP-SCWS
:
oplog
1141
25
MongoDB
Scons, Python
boost(CentOS)
static link mongod
tcmalloc
1141
26
MongoDB( ICC
COMMON_CXXFLAGS='-fp-model source -unroll2
static-intel -fpic -fno-strict-aliasing'
CXXFLAGS="-O3 -ipo
-axSSE4.1,SSE4.2 -xSSE3 -
-static-libgcc $COMMON_CXXFLAGS"
scons --release --static --extrapath=/opt/local --cxx=$CXX --icc -extralib='tcmalloc_minimal' --icc-cxxflags="$CXXFLAGS" --icccppflags="$CPPFLAGS" -c $BIN_SERVER
scons -j4 --release --static --extrapath=/opt/local --cxx=$CXX --icc
--extralib='tcmalloc_minimal' --icc-cxxflags="$CXXFLAGS" --icccppflags="$CPPFLAGS" $BIN_SERVER
1141
27
1141
28
Raid10
XFS
Ext4 (?)
1141
29
PHP-FPM
Nginx
Mongod Master)
Gearman-workers
Mongod Slave)
Gearman-workers
2009/6, 0.9/1.0
1 Master + 2 slaves
1m
20g
Dell 2850/4g(Master)2*Dell
2950/4g(
1141
30
* Slave
* lvm snapshot
fsync & lock db
* mongodump
1141
31
mongostat / vmstat / iostat
collectd
: json-rest+perl plugin
Munion / Nagios ...
1141
32
MongoDB
CPU
4G
IO
:http://czone.chinavisual.com/art/4c7918b74979590970b80000.html
1141
33
:http://czone.chinavisual.com/art/4b45015496ddabef73f49197.html
1141
34
Why?
Map/Reduce/
1.6+
** reIndexrepairDatabase,
1141
35
0:
* MongoDB
Out of Memory!
v1.3
* cursor
Perl driverbug,
1141
36
0:
1:
2
2:
driver
driver
1141
37
1:50x
502 Bad Gateway
* GridFS
Starman/Plack
Nginx
Proxy store
Disk Cache
MongoDB
Perl Plack
* GridFS
Nginx proxy_store
1141
38
1:50x
504 Gateway timeout
Perlnginx_errorlog
5mongodb.log
client
1141
39
1:50x
3
XFSpre-allocationFS
for i in {1..50}
do
echo $i
head -c 2146435072 /dev/zero > $db.$i
done
1141
40
2:
Mongod crash
Why?
Map/Reduce/
1141
41
: http://czone.chinavisual.com/art/4cad0e08497959d621a10000.html
1141
42
10
MongoDB
Repair5
10
: http://czone.chinavisual.com/art/4cad0e08497959d621a10000.html
1141
42
MongoDB
cluster: slave
1141
43
1
--syndelay
60s(default) => 15~30s
IO
fsync
1141
44
2
1.6.3,Master-SlavesRelicaSets
1 Primary + 2 Secondary
4g-8g
w=2
1141
45
5
1141
46
:http://czone.chinavisual.com/art/4bd19d3b4979593e1a350000.html
1141
47
4: RS fail-over
MongoDB
Primarykill2
secondary
secondary
1141
48
4: RS fail-over
2 Arbitor
> rs.addArb(192.168.8.10:27020)
...
1141
49
4: RS fail-over
6: ReplicaSet
1141
50
6
;-(
ReplicaSetfail-over
secondary
Primary ,
1141
51
1.8
1.8
journaling file
mongod -dur
crashrepairDatabase
1141
52
GridFS
10mb-500mb
1141
53
GridFS
Nginx proxy_store
MongoDB
,Plack app
prefork
1141
54
GridFS
slaveOK
Plack appTwiggyAnyEvent
1141
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
1141
56
1141
57
Slave only
Primary
IDC
MongoD
Secondary1
priority 0
Secondary2
ReplicaSet1
VPN
1141
IDC
Slave1
VPN2
58
>300ms
MongoDB
1141
59
MongoDB
snapshot
local.oplog.rs (tailable cursor)
replay oplog
1141
60
2
GridFS
VPN
1141
61
VPN
GridFS
BSONHTTP
mongod
1141
62
7
unix
: http://czone.chinavisual.com/art/4c05e7be4979596b7e570000.html
1141
63
Auto-sharding
1.6GA Auto-sharding
21
1141
64
Shard_key
shard keychunk
4sq
shard_key
counting
chunk
balancer
1141
65
shard
shard
1.8
1141
66
MongoDBauto-shard
GA
2.0+ ?
1141
67
MongoDB
MySQLWeb
Schema free
Geo
MySQL
GridFS
sharding
Auto-shardingshared_keybalancing
1.8/2.0
1141
68
Question?
:http://czone.chinavisual.com/art/4b45015461be3def730e6351.html
1141
69