From b359546358c39b839867ca920e10221979c65424 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Jul 2016 19:59:01 +0200 Subject: [PATCH] Server: limit actions for each request between pods --- server/initializers/constants.js | 4 ++++ server/models/request.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 55c555d04..32fe1645f 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -24,6 +24,9 @@ const PODS_SCORE = { // Number of requests in parallel we can make const REQUESTS_IN_PARALLEL = 10 +// How many requests we put in request (request scheduler) +const REQUESTS_LIMIT = 10 + // Number of requests to retry for replay requests module const RETRY_REQUESTS = 5 @@ -71,6 +74,7 @@ module.exports = { PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, PODS_SCORE: PODS_SCORE, REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, + REQUESTS_LIMIT: REQUESTS_LIMIT, RETRY_REQUESTS: RETRY_REQUESTS, SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, SORTABLE_COLUMNS: SORTABLE_COLUMNS, diff --git a/server/models/request.js b/server/models/request.js index 7fdf5bd31..248ab3303 100644 --- a/server/models/request.js +++ b/server/models/request.js @@ -102,7 +102,7 @@ function makeRequest (toPod, requestsToMake, callback) { function makeRequests () { const self = this - list.call(self, function (err, requests) { + listWithLimit.call(self, constants.REQUESTS_LIMIT, function (err, requests) { if (err) { logger.error('Cannot get the list of requests.', { err: err }) return // Abort @@ -269,8 +269,8 @@ function updatePodsScore (goodPods, badPods) { }) } -function list (callback) { - this.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).exec(callback) +function listWithLimit (limit, callback) { + this.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).limit(limit).exec(callback) } function removeAll (callback) {