From 419633ce9df63d7964872e833faa8b603d4e0ebf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 21 Jul 2016 17:15:29 +0200 Subject: [PATCH] Server: throttle "seedAll" when starting the server --- server/initializers/constants.js | 5 +++++ server/models/video.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 7fcf5b01b..467816f2c 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -40,6 +40,10 @@ const SEARCHABLE_COLUMNS = { VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] } +// Seeds in parallel we send to electron when "seed all" +// Once a video is in seeding state we seed another video etc +const SEEDS_IN_PARALLEL = 3 + // Sortable columns per schema const SORTABLE_COLUMNS = { VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] @@ -83,6 +87,7 @@ module.exports = { REQUESTS_LIMIT: REQUESTS_LIMIT, RETRY_REQUESTS: RETRY_REQUESTS, SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, + SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, SORTABLE_COLUMNS: SORTABLE_COLUMNS, THUMBNAILS_SIZE: THUMBNAILS_SIZE, THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, diff --git a/server/models/video.js b/server/models/video.js index 98f43a06d..396aa505d 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -1,7 +1,7 @@ 'use strict' const config = require('config') -const each = require('async/each') +const eachLimit = require('async/eachLimit') const ffmpeg = require('fluent-ffmpeg') const fs = require('fs') const parallel = require('async/parallel') @@ -235,7 +235,7 @@ function seedAllExisting (callback) { listOwned.call(this, function (err, videos) { if (err) return callback(err) - each(videos, function (video, callbackEach) { + eachLimit(videos, constants.SEEDS_IN_PARALLEL, function (video, callbackEach) { const videoPath = pathUtils.join(uploadsDir, video.filename) seed(videoPath, callbackEach) }, callback) -- 2.41.0