Tracking nb users connected and server load

When a user connects or disconnects on the server, we log this (along the current server load).
This is only temporary, in order to assess the number of users a server can safely handle before crashing.
This commit is contained in:
David Négrier 2020-05-28 22:00:56 +02:00
parent 763d988848
commit 66ec11176b
3 changed files with 21 additions and 322 deletions

View File

@ -32,6 +32,7 @@
"http-status-codes": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"socket.io": "^2.3.0",
"systeminformation": "^4.26.5",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3",
"uuidv4": "^6.0.7"

View File

@ -11,6 +11,7 @@ import {UserInterface} from "_Model/UserInterface";
import {SetPlayerDetailsMessage} from "_Model/Websocket/SetPlayerDetailsMessage";
import {MessageUserJoined} from "../Model/Websocket/MessageUserJoined";
import {MessageUserMoved} from "../Model/Websocket/MessageUserMoved";
import si from "systeminformation";
enum SockerIoEvent {
CONNECTION = "connection",
@ -99,6 +100,14 @@ export class IoSocketController {
this.Io.on(SockerIoEvent.CONNECTION, (socket: Socket) => {
let client : ExSocketInterface = socket as ExSocketInterface;
this.sockets.set(client.userId, client);
// Let's log server load when a user joins
let srvSockets = this.Io.sockets.sockets;
console.log('A user joined (', Object.keys(srvSockets).length, ' connected users)');
si.currentLoad().then(data => console.log('Current load: ', data.avgload));
si.currentLoad().then(data => console.log('CPU: ', data.currentload, '%'));
// End log server load
/*join-rom event permit to join one room.
message :
userId : user identification
@ -219,6 +228,13 @@ export class IoSocketController {
console.error(e);
}
this.sockets.delete(Client.userId);
// Let's log server load when a user leaves
let srvSockets = this.Io.sockets.sockets;
console.log('A user left (', Object.keys(srvSockets).length, ' connected users)');
si.currentLoad().then(data => console.log('Current load: ', data.avgload));
si.currentLoad().then(data => console.log('CPU: ', data.currentload, '%'));
// End log server load
});
// Let's send the user id to the user

File diff suppressed because it is too large Load Diff