Skip to content

Commit

Permalink
set up scaleway pools
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Feb 9, 2024
1 parent 0496052 commit 8d955e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions server/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
18 changes: 12 additions & 6 deletions server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion server/vm/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 4 additions & 3 deletions server/vmWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8d955e3

Please sign in to comment.