Scaling mongo with tons of writes

114 views
Skip to first unread message

wue

unread,
Feb 11, 2011, 4:38:17 PM2/11/11
to mongodb-user
Hi,
we are deploying a solution where we do inserts and findAndRemove
queries. These are all writes and if we setup replica sets, I think
all the queries still go through the master even if we enable reads
from slaves.
Traffic is potentially very high on these mongos and I need to figure
out a solution to scale this setup. Has anybody setup a similar
solution and/or can provide some feedback and suggestions.

Thanks!
Markus

sridhar

unread,
Feb 11, 2011, 4:47:39 PM2/11/11
to mongodb-user
Writes to the replica set always go to the primary but you can read
from secondaries. For horizontal scaling you can use the sharding
feature of Mongo. More information on sharding can be found at
http://www.mongodb.org/display/DOCS/Sharding and its sub documents.

wue

unread,
Feb 11, 2011, 5:36:49 PM2/11/11
to mongodb-user
Thanks for the quick reply. I should have mentioned that we have many
collections with anywhere between 5k - 100k objects. I think sharding
only kicks in at larger collections. FindAndRemove (i.e.,
findAndModify with the remove flag) still all go to the master, right?
If yes, replica sets don't give me much gain as there are very little
finds without modify.

Markus


On Feb 11, 4:47 pm, sridhar <srid...@10gen.com> wrote:
> Writes to the replica set always go to the primary but you can read
> from secondaries. For horizontal scaling you can use the sharding
> feature of Mongo. More information on sharding can be found athttp://www.mongodb.org/display/DOCS/Shardingand its sub documents.

Robert Wohleb

unread,
Feb 11, 2011, 5:47:52 PM2/11/11
to mongod...@googlegroups.com
From what I've seen, you can enable sharding on the DB level, but not on the collection level. The result is that the collections get evenly distributed among the shards, but each collection remains whole. A write for any particular collection will go to the proper shard. Am I understanding this correctly?


~Rob

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.




--
"C - all the power and flexibility of assembly language combined with the readability and maintainability of assembly language."

Scott Hernandez

unread,
Feb 11, 2011, 5:51:55 PM2/11/11
to mongod...@googlegroups.com
That is possible, but at the moment all un-sharded collections (in a
sharded db) will be on the default shard unless you move them. There
is a feature to support spreading the collections across shards in a
sharded db.

http://jira.mongodb.org/browse/SERVER-939

wue

unread,
Feb 11, 2011, 6:22:58 PM2/11/11
to mongodb-user
OK, I am a bit confused.... This link seems to say that it is possible
to shard dbs (i.e., collections as a whole are spread across shards)
unless I read it wrong:
http://www.google.com/url?sa=D&q=http://www.mongodb.org/display/DOCS/Configuring%2BSharding%23ConfiguringSharding-EnablingShardingonaDatabase
But this ticket indicates that it is currently not possible:
http://www.google.com/url?sa=D&q=http://jira.mongodb.org/browse/SERVER-939

Is it possible or not? If yes, this could be a solution for my setup.

Markus

On Feb 11, 5:51 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> That is possible, but at the moment all un-sharded collections (in a
> sharded db) will be on the default shard unless you move them. There
> is a feature to support spreading the collections across shards in a
> sharded db.
>
> http://jira.mongodb.org/browse/SERVER-939
>
>
>
>
>
>
>
> On Fri, Feb 11, 2011 at 2:47 PM, Robert Wohleb <rwoh...@gmail.com> wrote:
> > From what I've seen, you can enable sharding on the DB level, but not on the
> > collection level. The result is that the collections get evenly distributed
> > among the shards, but each collection remains whole. A write for any
> > particular collection will go to the proper shard. Am I understanding this
> > correctly?
> >http://www.mongodb.org/display/DOCS/Configuring+Sharding#ConfiguringS...
> > ~Rob
> > On Fri, Feb 11, 2011 at 2:36 PM, wue <markus....@gmail.com> wrote:
>
> >> Thanks for the quick reply. I should have mentioned that we have many
> >> collections with anywhere between 5k - 100k objects. I think sharding
> >> only kicks in at larger collections. FindAndRemove (i.e.,
> >> findAndModify with the remove flag) still all go to the master, right?
> >> If yes, replica sets don't give me much gain as there are very little
> >> finds without modify.
>
> >> Markus
>
> >> On Feb 11, 4:47 pm, sridhar <srid...@10gen.com> wrote:
> >> > Writes to the replica set always go to the primary but you can read
> >> > from secondaries. For horizontal scaling you can use the sharding
> >> > feature of Mongo. More information on sharding can be found
> >> > athttp://www.mongodb.org/display/DOCS/Shardingandits sub documents.

Scott Hernandez

unread,
Feb 11, 2011, 6:31:52 PM2/11/11
to mongod...@googlegroups.com
The docs are misleading; it doesn't do distribution yet. You can do
that manually though.

wue

unread,
Feb 11, 2011, 6:40:36 PM2/11/11
to mongodb-user
If I enable sharding on all collections, will there be a benefit with
lots of small sharded collections? Or will they stay on the default
shard because they are small collections?

Markus

On Feb 11, 6:31 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> The docs are misleading; it doesn't do distribution yet. You can do
> that manually though.
>
>
>
>
>
>
>
> On Fri, Feb 11, 2011 at 3:22 PM, wue <markus....@gmail.com> wrote:
> > OK, I am a bit confused.... This link seems to say that it is possible
> > to shard dbs (i.e., collections as a whole are spread across shards)
> > unless I read it wrong:
> >http://www.google.com/url?sa=D&q=http://www.mongodb.org/display/DOCS/...
> > But this ticket indicates that it is currently not possible:
> >http://www.google.com/url?sa=D&q=http://jira.mongodb.org/browse/SERVE...
> >> >> > athttp://www.mongodb.org/display/DOCS/Shardinganditssub documents.

Scott Hernandez

unread,
Feb 11, 2011, 6:54:55 PM2/11/11
to mongod...@googlegroups.com
If you enable sharding on collections then the collections will be
spread across the shards.

There are limits you must reach before the balancer can move chunks to
other shards. Is that what you are saying?

Sergei Tulentsev

unread,
Feb 11, 2011, 7:46:01 PM2/11/11
to mongod...@googlegroups.com
But there's always a possibility to manually split and move chunks, right?

wue, what rate are you anticipating? I think, your average box can easily deliver around 40k writes/sec.
Best regards,
Sergei Tulentsev

wue

unread,
Feb 11, 2011, 8:38:50 PM2/11/11
to mongodb-user
I don't think that we are seeing 40k... more like 3-4k before queries
get really slow and connections start to pile up. This is what we have
now but we'd like to be able to scale more, of course.
Scott, yes, at what size of the collection is the balancer able to
move chunks?

Markus


On Feb 11, 7:46 pm, Sergei Tulentsev <sergei.tulent...@gmail.com>
wrote:
> But there's always a possibility to manually split and move chunks, right?
>
> wue, what rate are you anticipating? I think, your average box can easily
> deliver around 40k writes/sec.
>
> On Sat, Feb 12, 2011 at 2:54 AM, Scott Hernandez
> <scotthernan...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
> > If you enable sharding on collections then the collections will be
> > spread across the shards.
>
> > There are limits you must reach before the balancer can move chunks to
> > other shards. Is that what you are saying?
>

Scott Hernandez

unread,
Feb 11, 2011, 9:15:33 PM2/11/11
to mongod...@googlegroups.com
On Fri, Feb 11, 2011 at 5:38 PM, wue <marku...@gmail.com> wrote:
> I don't think that we are seeing 40k... more like 3-4k before queries
> get really slow and connections start to pile up. This is what we have
> now but we'd like to be able to scale more, of course.
> Scott, yes, at what size of the collection is the balancer able to
> move chunks?

It depends on the version. Basically when there is an un-balance of
chunks exceeding 8, then they will start moving. Things will split
when they get too big; that is configurable but in versions was set at
200MB by default.

You can see the sharding faq: http://www.mongodb.org/display/DOCS/Sharding+FAQ

Nat

unread,
Feb 11, 2011, 9:17:56 PM2/11/11
to mongodb-user
Markus,

If you have a lot of collections, you'd probably better off with
custom connection logic where you find the server to connect to based
on the collection name. That's way you can scale quite easily.
Reply all
Reply to author
Forward
0 new messages