在多个AWS实例MongoDB的负载均衡 [英] MongoDB load balancing in multiple AWS instances

查看:291
本文介绍了在多个AWS实例MongoDB的负载均衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用亚马逊网络服务这是使用Node.js的服务器和MongoDB的数据库业务应用程序。目前的node.js服务器乳宁在EC2中的实例。而且我们保持我们的MongoDB数据库中的一个单独的微型实例。现在,我们要部署副本集在我们的MongoDB数据库,因此,如果MongoDB中被锁定或unavailble,我们仍然可以运行我们的数据库并从中获取数据。

We're using amazon web service for a business application which is using node.js server and mongodb as database. Currently the node.js server is runing on a EC2 medium instance. And we're keeping our mongodb database in a separate micro instance. Now we want to deploy replica set in our mongodb database, so that if the mongodb gets locked or unavailble, we still can run our database and get data from it.

因此​​,我们试图保持副本在不同的情况下,设置的每个成员,这样我们就可以从数据库中获取数据,即使在主memeber的实例关闭。

So we're trying to keep each member of the replica set in separate instances, so that we can get data from the database even if the instance of the primary memeber shuts down.

现在,我想添加负载平衡器的数据库,使数据库正常工作,即使在巨大的交通负荷的时间。在这种情况下,我可以读通过添加slaveOK配置在replicaSet平衡数据库。但它会不会加载平衡数据库如果在数据库中写入操作巨大的交通负荷。

Now, I want to add load balancer in the database, so that the database works fine even in huge traffic load at a time. In that case I can read balance the database by adding slaveOK config in the replicaSet. But it'll not load balance the database if there is huge traffic load for write operation in the database.

要解决这个问题,我有两个选择:到现在。

To solve this problem I got two options till now.

选项1:我已经给分片的数据库,并保持每个碎片在单独的实例。而每个碎片下会有一个reaplica在同一个实例中设置。但有一个问题,因为碎片划分在多个部分的数据库,因此,每个碎片不会在其内保持相同的数据。因此,如果一个实例关闭,我们就不能说实例中的碎片访问数据。

Option 1: I've to shard the database and keep each shard in separate instance. And under each shard there will be a reaplica set in the same instance. But there is a problem, as the shard divides the database in multiple parts, so each shard will not keep same data within it. So if one instance shuts down, we'll not be able to access the data from the shard within that instance.

要解决这个问题,我想在分裂的碎片数据库和每个碎片都会在不同的情况下,一个replicaSet。因此,即使一个实例关闭,我们将不会面临任何问题。但是,如果我们已经2碎片和每个碎片已在replicaSet 3名成员那么我就需要6 AWS实例。所以,我认为这不是最佳的解决方案。

To solve this problem I'm trying to divide the database in shards and each shard will have a replicaSet in separate instances. So even if one instance shuts down, we'll not face any problem. But if we've 2 shards and each shard has 3 members in the replicaSet then I need 6 aws instances. So I think it's not the optimal solution.

选项2:我们可以创建MongoDB的主 - 主配置,这意味着所有的数据库将是主要的且都将具有读/写访问的,但我也想他们自动同步与对方几乎每经常,所以他们都最终会被彼此的克隆。而所有这些主数据库将在单独的实例。但我不知道MongoDB中是否支持这种结构还是不行。

Option 2: We can create a master-master configuration in the mongodb, that means all the database will be primary and all will have read/write access, but I would also like them to auto-sync with each other every so often, so they all end up being clones of each other. And all these primary databases will be in separate instance. But I don't know whether mongodb supports this structure or not.

我没有得到任何的MongoDB DOC /博客的这种情况。所以,请建议我应该是什么这个问题的最佳解决方案。

I've not got any mongodb doc/ blog for this situation. So, please suggest me what should be the best solution for this problem.

推荐答案

这不会是迄今为止一个完整的答案,有太多的细节,我能写但整个文章关于这个问题,因为可能很多人一样,因为我没有那样的空闲时间,我会添加一些评论对我所看到的。

This won't be a complete answer by far, there is too many details and I could write an entire essay about this question as could many others however, since I don't have that kind of time to spare, I will add some commentary about what I see.

现在,我想添加负载平衡器的数据库,使数据库正常工作,即使在巨大的交通负荷的时间。

Now, I want to add load balancer in the database, so that the database works fine even in huge traffic load at a time.

副本集不是为了这样的。如果您想负载平衡,你实际上可能寻求拆分,这将让你做到这一点。

Replica sets are not designed to work like that. If you wish to load balance you might in fact be looking for sharding which will allow you to do this.

复制为自动故障转移。

在这种情况下,我可以读通过添加slaveOK配置在replicaSet平衡数据库。

In that case I can read balance the database by adding slaveOK config in the replicaSet.

一直以来,以保持最新,您的成员将得到同样多的OPS作为主好像这样不能帮太多。

Since, to stay up to date, your members will be getting just as many ops as the primary it seems like this might not help too much.

在现实中,而不是有一台服务器有很多连接排队,你有许多服务器排队陈旧数据的连接数,因为成员的一致性是最终的,不是立竿见影不像ACID技术,然而,话虽如此,他们只能通过32位最终一致性奇毫秒,这意味着他们没有落后不够的,如果装在主给予像样的吞吐量。

In reality instead of having one server with many connections queued you have many connections on many servers queueing for stale data since member consistency is eventual, not immediate unlike ACID technologies, however, that being said they are only eventually consistent by 32-odd ms which means they are not lagging enough to give decent throughput if the primary is loaded.

由于读操作的同时,你会得到同样的速度不管你是从小学或中学读书。我想你可以推迟从创建有机磷农药的停顿,但将带回大量陈旧的数据回报。

Since reads ARE concurrent you will get the same speed whether you are reading from the primary or secondary. I suppose you could delay a slave to create a pause of OPs but that would bring back massively stale data in return.

且不说MongoDB是不是多主因此你只能写一个节点一时间使得slaveOK不是最有用的设置在世界上的任何更多,我见过无数次,其中10gen的自我推荐您使用分片了该设置。

Not to mention that MongoDB is not multi-master as such you can only write to one node a time makes slaveOK not the most useful setting in the world any more and I have seen numerous times where 10gen themselves recommend you use sharding over this setting.

选项2:我们可以在MongoDB中创建一个主 - 主配置,

Option 2: We can create a master-master configuration in the mongodb,

这需要你自己的编码。在这一点上,你可能需要使用支持 http://en.wikipedia.org数据库实际上考虑/维基/多master_replication

This would require you own coding. At which point you may want to consider actually using a database that supports http://en.wikipedia.org/wiki/Multi-master_replication

这是因为你正在寻找的速度是最有可能实际上在写不读,因为我上面所讨论的。

This is since the speed you are looking for is most likely in fact in writes not reads as I discussed above.

选项1:我已经给分片的数据库,并保持每个碎片在单独的实例

Option 1: I've to shard the database and keep each shard in separate instance.

这是推荐的方式,但你发现它的告诫。这是不幸的事情仍然没有解决的多主机复制是应该解决的,但是,多主机复制并添加自己的船鼠疫鼠到欧洲自身,我会强烈建议你做一些认真的研究,你认为是否之前MongoDB中目前无法提供服务您的需求。

This is the recommended way but you have found the caveat with it. This is unfortunately something that remains unsolved that multi-master replication is supposed to solve, however, multi-master replication does add its own ship of plague rats to Europe itself and I would strongly recommend you do some serious research before you think as to whether MongoDB cannot currently service your needs.

您可能会担心没有什么,因为FSYNC队列的目的是处理与IO瓶颈放慢你写,因为它会在SQL和读取是并发的,所以如果你计划你的架构和工作集的权利,你应该能够有机磷农药得到了大量的。

You might be worrying about nothing really since the fsync queue is designed to deal with the IO bottleneck slowing down your writes as it would in SQL and reads are concurrent so if you plan your schema and working set right you should be able to get a massive amount of OPs.

有实际上是一个链接的问题在这里从10gen公司的员工,这是非常好的阅读: http://stackoverflow.com /一/三十八万三千四百七十八分之一千七百四十五万九千四百八十八,它表明到底有多少吞吐量的MongoDB可以在负载下实现的。

There is in fact a linked question around here from a 10gen employee that is very good to read: http://stackoverflow.com/a/17459488/383478 and it shows just how much throughput MongoDB can achieve under load.

这将很快长出新的文件级锁定已在Dev分支。

It will grow soon with the new document level locking that is already in dev branch.

这篇关于在多个AWS实例MongoDB的负载均衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆