I am creating a HTML5 game with NodeJS (using websockets). To update my the game and send the data to every player I use setInterval() with a 33ms interval (to update 30 times per second).
It happens that when over 10 players connect to the game, the websockets library starts to consume a lot of CPU and the setInterval start to having some delay (it goes to 27-28 frames per second).
After profiling my code I found out that most of the time my CPU is idle. So I was thiking. Is my whole program idle in that 33ms interval beetwen every loop? Would it work if I set a dynamic interval? Something like when a lot of players are connected and the frames per second starts to drop I reset the interval from 33ms to 28ms for example? Could this work/have anyone use any system like this?
Best regards, Daniel