Merge pull request #9231 from overleaf/jpa-clsi-lifespan-fix

[clsi] cycle VMs before their 24h limit with some jitter

GitOrigin-RevId: c08bea6765dc8b03db9f0792a8bb20084f595f59
This commit is contained in:
Jakob Ackermann 2022-08-29 13:29:20 +01:00 committed by Copybot
parent b449107411
commit 199ced5eef

View file

@ -240,15 +240,19 @@ app.get('/status', (req, res, next) => res.send('CLSI is alive\n'))
Settings.processTooOld = false
if (Settings.processLifespanLimitMs) {
Settings.processLifespanLimitMs +=
// Pre-emp instances have a maximum lifespan of 24h after which they will be
// shutdown, with a 30s grace period.
// Spread cycling of VMs by up-to 2.4h _before_ their limit to avoid large
// numbers of VMs that are temporarily unavailable (while they reboot).
Settings.processLifespanLimitMs -=
Settings.processLifespanLimitMs * (Math.random() / 10)
logger.debug(
'Lifespan limited to ',
Date.now() + Settings.processLifespanLimitMs
logger.info(
{ target: new Date(Date.now() + Settings.processLifespanLimitMs) },
'Lifespan limited'
)
setTimeout(() => {
logger.debug('shutting down, process is too old')
logger.info({}, 'shutting down, process is too old')
Settings.processTooOld = true
}, Settings.processLifespanLimitMs)
}