mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 03:53:40 -05:00
Merge pull request #2858 from overleaf/sk-make-lock-timeout-configurable
Make lock timeout configurable GitOrigin-RevId: c1df72a7cae56db125e090ada75b2c56ca9853bb
This commit is contained in:
parent
c806d27b22
commit
c4ec032ffa
6 changed files with 49 additions and 7 deletions
|
@ -6,6 +6,7 @@ const logger = require('logger-sharelatex')
|
|||
const os = require('os')
|
||||
const crypto = require('crypto')
|
||||
const async = require('async')
|
||||
const settings = require('settings-sharelatex')
|
||||
|
||||
const HOST = os.hostname()
|
||||
const PID = process.pid
|
||||
|
@ -14,12 +15,22 @@ let COUNT = 0
|
|||
|
||||
const LOCK_QUEUES = new Map() // queue lock requests for each name/id so they get the lock on a first-come first-served basis
|
||||
|
||||
logger.log(
|
||||
{ lockManagerSettings: settings.lockManager },
|
||||
'LockManager initialising'
|
||||
)
|
||||
|
||||
const LockManager = {
|
||||
LOCK_TEST_INTERVAL: 50, // 50ms between each test of the lock
|
||||
MAX_TEST_INTERVAL: 1000, // back off to 1s between each test of the lock
|
||||
MAX_LOCK_WAIT_TIME: 10000, // 10s maximum time to spend trying to get the lock
|
||||
REDIS_LOCK_EXPIRY: 30, // seconds. Time until lock auto expires in redis
|
||||
SLOW_EXECUTION_THRESHOLD: 5000, // 5s, if execution takes longer than this then log
|
||||
// ms between each test of the lock
|
||||
LOCK_TEST_INTERVAL: settings.lockManager.lockTestInterval || 50,
|
||||
// back off to ms between each test of the lock
|
||||
MAX_TEST_INTERVAL: settings.lockManager.maxTestInterval || 1000,
|
||||
// ms maximum time to spend trying to get the lock
|
||||
MAX_LOCK_WAIT_TIME: settings.lockManager.maxLockWaitTime || 10000,
|
||||
// seconds. Time until lock auto expires in redis
|
||||
REDIS_LOCK_EXPIRY: settings.lockManager.redisLockExpiry || 30,
|
||||
// ms, if execution takes longer than this then log
|
||||
SLOW_EXECUTION_THRESHOLD: settings.lockManager.slowExecutionThreshold || 5000,
|
||||
|
||||
// Use a signed lock value as described in
|
||||
// http://redis.io/topics/distlock#correct-implementation-with-a-single-instance
|
||||
|
|
|
@ -27,6 +27,11 @@ else
|
|||
user: undefined
|
||||
pass: undefined
|
||||
|
||||
intFromEnv = (name, defaultValue) ->
|
||||
if defaultValue in [null, undefined] or typeof defaultValue != 'number'
|
||||
throw new Error("Bad default integer value for setting: #{name}, #{defaultValue}")
|
||||
parseInt(process.env[name], 10) || defaultValue
|
||||
|
||||
module.exports = settings =
|
||||
|
||||
allowAnonymousReadAndWriteSharing:
|
||||
|
@ -190,6 +195,12 @@ module.exports = settings =
|
|||
# that are sent out, generated links, etc.
|
||||
siteUrl : siteUrl = process.env['PUBLIC_URL'] or 'http://localhost:3000'
|
||||
|
||||
lockManager:
|
||||
lockTestInterval: intFromEnv('LOCK_MANAGER_LOCK_TEST_INTERVAL', 50)
|
||||
maxTestInterval: intFromEnv('LOCK_MANAGER_MAX_TEST_INTERVAL', 1000)
|
||||
maxLockWaitTime: intFromEnv('LOCK_MANAGER_MAX_LOCK_WAIT_TIME', 10000)
|
||||
redisLockExpiry: intFromEnv('LOCK_MANAGER_REDIS_LOCK_EXPIRY', 30)
|
||||
slowExecutionThreshold: intFromEnv('LOCK_MANAGER_SLOW_EXECUTION_THRESHOLD', 5000)
|
||||
|
||||
# Used to close the editor off to users
|
||||
editorIsOpen: process.env['EDITOR_IS_OPEN'] or true
|
||||
|
|
|
@ -23,6 +23,7 @@ services:
|
|||
PROJECT_HISTORY_ENABLED: 'true'
|
||||
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
||||
LINKED_URL_PROXY: 'http://localhost:6543'
|
||||
LOCK_MANAGER_MAX_LOCK_WAIT_TIME: 30000
|
||||
NODE_ENV: test
|
||||
SHARELATEX_CONFIG:
|
||||
command: npm run test:acceptance:app
|
||||
|
|
|
@ -32,6 +32,7 @@ services:
|
|||
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
||||
MOCHA_GREP: ${MOCHA_GREP}
|
||||
NODE_ENV: test
|
||||
LOCK_MANAGER_MAX_LOCK_WAIT_TIME: 30000
|
||||
# SHARELATEX_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING: 'true'
|
||||
SHARELATEX_CONFIG:
|
||||
command: npm run test:acceptance:app
|
||||
|
|
|
@ -38,7 +38,16 @@ describe('LockManager - getting the lock', function() {
|
|||
return { auth() {} }
|
||||
}
|
||||
},
|
||||
'settings-sharelatex': { redis: {} },
|
||||
'settings-sharelatex': {
|
||||
redis: {},
|
||||
lockManager: {
|
||||
lockTestInterval: 50,
|
||||
maxTestInterval: 1000,
|
||||
maxLockWaitTime: 10000,
|
||||
redisLockExpiry: 30,
|
||||
slowExecutionThreshold: 5000
|
||||
}
|
||||
},
|
||||
'metrics-sharelatex': {
|
||||
inc() {},
|
||||
gauge() {}
|
||||
|
|
|
@ -38,7 +38,16 @@ describe('LockManager - trying the lock', function() {
|
|||
}
|
||||
}
|
||||
},
|
||||
'settings-sharelatex': { redis: {} },
|
||||
'settings-sharelatex': {
|
||||
redis: {},
|
||||
lockManager: {
|
||||
lockTestInterval: 50,
|
||||
maxTestInterval: 1000,
|
||||
maxLockWaitTime: 10000,
|
||||
redisLockExpiry: 30,
|
||||
slowExecutionThreshold: 5000
|
||||
}
|
||||
},
|
||||
'metrics-sharelatex': {
|
||||
inc() {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue