mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #69 from overleaf/ho-drain-connections-timewindow
add shutdownDrainTimeWindow, drains all connections within time range
This commit is contained in:
commit
fa94e3d5e3
4 changed files with 29 additions and 14 deletions
|
@ -116,17 +116,10 @@ shutdownCleanly = (signal) ->
|
||||||
shutdownCleanly(signal)
|
shutdownCleanly(signal)
|
||||||
, 10000
|
, 10000
|
||||||
|
|
||||||
forceDrain = ->
|
|
||||||
logger.log {delay_ms:Settings.forceDrainMsDelay}, "starting force drain after timeout"
|
|
||||||
setTimeout ()->
|
|
||||||
logger.log "starting drain"
|
|
||||||
DrainManager.startDrain(io, 4)
|
|
||||||
, Settings.forceDrainMsDelay
|
|
||||||
|
|
||||||
shutDownInProgress = false
|
shutDownInProgress = false
|
||||||
if Settings.forceDrainMsDelay?
|
if Settings.shutdownDrainTimeWindow?
|
||||||
Settings.forceDrainMsDelay = parseInt(Settings.forceDrainMsDelay, 10)
|
Settings.forceDrainMsDelay = parseInt(Settings.shutdownDrainTimeWindow, 10)
|
||||||
logger.log forceDrainMsDelay: Settings.forceDrainMsDelay,"forceDrainMsDelay enabled"
|
logger.log shutdownDrainTimeWindow: Settings.shutdownDrainTimeWindow,"shutdownDrainTimeWindow enabled"
|
||||||
for signal in ['SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGABRT']
|
for signal in ['SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGABRT']
|
||||||
process.on signal, ->
|
process.on signal, ->
|
||||||
if shutDownInProgress
|
if shutDownInProgress
|
||||||
|
@ -134,9 +127,9 @@ if Settings.forceDrainMsDelay?
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
shutDownInProgress = true
|
shutDownInProgress = true
|
||||||
logger.log signal: signal, "received interrupt, cleaning up"
|
logger.log signal: signal, "received interrupt, starting drain over #{Settings.shutdownDrainTimeWindow} mins"
|
||||||
|
DrainManager.startDrainTimeWindow(io, Settings.shutdownDrainTimeWindow)
|
||||||
shutdownCleanly(signal)
|
shutdownCleanly(signal)
|
||||||
forceDrain()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
|
|
||||||
module.exports =
|
module.exports = DrainManager =
|
||||||
|
|
||||||
|
startDrainTimeWindow: (io, minsToDrain)->
|
||||||
|
drainPerMin = io.sockets.clients().length / minsToDrain
|
||||||
|
DrainManager.startDrain(io, Math.max(drainPerMin / 60, 4)) # enforce minimum drain rate
|
||||||
|
|
||||||
startDrain: (io, rate) ->
|
startDrain: (io, rate) ->
|
||||||
# Clear out any old interval
|
# Clear out any old interval
|
||||||
clearInterval @interval
|
clearInterval @interval
|
||||||
|
|
|
@ -48,7 +48,7 @@ settings =
|
||||||
|
|
||||||
max_doc_length: 2 * 1024 * 1024 # 2mb
|
max_doc_length: 2 * 1024 * 1024 # 2mb
|
||||||
|
|
||||||
forceDrainMsDelay: process.env['FORCE_DRAIN_MS_DELAY'] or false
|
shutdownDrainTimeWindow: process.env['SHUTDOWN_DRAIN_TIME_WINDOW'] or 9
|
||||||
|
|
||||||
continualPubsubTraffic: process.env['CONTINUAL_PUBSUB_TRAFFIC'] or false
|
continualPubsubTraffic: process.env['CONTINUAL_PUBSUB_TRAFFIC'] or false
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,23 @@ describe "DrainManager", ->
|
||||||
sockets:
|
sockets:
|
||||||
clients: sinon.stub()
|
clients: sinon.stub()
|
||||||
|
|
||||||
|
describe "startDrainTimeWindow", ->
|
||||||
|
beforeEach ->
|
||||||
|
@clients = []
|
||||||
|
for i in [0..5399]
|
||||||
|
@clients[i] = {
|
||||||
|
id: i
|
||||||
|
emit: sinon.stub()
|
||||||
|
}
|
||||||
|
@io.sockets.clients.returns @clients
|
||||||
|
@DrainManager.startDrain = sinon.stub()
|
||||||
|
|
||||||
|
it "should set a drain rate fast enough", (done)->
|
||||||
|
@DrainManager.startDrainTimeWindow(@io, 9)
|
||||||
|
@DrainManager.startDrain.calledWith(@io, 10).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
describe "reconnectNClients", ->
|
describe "reconnectNClients", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@clients = []
|
@clients = []
|
||||||
|
|
Loading…
Reference in a new issue