Explorar o código

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

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

GitOrigin-RevId: d1af260a3bfba7852519b3bc369a6747e79f3b18
Jakob Ackermann %!s(int64=5) %!d(string=hai) anos
pai
achega
1dc9f428fa
Modificáronse 1 ficheiros con 11 adicións e 3 borrados
  1. 11 3
      services/clsi/app.js

+ 11 - 3
services/clsi/app.js

@@ -330,11 +330,19 @@ const loadTcpServer = net.createServer(function (socket) {
     }
 
     const freeLoad = availableWorkingCpus - currentLoad
-    let freeLoadPercentage = Math.round((freeLoad / availableWorkingCpus) * 100)
+    const freeLoadPercentage = Math.round(
+      (freeLoad / availableWorkingCpus) * 100
+    )
     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()
   } else {
     socket.write(`${STATE}\n`, 'ASCII')