diff --git a/src/database/mongo/connection.js b/src/database/mongo/connection.js index 2f5d64e714..b5c375b4e6 100644 --- a/src/database/mongo/connection.js +++ b/src/database/mongo/connection.js @@ -44,7 +44,7 @@ connection.getConnectionString = function (mongo) { connection.getConnectionOptions = function (mongo) { mongo = mongo || nconf.get('mongo'); const connOptions = { - maxPoolSize: 10, + maxPoolSize: 20, minPoolSize: 3, connectTimeoutMS: 90000, }; diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 9dbf947b1a..4a8bbc691d 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -574,7 +574,7 @@ module.exports = function (module) { if (processFn && processFn.constructor && processFn.constructor.name !== 'AsyncFunction') { processFn = util.promisify(processFn); } - + let iteration = 1; while (!done) { /* eslint-disable no-await-in-loop */ const item = await cursor.next(); @@ -585,12 +585,12 @@ module.exports = function (module) { } if (ids.length >= options.batch || (done && ids.length !== 0)) { - await processFn(ids); - - ids.length = 0; - if (options.interval) { + if (iteration > 1 && options.interval) { await sleep(options.interval); } + await processFn(ids); + iteration += 1; + ids.length = 0; } } }; diff --git a/src/database/postgres/connection.js b/src/database/postgres/connection.js index 54cdc5ebee..19d796d7ed 100644 --- a/src/database/postgres/connection.js +++ b/src/database/postgres/connection.js @@ -28,6 +28,8 @@ connection.getConnectionOptions = function (postgres) { password: postgres.password, database: postgres.database, ssl: String(postgres.ssl) === 'true', + max: 20, + connectionTimeoutMillis: 90000, }; return _.merge(connOptions, postgres.options || {}); diff --git a/src/database/postgres/sorted.js b/src/database/postgres/sorted.js index 70e66af314..2b707a3a7d 100644 --- a/src/database/postgres/sorted.js +++ b/src/database/postgres/sorted.js @@ -677,7 +677,7 @@ SELECT z."value", z."score" if (process && process.constructor && process.constructor.name !== 'AsyncFunction') { process = util.promisify(process); } - + let iteration = 1; while (true) { /* eslint-disable no-await-in-loop */ let rows = await cursor.readAsync(batchSize); @@ -692,14 +692,15 @@ SELECT z."value", z."score" rows = rows.map(r => r.value); } try { + if (iteration > 1 && options.interval) { + await sleep(options.interval); + } await process(rows); + iteration += 1; } catch (err) { await client.release(); throw err; } - if (options.interval) { - await sleep(options.interval); - } } }; };