lance-gg / lance

Multiplayer game server based on Node.JS
https://lance-gg.github.io/
Apache License 2.0
1.58k stars 166 forks source link

Replacing socket.io with uwebsockets for better latency/performance? #98

Open MaZZly opened 5 years ago

MaZZly commented 5 years ago

Hi,

First of all, awesome framework! Finally gotten started writing a game I've wanted to make for like 3 years.

I was researching today about scalability of server nodes and stumbled upon this interesting reddit thread: https://www.reddit.com/r/gamedev/comments/6gjgnx/backend_scaling_for_multiplayer_html5_games/

There they mention that socket.io is not so good and mention that uwebsockets is performing better.

Could this maybe be something worth considering for the websocket communications?

namel commented 5 years ago

Hi MaZZly

Good luck with your game. uwebsockets sounds interesting, and thanks for pointing me to that reddit thread.

Truth is that I want to move towards UDP, which probably means dropping websockets altogether. This is what non-javascript (i.e. real) games use, and provides a much better experience. However last time we checked UDP was still tricky to use in node-js environments.

It's very high on the wish-list...

MaZZly commented 5 years ago

Yeah ofc better latency is always a plus (as long as it also scales)

Have you checked out https://www.npmjs.com/package/wrtc ? Seems to be handling WebRTC with node?

This might be interesting if you are starting to write the client-server handling with WebRTC: http://blog.brkho.com/2017/03/15/dive-into-client-server-web-games-webrtc/


Found this thread that boasts quite nice numbers for uWS: https://github.com/socketio/engine.io/issues/388

I was mostly interested in the uWS vs socket.io because there seems to be a benefit CPU-load wise.. And swapping it out doesn't seem like it should be too much work? as uWS was written to be easy to plug in.

OpherV commented 5 years ago

@MaZZly The problem is that there are no good node-server based implementation for WebRTC, especially ones that implement unreliable data channels properly. WebRTC in itself was designed to work peer-to-peer rather than with server-client star topology

MaZZly commented 5 years ago

So while waiting for something good along the lines of WebRTC to come along, maybe uWebSockets could be put in place? https://github.com/uNetworking/uWebSockets.js

richrd commented 5 years ago

UDP is sure the way to go, but hard to do in browsers. One question though: why not just use vanilla js websockets instead of uwebsockets / socket.io / or any other wrapper?

ouya99 commented 4 years ago

I tested http://geckos.io/ . It does WebRTC with UDP channels

Could this be used for lance?

MaZZly commented 4 years ago

@OpherV @namel do you have any input/comments for the above Geckos suggestion? I feel like this is quite an important part of getting a multiplayer game to run smoothly with low latencies. And now it seems it would be quite easy to implement? (hopefully) :)

The demo from the Geckos.io repo has quite a good comparison: https://www.youtube.com/watch?v=ZEEBsq3eQmg