-
Notifications
You must be signed in to change notification settings - Fork 2
/
concurrency.js
25 lines (19 loc) · 959 Bytes
/
concurrency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var os = require('os');
var semaphore = require('semaphore');
var log = require('./log');
var maxConcurrentProxyStreams = process.env['MAX_CONCURRENT_PROXY_STREAMS'] || 20;
var proxyStreamsSemaphore = semaphore(maxConcurrentProxyStreams);
log.info("Maximum concurrent proxy streams: " + maxConcurrentProxyStreams);
// If maxConcurrentManipulations is not provided, default to the number of CPUs.
// This is recommended for best performance anyway, so most users will not need
// to override this.
var maxConcurrentManipulations = process.env['MAX_CONCURRENT_MANIPULATIONS'];
if (typeof(maxConcurrentManipulations) === 'undefined') {
maxConcurrentManipulations = os.cpus().length;
}
var manipulationsSemaphore = semaphore(maxConcurrentManipulations);
log.info('Maximum concurrent manipulations: ' + maxConcurrentManipulations);
module.exports = {
proxyStreamsSemaphore: proxyStreamsSemaphore,
manipulationsSemaphore: manipulationsSemaphore
};