Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10738

Why is my mongodb so slow?

      Our company produces environment uses mongodb as a web database, but I found us a simple query or update (with index) will be a few hundred ms time-consuming, and some even more. Was not what we use right?

      Here is the log part (most of them are like this):

      Wed Sep 11 16:47:36.187 [conn46044] update sandbox.status_5167852c208eb5a2f1c2b260_201309 query:

      { _id: "244593027441387" }

      update: { $set:

      { rcount: 10, hot: true, ccount: 2 }

      } nscanned:1 nupdated:1 keyUpdates:0 locks(micros) w:614810 614ms
      Wed Sep 11 16:47:36.187 [conn24456] update sandbox.status query:

      { _id: "333820030946999" }

      update: { $set:

      { rsince_timestamp: 1378873552 }

      , $inc:

      { sm_flash_factor: 0, repost_count: 0 }

      } idhack:1 nupdated:1 fastmod:1 keyUpdates:0 locks(micros) w:123 554ms
      Wed Sep 11 16:47:36.188 [conn24054] update sandbox.influence query:

      { date: new Date(1378857600000), id: "ftchinese" }

      update: { $inc:

      { nctc: 0 }

      } nscanned:1 nupdated:1 fastmod:1 keyUpdates:0 locks(micros) w:169 521ms
      Wed Sep 11 16:47:36.188 [conn39887] insert sandbox.follow_relations ninserted:1 keyUpdates:0 locks(micros) w:120 488ms
      Wed Sep 11 16:47:45.104 [conn40782] update sandbox.status_50054a70b3158aa4709ebfc5_201309 query:

      { _id: "228751112143775" }

      update: { $set:

      { rcount: 0, hot: false, ccount: 0 }

      } nscanned:1 nupdated:1 keyUpdates:0 locks(micros) w:397837 397ms
      Wed Sep 11 16:47:45.104 [conn39887] update sandbox.followers query:

      { _id: "lonetan" }

      update: { $set: { id: "lonestan", city: "", verified: false, activeness: 0.005800625374694182, followers_count: 167, status_created_at: new Date(1251590400000), location: "unkown", province: "31", description: "", friends_count: 1277, tags: {}, profile_image_url: "http://mat1.gtimg.com/www/mb/images/head_50.jpg", sm_flwr_quality: 0.002194834672492721, screen_name: "longes", supdate_time: new Date(1378857600000), favourites_count: 0, name: "lonetan", url: "http://www.google.com/", gender: "m", created_at: new Date(1251590400000) }, $addToSet:

      { sm_uids: "htcwildfire" }

      } nscanned:1 nupdated:1 keyUpdates:0 locks(micros) w:446 342ms

      example the first line. you can see ocks(micros) w:614810 and use 614ms!! this is indexes:
      > db.status_5167852c208eb5a2f1c2b260_201309.getIndexes()
      [
      {
      "v" : 1,
      "key" :

      { "_id" : 1 }

      ,
      "ns" : "sandbox.status_5167852c208eb5a2f1c2b260_201309",
      "name" : "id"
      },
      {
      "v" : 1,
      "key" :

      { "cdate" : -1 }

      ,
      "ns" : "sandbox.status_5167852c208eb5a2f1c2b260_201309",
      "name" : "cdate_-1"
      },
      {
      "v" : 1,
      "key" :

      { "idate" : -1 }

      ,
      "ns" : "sandbox.status_5167852c208eb5a2f1c2b260_201309",
      "name" : "idate_-1"
      }
      ]

      > db.status_5167852c208eb5a2f1c2b260_201309.find({_id: "244593027441387"}).explain()
      {
      "cursor" : "BtreeCursor id",
      "isMultiKey" : false,
      "n" : 1,
      "nscannedObjects" : 1,
      "nscanned" : 1,
      "nscannedObjectsAllPlans" : 1,
      "nscannedAllPlans" : 1,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "millis" : 0,
      "indexBounds" : {
      "start" :

      { "_id" : "244593027441387" }

      ,
      "end" :

      { "_id" : "244593027441387" }

      },
      "server" : "bj-43:27018"
      }

      the collection has 17384 entry.

      > db.status_5167852c208eb5a2f1c2b260_201309.find().count()
      17384

      > db.status_5167852c208eb5a2f1c2b260_201309.stats()
      {
      "ns" : "sandbox_opinion.status_5167852c208eb5a2f1c2b260_201309",
      "count" : 17384,
      "size" : 29005104,
      "avgObjSize" : 1668.4942475839853,
      "storageSize" : 37797888,
      "numExtents" : 8,
      "nindexes" : 3,
      "lastExtentSize" : 15290368,
      "paddingFactor" : 1.0040000000002294,
      "systemFlags" : 1,
      "userFlags" : 0,
      "totalIndexSize" : 1970416,
      "indexSizes" :

      { "_id_" : 948416, "cdate_-1" : 506912, "idate_-1" : 515088 }

      ,
      "ok" : 1
      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            dongwm dongweiming
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: