在MEAN堆栈应用程序中的Mongodb批量操作中获取连接超时错误

时间:2016-10-17 15:02:52

标签: node.js mongodb mean-stack

我正在MEAN Stack中开发一个Web应用程序,不幸的是遇到了这个错误。

The mongodb version used is: "3.0.10"

机器规格如下: 具有相同conf的四核处理器

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 63
model name  : Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
stepping    : 2
microcode   : 0x25
cpu MHz     : 2900.022
cache size  : 25600 KB
physical id : 0
siblings    : 4
core id     : 1
cpu cores   : 2
apicid      : 3
initial apicid  : 3
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm xsaveopt fsgsbase bmi1 avx2 smep bmi2 erms invpcid
bogomips    : 5800.04
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management: 

我在MongoDb中运行批处理查询,但是在执行批处理查询时我收到此错误,

{ name: 'MongoError', message: 'connection 5 to localhost:27017 timed out' } undefined

同步运行这3个批处理查询,批处理查询的代码是:

var User_Earning_Buckets = db.collection('userearningbuckets');
var Users = db.collection('users');
var Admin_Account_Details = db.collection('admin_account_details');

var User_Earning_Buckets_Batch = User_Earning_Buckets.initializeOrderedBulkOp();
var Users_Batch = Users.initializeOrderedBulkOp();
var Admin_Account_Details_Batch = Admin_Account_Details.initializeOrderedBulkOp();

function(...) //running queries for batch query


Users_Batch.execute(function(err,resUsers){
        Admin_Account_Details_Batch.execute(function(err,resAdmin){
          User_Earning_Buckets_Batch.execute(function(err,resUserEarning){
            console.log("Batch Execution Completed")
          });
        });
      });

每批次的查询数量约为。 10,000个查询。

db连接字符串是:

var options = {server: {socketOptions: {connectTimeoutMS: 30000,keepAlive:3000}},replSet: {},mongos: {},auto_reconnect: true,poolSize: 500};
var url = "mongodb://admin:admin@localhost:27017/testDb"
MongoClient.connect(url,options, function(err,db) {})

日志文件中的最后一行是:

MMAPV1Journal: { acquireCount: { w: 293 }, acquireWaitCount: { w: 96 }, timeAcquiringMicros: { w: 1467324 } }, Database: { acquireCount: { w: 192 } }, Collection: { acquireCount: { W: 192 }, acquireWaitCount: { W: 5 }, timeAcquiringMicros: { W: 263 } } } 155ms
2016-10-17T20:15:48.034+0530 I WRITE    [conn46] update Weone.admin_account_details query: { deleted: false } update: { $inc: { total_balance: 0.6000000000000001 }, $push: { earning_details: { date: new Date(1476714915149), amount: 0.6000000000000001, user_id: ObjectId('57419cfa4d7acd5f7f6af1ca') } } } nscanned:0 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:0 writeConflicts:0 numYields:1 locks:{ Global: { acquireCount: { r: 194, w: 194 } }, MMAPV1Journal: { acquireCount: { w: 296 }, acquireWaitCount: { w: 97 }, timeAcquiringMicros: { w: 1470956 } }, Database: { acquireCount: { w: 194 } }, Collection: { acquireCount: { W: 194 }, acquireWaitCount: { W: 5 }, timeAcquiringMicros: { W: 263 } } } 158ms
2016-10-17T20:15:48.191+0530 I WRITE    [conn46] update Weone.admin_account_details query: { deleted: false } update: { $inc: { total_balance: 0.6000000000000001 }, $push: { earning_details: { date: new Date(1476714915245), amount: 0.6000000000000001, user_id: ObjectId('57ac2cfbc60086654b79d677') } } } nscanned:0 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:0 writeConflicts:0 numYields:1 locks:{ Global: { acquireCount: { r: 196, w: 196 } }
MMAPV1Journal: { acquireCount: { w: 299 }, acquireWaitCount: { w: 98 }, timeAcquiringMicros: { w: 1474765 } }, Database: { acquireCount: { w: 196 } }, Collection: { acquireCount: { W: 196 }, acquireWaitCount: { W: 5 }, timeAcquiringMicros: { W: 263 } } } 156ms
2016-10-17T20:15:48.344+0530 I WRITE    [conn46] update Weone.admin_account_details query: { deleted: false } update: { $inc: { total_balance: 0.6000000000000001 }, $push: { earning_details: { date: new Date(1476714915457), amount: 0.6000000000000001, user_id: ObjectId('57641f90dca8b0f82f4efe7b') } } } nscanned:0 nscannedObjects:1 nMatched:1 nModified:1 keyUpdates:0 writeConflicts:0 numYields:1 locks:{ Global: { acquireCount: { r: 198, w: 198 } }, MMAPV1Journal: { acquireCount: { w: 302 }, acquireWaitCount: { w: 99 }, timeAcquiringMicros: { w: 1478352 } }, Database: { acquireCount: { w: 198 } }, Collection: { acquireCount: { W: 198 }, acquireWaitCount: { W: 5 }, timeAcquiringMicros: { W: 263 } } } 153ms
2016-10-17T20:15:48.480+0530
.
.
.
.
2016-10-17T19:40:34.921+0530 I COMMAND  [conn15] command Weone.$cmd command: update { update: "userearningbuckets", updates: 924, ordered: true } ntoreturn:1 keyUpdates:0 writeConflicts:0 numYields:0 reslen:55 locks:{ Global: { acquireCount: { r: 330735, w: 330735 } }, MMAPV1Journal: { acquireCount: { w: 331668 }, acquireWaitCount: { w: 419 }, timeAcquiringMicros: { w: 15616100 } }, Database: { acquireCount: { w: 330735 } }, Collection: { acquireCount: { W: 330735 }, acquireWaitCount: { W: 9 }, timeAcquiringMicros: { W: 459 } } } 58579ms 2016-10-17T19:40:34.921+0530 I NETWORK  [conn15] end connection 127.0.0.1:35354 (2 connections now open)

mongo中的db.serverStatus()返回以下参数

{
"host" : "rajat.katiyar",
"version" : "3.0.10",
"process" : "mongod",
"pid" : NumberLong(979),
"uptime" : 743,
"uptimeMillis" : NumberLong(742628),
"uptimeEstimate" : 732,
"localTime" : ISODate("2016-10-17T14:14:04.477Z"),
"asserts" : {
    "regular" : 0,
    "warning" : 0,
    "msg" : 0,
    "user" : 3,
    "rollovers" : 0
},
"backgroundFlushing" : {
    "flushes" : 12,
    "total_ms" : 5299,
    "average_ms" : 441.5833333333333,
    "last_ms" : 40,
    "last_finished" : ISODate("2016-10-17T14:13:42.086Z")
},
"connections" : {
    "current" : 3,
    "available" : 51197,
    "totalCreated" : NumberLong(16)
},
"cursors" : {
    "note" : "deprecated, use server status metrics",
    "clientCursors_size" : 0,
    "totalOpen" : 0,
    "pinned" : 0,
    "totalNoTimeout" : 0,
    "timedOut" : 0
},
"dur" : {
    "commits" : 30,
    "journaledMB" : 0,
    "writeToDataFilesMB" : 0,
    "compression" : 0,
    "commitsInWriteLock" : 0,
    "earlyCommits" : 0,
    "timeMs" : {
        "dt" : 3069,
        "prepLogBuffer" : 0,
        "writeToJournal" : 0,
        "writeToDataFiles" : 0,
        "remapPrivateView" : 0,
        "commits" : 0,
        "commitsInWriteLock" : 0
    }
},
"extra_info" : {
    "note" : "fields vary by platform",
    "heap_usage_bytes" : 78570688,
    "page_faults" : 523
},
"globalLock" : {
    "totalTime" : NumberLong(742627000),
    "currentQueue" : {
        "total" : 0,
        "readers" : 0,
        "writers" : 0
    },
    "activeClients" : {
        "total" : 11,
        "readers" : 0,
        "writers" : 0
    }
},
"locks" : {
    "Global" : {
        "acquireCount" : {
            "r" : NumberLong(969820),
            "w" : NumberLong(895699),
            "W" : NumberLong(5)
        },
        "acquireWaitCount" : {
            "r" : NumberLong(1),
            "W" : NumberLong(1)
        },
        "timeAcquiringMicros" : {
            "r" : NumberLong(86),
            "W" : NumberLong(4)
        }
    },
    "MMAPV1Journal" : {
        "acquireCount" : {
            "r" : NumberLong(37117),
            "w" : NumberLong(917279),
            "R" : NumberLong(6916),
            "W" : NumberLong(88)
        },
        "acquireWaitCount" : {
            "w" : NumberLong(1777),
            "R" : NumberLong(875)
        },
        "timeAcquiringMicros" : {
            "w" : NumberLong(67252788),
            "R" : NumberLong(27251835)
        }
    },
    "Database" : {
        "acquireCount" : {
            "r" : NumberLong(37043),
            "w" : NumberLong(895580),
            "R" : NumberLong(15),
            "W" : NumberLong(125)
        }
    },
    "Collection" : {
        "acquireCount" : {
            "R" : NumberLong(38267),
            "W" : NumberLong(895580)
        },
        "acquireWaitCount" : {
            "R" : NumberLong(61),
            "W" : NumberLong(162)
        },
        "timeAcquiringMicros" : {
            "R" : NumberLong(1269692),
            "W" : NumberLong(366083)
        }
    },
    "Metadata" : {
        "acquireCount" : {
            "W" : NumberLong(6)
        }
    }
},
"network" : {
    "bytesIn" : NumberLong(4596144),
    "bytesOut" : NumberLong(35543142),
    "numRequests" : NumberLong(3102)
},
"opcounters" : {
    "insert" : 17078,
    "query" : 2634,
    "update" : 4084,
    "delete" : 0,
    "getmore" : 177,
    "command" : 269
},
"opcountersRepl" : {
    "insert" : 0,
    "query" : 0,
    "update" : 0,
    "delete" : 0,
    "getmore" : 0,
    "command" : 0
},
"storageEngine" : {
    "name" : "mmapv1"
},
"writeBacksQueued" : false,
"mem" : {
    "bits" : 64,
    "resident" : 453,
    "virtual" : 10677,
    "supported" : true,
    "mapped" : 5167,
    "mappedWithJournal" : 10334
},
"metrics" : {
    "commands" : {
        "createIndexes" : {
            "failed" : NumberLong(3),
            "total" : NumberLong(3)
        },
        "distinct" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(2)
        },
        "getLog" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(1)
        },
        "insert" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(18)
        },
        "isMaster" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(209)
        },
        "listIndexes" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(6)
        },
        "replSetGetStatus" : {
            "failed" : NumberLong(1),
            "total" : NumberLong(1)
        },
        "saslContinue" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(30)
        },
        "saslStart" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(15)
        },
        "serverStatus" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(1)
        },
        "update" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(6)
        },
        "whatsmyuri" : {
            "failed" : NumberLong(0),
            "total" : NumberLong(1)
        }
    },
    "cursor" : {
        "timedOut" : NumberLong(0),
        "open" : {
            "noTimeout" : NumberLong(0),
            "pinned" : NumberLong(0),
            "total" : NumberLong(0)
        }
    },
    "document" : {
        "deleted" : NumberLong(0),
        "inserted" : NumberLong(17078),
        "returned" : NumberLong(183933),
        "updated" : NumberLong(4084)
    },
    "getLastError" : {
        "wtime" : {
            "num" : 0,
            "totalMillis" : 0
        },
        "wtimeouts" : NumberLong(0)
    },
    "operation" : {
        "fastmod" : NumberLong(1848),
        "idhack" : NumberLong(188),
        "scanAndOrder" : NumberLong(0),
        "writeConflicts" : NumberLong(0)
    },
    "queryExecutor" : {
        "scanned" : NumberLong(6249),
        "scannedObjects" : NumberLong(114198998)
    },
    "record" : {
        "moves" : NumberLong(53)
    },
    "repl" : {
        "apply" : {
            "batches" : {
                "num" : 0,
                "totalMillis" : 0
            },
            "ops" : NumberLong(0)
        },
        "buffer" : {
            "count" : NumberLong(0),
            "maxSizeBytes" : 268435456,
            "sizeBytes" : NumberLong(0)
        },
        "network" : {
            "bytes" : NumberLong(0),
            "getmores" : {
                "num" : 0,
                "totalMillis" : 0
            },
            "ops" : NumberLong(0),
            "readersCreated" : NumberLong(0)
        },
        "preload" : {
            "docs" : {
                "num" : 0,
                "totalMillis" : 0
            },
            "indexes" : {
                "num" : 0,
                "totalMillis" : 0
            }
        }
    },
    "storage" : {
        "freelist" : {
            "search" : {
                "bucketExhausted" : NumberLong(0),
                "requests" : NumberLong(17240),
                "scanned" : NumberLong(0)
            }
        }
    },
    "ttl" : {
        "deletedDocuments" : NumberLong(0),
        "passes" : NumberLong(12)
    }
},
"ok" : 1
}

请有人帮助我,提前谢谢。

0 个答案:

没有答案