Merge pull request #4890 from overleaf/jpa-clsi-maint

[clsi] put server into maintenance mode when reaching zero capacity

GitOrigin-RevId: d1af260a3bfba7852519b3bc369a6747e79f3b18
This commit is contained in:
Jakob Ackermann 2021-08-26 14:02:09 +02:00 committed by Copybot
parent 18192e4559
commit 1dc9f428fa

View file

@ -330,11 +330,19 @@ const loadTcpServer = net.createServer(function (socket) {
} }
const freeLoad = availableWorkingCpus - currentLoad const freeLoad = availableWorkingCpus - currentLoad
let freeLoadPercentage = Math.round((freeLoad / availableWorkingCpus) * 100) const freeLoadPercentage = Math.round(
(freeLoad / availableWorkingCpus) * 100
)
if (freeLoadPercentage <= 0) { if (freeLoadPercentage <= 0) {
freeLoadPercentage = 0 // when its 0 the server is set to drain and will move projects to different servers // When its 0 the server is set to drain implicitly.
// Drain will move new projects to different servers.
// Drain will keep existing projects assigned to the same server.
// Maint will more existing and new projects to different servers.
socket.write(`maint, 0%\n`, 'ASCII')
} else {
// Ready will cancel the maint state.
socket.write(`up, ready, ${freeLoadPercentage}%\n`, 'ASCII')
} }
socket.write(`up, ${freeLoadPercentage}%\n`, 'ASCII')
return socket.end() return socket.end()
} else { } else {
socket.write(`${STATE}\n`, 'ASCII') socket.write(`${STATE}\n`, 'ASCII')