javascript – websocket server multiplayer game using two mouses?

I am trying to build a multiplayer game using javascript/websocket/node.js/heroku, and I suppose players may use mouse to control their character (on mouse move).

I wrote code like this:

client.js:

game.draw(dataFromServer);

ws.send(JSON.stringify(localMouseData));

server.js

client.on('message', (data) => {
    let parseData = JSON.parse(data);
    if (parseData.login === false) {
      CACHE.clients.push(parseData);
    }
    for (let i = 0; i < CACHE.clients.length; i++) {
      if (CACHE.clients(i).id === parseData.id) {
        CACHE.clients(i) = parseData;
      }
    }
  })
  
setInterval(() => {
    wsServer.clients.forEach((client) => {
      client.send(JSON.stringify(CACHE));
    });
  }, 1000 / FPS);

But here comes the problem, the game performance is good when running locally, but getting delay (about 1 second) after deployed on heroku.

I guess the problem is about the server speed, but I also wonder if there is any solution for this case, because I used to see this kind of feature before(in other program, like figma), player can see their cursor and other player’s cursor, but I just can’t figure out how those developers solve the problems about server delay.

If anyone can give suggestion, I will be very appreciated, thanks!