mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add rate limits for autocompiles
global rate limit for all users and a lower rate limit for free users
This commit is contained in:
parent
cab3efd77c
commit
d14723f24a
1 changed files with 38 additions and 8 deletions
|
@ -34,12 +34,16 @@ module.exports = CompileManager =
|
|||
return callback(error) if error?
|
||||
for key, value of limits
|
||||
options[key] = value
|
||||
# only pass user_id down to clsi if this is a per-user compile
|
||||
compileAsUser = if Settings.disablePerUserCompiles then undefined else user_id
|
||||
ClsiManager.sendRequest project_id, compileAsUser, options, (error, status, outputFiles, clsiServerId, validationProblems) ->
|
||||
return callback(error) if error?
|
||||
logger.log files: outputFiles, "output files"
|
||||
callback(null, status, outputFiles, clsiServerId, limits, validationProblems)
|
||||
# Put a lower limit on autocompiles for free users
|
||||
CompileManager._checkIfFreeAutoCompileLimitHasBeenHit options.isAutoCompile, limits.compileGroup, (err, canCompile)->
|
||||
if !canCompile
|
||||
return callback null, "autocompile-backoff", []
|
||||
# only pass user_id down to clsi if this is a per-user compile
|
||||
compileAsUser = if Settings.disablePerUserCompiles then undefined else user_id
|
||||
ClsiManager.sendRequest project_id, compileAsUser, options, (error, status, outputFiles, clsiServerId, validationProblems) ->
|
||||
return callback(error) if error?
|
||||
logger.log files: outputFiles, "output files"
|
||||
callback(null, status, outputFiles, clsiServerId, limits, validationProblems)
|
||||
|
||||
|
||||
stopCompile: (project_id, user_id, callback = (error) ->) ->
|
||||
|
@ -75,15 +79,41 @@ module.exports = CompileManager =
|
|||
_checkIfAutoCompileLimitHasBeenHit: (isAutoCompile, callback = (err, canCompile)->)->
|
||||
if !isAutoCompile
|
||||
return callback(null, true)
|
||||
opts =
|
||||
Metrics.inc "auto-compile"
|
||||
opts =
|
||||
endpointName:"auto_compile"
|
||||
timeInterval:20
|
||||
subjectName:"everyone"
|
||||
throttle: 25
|
||||
throttle: 200
|
||||
rateLimiter.addCount opts, (err, canCompile)->
|
||||
if err?
|
||||
canCompile = false
|
||||
logger.log canCompile:canCompile, opts:opts, "checking if auto compile limit has been hit"
|
||||
if !canCompile
|
||||
Metrics.inc "auto-compile-rate-limited"
|
||||
callback err, canCompile
|
||||
|
||||
|
||||
_checkIfFreeAutoCompileLimitHasBeenHit: (isAutoCompile, compileGroup, callback = (err, canCompile)->)->
|
||||
if !isAutoCompile
|
||||
return callback(null, true)
|
||||
|
||||
if compileGroup is "priority"
|
||||
Metrics.inc "auto-compile-priority"
|
||||
return callback(null, true)
|
||||
|
||||
Metrics.inc "auto-compile-free"
|
||||
opts =
|
||||
endpointName:"auto_compile"
|
||||
timeInterval:20
|
||||
subjectName:"free"
|
||||
throttle: 100
|
||||
rateLimiter.addCount opts, (err, canCompile)->
|
||||
if err?
|
||||
canCompile = false
|
||||
logger.log canCompile:canCompile, opts:opts, "checking if free users auto compile limit has been hit"
|
||||
if !canCompile
|
||||
Metrics.inc "auto-compile-free-rate-limited"
|
||||
callback err, canCompile
|
||||
|
||||
_ensureRootDocumentIsSet: (project_id, callback = (error) ->) ->
|
||||
|
|
Loading…
Reference in a new issue