From: Chocobozzz Date: Wed, 6 Jul 2016 17:59:01 +0000 (+0200) Subject: Server: limit actions for each request between pods X-Git-Tag: v0.0.1-alpha~836 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b359546358c39b839867ca920e10221979c65424;p=oweals%2Fpeertube.git Server: limit actions for each request between pods --- 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) {