Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:05:28+00:00 2026-05-28T20:05:28+00:00

I am currently using mongodb, and I see very bad performance of queries (It

  • 0

I am currently using mongodb, and I see very bad performance of queries (It could take seconds).
The scenario is as following:

I have a documents of structure:

{_id:"xxx", userId:"yyy", a:1 ,b:2,  counter:1}    

In the test the:

"userId" value could be {1..200,000}
"a" values could be {1..30}
"b" values could be {1}

Thus my collection of maximun size will be 6,000,000
Currently there are two indexes defined for this collection : default _id and useId

The business logic queries for all user entries, and then updates one specific by incrementing the counter (the query update is written by “_id” ). Also if this is a new entity there is an insert query.

I’m running with mongo 1.8.2 on ubuntu with 8g ram

I have a master secondaries replications (all the mongo’s runs with local disk storage and in one subnetwork with tomcat server). Of course all the reads go to secondary and writes to master.
I didn’t tested sharding since i think that 6,000,000 is not a huge collection, isn’t it?

In addition i run jmetter test that generates 500 threads requests at a time with different userIds.

When i ran mongostat i see that the %locked is very high (about 70%)
after about 5-10 minutes of load i see that qw (queue for write) is 500 (as a number of my open connections)
When i stop the server it takes the mongo about 10-20 minutes to fulfill all the queued tasks

I’ve also ran db.serverStatus() and explain and the results looks fine.
when i run the db.currentOp() i see the queries that are waiting for ‘write’ lock
I could not have the output of currentOp to file to fully analyze it, because i executed the query from the commandline and had only the window buffer size. But from there i saw a lot of updates (by _id) that are waiting to write lock.

I’ll appreciate any ideas.

One more things: since each query pottentially will bring 30 documents I think there could be different moddeling as following:

{_id:"xxx", userId:"123", bs: [{b:1, cs[{c:1, cnt:1}, {c:2, cnt:1}}, {{b:2 cs: [{c:1, cnt:1}]}}]

But when i tryed this modelling, i could not increment the counter, I simply didn’t find the right way to do that. I can do insert and push bud can not update
for the following query :

db.coll.update({userId:"123", "bs.b":1, "bs.cs.c":1}, {"bs.cs.cnt" : {$inc : 1})

I have an error about the illegal ‘dot’ in the query

I’m pretty stacked by now. Waiting for some good ideas

Thanks a lot
Julia

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:05:30+00:00Added an answer on May 28, 2026 at 8:05 pm

    MongoDB has a global write lock. This means that only one of your updates can proceed at a time.

    The db.serverStatus() command can help you diagnose issues with the global write lock.

    Here are some things you can try:

    1) Make sure you’re using mongodb 2.0. It has better concurrency than older versions. 2.2 will have better concurrency yet.

    2) Queue your writes so that they are asynchronous, and perform them all using a single thread. This might help with concurrency, because generally only one thread will be attempting to use the global write lock at a time.

    3) If you’re using the latest version, and you can’t make your writes single threaded, then consider sharding. Sharding is for much more than just size; it’s at least as important for write concurrency. If you shard, then each segment will run in its own process with its own global write lock. This will allow the whole system to process more writes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup hadoop on top of mongodb using hadoop-mongodb driver. Currently I can
I currently have a MongoDB setup with a fairly large database (about 250m documents).
I am using mongoDB currently, and I am wondering what measures we should take
I'm currently using MongoDB to record application logs, and while I'm quite happy with
I am currently working on a rails app where we are using mongoid/mongoDB on
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I currently using android NDK to write some native code in C. I have
I'm running node.js on OSX and have just installed mongodb using command npm install
I'm designing an application that processes RSS feeds using MongoDB. Currently my collections are
I am currently using MongoDB's MapReduce to generate hourly ad view counts like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.