Purpose
Test the read and write performance of mysql and mongodb
illustrate
1. mongodb uses the latest version 2.4
2. Mysql uses 5.0.95, and the storage engine uses MYISAM (the measured read and write performance of INNODB is only a fraction of that of MYISAM)
3. The test data has only two fields, id:
Integer (index field) increasing from 0 data: data field, tested the performance of data 1KB and 24KB respectively
4. When testing read performance, the query id is a random value in the inserted id
5. There are 50 concurrent read and write processes
6. Pressing machine: 4 cores/8G, DB machines were tested and deployed on ordinary machines (4 cores/8G memory) and high-end machines (24 cores/132G memory), and the hard disk is an ordinary mechanical hard disk
7. The pressing machine and the DB machine are directly connected through a 1000M network card
1. DB is deployed on a common machine
1. The data size is 1KB, and the number of reads and writes is 400W
a) mongodb
the |
Total Data Size |
QPS |
iowait |
net |
Read |
11G |
14600 |
<1% |
20Mb/s |
Write |
11G |
10630 |
~100% |
<17Mb/s |
b) mysql
the |
Total Data Size |
QPS |
iowait |
net |
Read |
4G |
29000 |
<1% |
35Mb/s |
Write |
4G |
15600 |
<40% |
20Mb/s |
2. The data size is 24KB, and the number of reads and writes is 100W
a) mongodb
the |
Total Data Size |
QPS |
iowait |
net |
Read |
32G |
271 |
100% |
<6Mb/s |
Write |
32G |
1230 |
~100% |
<40Mb/s |
b) mysql
the |
Total Data Size |
QPS |
iowait |
net |
Read |
23G |
287 |
100% |
<6Mb/s |
Write |
23G |
6490 |
40% |
130Mb/s |
Under this amount of data, the writing performance of mysql is much higher than that of mongodb. Basically, the network card is full, and both are very slow when reading. Through iostat ?xm
2 commands to view, the disk is always 100% occupied
2. The DB is deployed on a high-end machine
1. The data size is 1KB, and the number of reads and writes is 400W
a) mongodb
the |
Total Data Size |
QPS |
iowait |
net |
Read |
11G |
15800 |
<1% |
20Mb/s |
Write |
11G |
13800 |
~100% |
<20Mb/s |
b) mysql
the |
Total Data Size |
QPS |
iowait |
net |
Read |
4G |
38200 |
<1% |
45Mb/s |
Write |
4G |
23800 |
<40% |
27Mb/s |
2. The data size is 24KB, and the number of reads and writes is 100W
a) mongodb
the |
Total Data Size |
QPS |
iowait |
net |
Read |
32G |
4734 |
<1% |
120Mb/s |
Write |
32G |
2270 |
~100% |
<100Mb/s |
b) mysql
the |
Total Data Size |
QPS |
iowait |
net |
Read |
23G |
4700 |
<1% |
120Mb/s |
Write |
23G |
4500 |
<40% |
120Mb/s |
in conclusion
1. Judging from the test results, the performance of mongodb is not as good as the legendary one. In the above tests, the write performance of mysql is at least 50% faster than that of mongodb, and the read performance is basically 100% faster than that of mongodb.
2. During the test, it was found that mongodb’s hard disk IO usage is very high when writing data, and the time when iowait is 100% basically accounts for about half
3. The hard disk space occupied by mongodb is much larger than that of mysql, and the memory usage of mongodb is very alarming
4. From the performance point of view, mongodb has no reason to replace mysql at all. The advantages of mongodb are relatively complete cluster functions (rich collection, automatic fragmentation, etc.), and friendly Client
Api, if that’s what you need, choose mongodb
rite
32G
2270
~100%
<100Mb/s
b) mysql
the |
Total Data Size |
QPS |
iowait |
net |
Read |
23G |
4700 |
<1% |
120Mb/s |
Write |
23G |
4500 |
<40% |
120Mb/s |
in conclusion
1. Judging from the test results, the performance of mongodb is not as good as the legendary one. In the above tests, the write performance of mysql is at least 50% faster than that of mongodb, and the read performance is basically 100% faster than that of mongodb.
2. During the test, it was found that mongodb’s hard disk IO usage is very high when writing data, and the time when iowait is 100% basically accounts for about half
3. The hard disk space occupied by mongodb is much larger than that of mysql, and the memory usage of mongodb is very alarming
4. From the performance point of view, mongodb has no reason to replace mysql at all. The advantages of mongodb are relatively complete cluster functions (rich collection, automatic fragmentation, etc.), and friendly Client
Api, if that’s what you need, choose mongodb