From 8d955e30673a6d97d843962aebe033fda5667739 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 9 Feb 2024 20:42:27 +0000 Subject: [PATCH] set up scaleway pools --- server/ecosystem.config.js | 4 ++-- server/room.ts | 18 ++++++++++++------ server/vm/base.ts | 4 +++- server/vmWorker.ts | 7 ++++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/server/ecosystem.config.js b/server/ecosystem.config.js index 29e0852576..a2270c8cdb 100644 --- a/server/ecosystem.config.js +++ b/server/ecosystem.config.js @@ -43,8 +43,8 @@ module.exports = { HETZNER_GATEWAY: 'gateway2.watchparty.me', HETZNER_SSH_KEYS: '1570536', HETZNER_IMAGE: '145986216', - SCW_GATEWAY: 'gateway1.watchparty.me', - SCW_IMAGE: '', + SCW_GATEWAY: 'gateway2.watchparty.me', + SCW_IMAGE: '172bd9df-eba5-44e7-add0-f6edbb0f9c64', DO_GATEWAY: 'gateway4.watchparty.me', DO_IMAGE: '', DO_SSH_KEYS: '', diff --git a/server/room.ts b/server/room.ts index 63d6d86dc8..edbb0470fc 100644 --- a/server/room.ts +++ b/server/room.ts @@ -903,13 +903,19 @@ export class Room { // TODO limit users based on client or uid usage } } - // TODO (howard) check if the user or room has a VM already in postgres - if (false) { - socket.emit( - 'errorMessage', - 'There is already an active vBrowser for this user.', + // check if the user already has a VM already in postgres + if (postgres) { + const { rows } = await postgres.query( + 'SELECT count(1) from vbrowser WHERE uid = ?', + [decoded.uid], ); - return; + if (rows[0].count >= 2) { + socket.emit( + 'errorMessage', + 'There is already an active vBrowser for this user.', + ); + return; + } } } let isLarge = false; diff --git a/server/vm/base.ts b/server/vm/base.ts index a2d3d5f077..aa46a5a098 100644 --- a/server/vm/base.ts +++ b/server/vm/base.ts @@ -483,7 +483,9 @@ export abstract class VMManager { console.log('[VMWORKER] %s: starting background jobs', this.getPoolName()); setInterval(resizeVMGroupIncr, incrInterval); - // setInterval(resizeVMGroupDecr, decrInterval); + if (this.id !== 'Hetzner') { + setInterval(resizeVMGroupDecr, decrInterval); + } setInterval(async () => { console.log( '[STATS] %s: currentSize %s, available %s, staging %s, buffer %s', diff --git a/server/vmWorker.ts b/server/vmWorker.ts index 75175b3c3e..0327889eb4 100644 --- a/server/vmWorker.ts +++ b/server/vmWorker.ts @@ -15,14 +15,15 @@ Object.values(vmManagers).forEach((manager) => { app.post('/assignVM', async (req, res) => { try { // Find a pool that matches the size and region requirements - const pool = Object.values(vmManagers).find((mgr) => { + const pools = Object.values(vmManagers).filter((mgr) => { return ( mgr?.getIsLarge() === Boolean(req.body.isLarge) && mgr?.getRegion() === req.body.region ); }); - // TODO maybe there's more than one, load balance between them? - // However if the pool is 0 sized we need to consistently request the same pool for a given uid/roomid + // maybe there's more than one, randomly load balance between them? + const pool = pools[Math.floor(Math.random() * pools.length)]; + // TODO (howard) However if the pool is 0 sized we need to consistently request the same pool for a given uid/roomid // Otherwise we may spawn multiple VMs on retries if (pool) { console.log(