From 19e41af82a42d04e9bb987ef3aa545e6174c21b1 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Wed, 16 Oct 2013 14:21:01 -0700 Subject: [PATCH] Only use one connection for oplog tailing. --- packages/mongo-livedata/mongo_driver.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/mongo-livedata/mongo_driver.js b/packages/mongo-livedata/mongo_driver.js index 3c1ccbe8ce..b4b908df21 100644 --- a/packages/mongo-livedata/mongo_driver.js +++ b/packages/mongo-livedata/mongo_driver.js @@ -113,13 +113,13 @@ MongoConnection = function (url, options) { self._connectCallbacks = []; self._liveResultsSets = {}; - var mongoOptions = {db: {safe: true}}; + var mongoOptions = {db: {safe: true}, server: {}}; // Set autoReconnect to true, unless passed on the URL. Why someone // would want to set autoReconnect to false, I'm not really sure, but // keeping this for backwards compatibility for now. if (!(/[\?&]auto_?[rR]econnect=/.test(url))) { - mongoOptions.server = {auto_reconnect: true}; + mongoOptions.server.auto_reconnect = true; } // Disable the native parser by default, unless specifically enabled @@ -134,6 +134,12 @@ MongoConnection = function (url, options) { mongoOptions.db.native_parser = false; } + // XXX maybe we should have a better way of allowing users to configure the + // underlying Mongo driver + if (_.has(options, 'poolSize')) { + mongoOptions.server.poolSize = 1; + } + MongoDB.connect(url, mongoOptions, function(err, db) { if (err) throw err; @@ -332,8 +338,10 @@ MongoConnection.prototype._startOplogTailing = function (oplogUrl, dbName) { // passed). So if the connection pool used for tailing cursors is the same // pool used for other queries, the other queries will be delayed by seconds // 1/5 of the time. - // XXX set the pool size for oplogTailConnection to 1 - oplogTailConnection = new MongoConnection(oplogUrl); + // + // The tail connection will only ever be running a single tail command, so + // it only needs to make one underlying TCP connection. + oplogTailConnection = new MongoConnection(oplogUrl, {poolSize: 1}); oplogQueryConnection = new MongoConnection(oplogUrl); // Find the last oplog entry. Blocks until the connection is ready.