mongodb is与mysql速度,与具有1000万条记录的MySQL相比,MongoDB非常慢

I've got fairly high loaded project, running on MySQL with around 10M records, getting capped with approx 500 requests per second. The data is pretty unique, and cache hit rate is around 3% only. Every row got about 10 fields, 2 of which indexed. 99% of my queries use the two index fields for requests.

I decided to try a NoSQL, and MongoDB was no brainer. Moving data was pretty easy, with simple custom made script. Database schema remained exactly the same, I replicated the same two indexes fields, which were still accountable for 90% of requests. Then I decided to give it a try and was quite shocked: MongoDB was very, VERY slow answering to the queries. Response rate varied from 5 to 10 requests per second, comparing to 500 with mysql.

Any ideas why is this happening? Is it normal? Should I expect MongoDb to outperform Mysql in this particular case(10M records, lots of unique requests with low cache hit rate)? I'm feeling like I'm missing a point.

UPDATE with some specs

Server I was testing with is quad core xeon with 4GB ram

MySQL Table is(field names renamed):

CREATE TABLE `table` (

`recordid` int(10) unsigned NOT NULL AUTO_INCREMENT,

`var1` varchar(200) DEFAULT NULL,

`var2` char(32) DEFAULT NULL,

`var3` bigint(20) unsigned DEFAULT NULL,

`var4` smallint(5) unsigned DEFAULT NULL,

`var5` datetime DEFAULT NULL,

`var6` int(10) unsigned NOT NULL,

`var7` int(10) unsigned NOT NULL,

`var8` tinyint(1) DEFAULT NULL,

PRIMARY KEY (`recordid`),

UNIQUE KEY `recordid_UNIQUE` (`recordid`),

KEY `keyvar7` (`var7`),

KEY `keyvar6` (`var6`)

Typical query is:

SELECT var2, var4, var5, var6 from table where var7=xxx and var6=yyy

I hand verified that MongoDB properly replicated the same indexes, by comparing queries using indexed and non-indexed fields.

UPDATE2 MongoDB .getIndexes() reply

> db.table.getIndexes();

[

{

"v" : 1,

"key" : {

"_id" : 1

},

"ns" : "table.table",

"name" : "_id_"

},

{

"v" : 1,

"key" : {

"var6" : 1

},

"ns" : "table.table",

"name" : "var6_1"

},

{

"v" : 1,

"key" : {

"var7" : 1

},

"ns" : "table.table",

"name" : "var7_1"

}

]

解决方案

MongoDB is not a magic query accelerator. Your site won't sustain 10x load just because you switch to mongo.

Judging from your numbers, I suspect that there was resource saturation taking place. MySQL can certainly do a lot more than 500 QPS.

Do you know what was your bottleneck? I'd wager that you have much less RAM than needed, data has to be fetched from disk and disk gets saturated. At this point, no DB tech will help you, unless you get more iron (or delete some data).

As for the poorer performance of mongo, it's hard to tell without the specifics.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值