SampleProvider / Meadow-Guarder-old2

A free browser RPG game.
http://meadowguarder.herokuapp.com/
Other
16 stars 7 forks source link

You should add lag preventers #371

Closed BannanaPants closed 2 years ago

BannanaPants commented 2 years ago

Why I play Meadow Guarder all the time it lags mostly when there's a ton of people, but sometimes when I'm the only one on. Also it lags when too many boss get defeated at the same time.

Suvanth-Erranki commented 2 years ago

It doesn't just work like that. Heroku only gives Maitian 1 server for free, and the code is executed synchronously (meaning sequentially one line after the next), and there are a lot of processes to be handled, such as rendering the map for each player, calculating monster pathfinding, modifying the database, etc.

There is no simple way to "add lag preventers". All sp can do is optimize it, but that is very hard, and is already very optimized.

spsquared commented 1 year ago

I want to make a few corrections. You are correct in that there is no way to add lag preventers, however, there are some inaccuracies in this reply. Firstly, the code is not actually executed fully synchronously. Background tasks like IO are handled by a separate process spawned by the Node.JS runtime. This means that IO and such do not block server ticks, but the server ticks (mainly calculating movement) cause the server to slow down. The database is entirely asynchronous - in fact, it's actually on another server. Secondly, the server doesn't render any maps for any players. It sends the files to the client asynchronously, where they are processed by the client's computer, not the server. Thirdly, it's actually a network bottleneck you are experiencing. Socket.IO is an already highly efficient system of transferring data, but it has its limits. When a large number of entities are present, the server must package and send every single entity to the clients, because it doesn't do any filtering to remove entities far from the player. So if you experience a lot of lag, it's much more likely that your connection is throttling and you're just unable to receive the packets as fast as the server is sending them. The lag that results from many bosses getting defeated at the same time is because the server must spawn a bunch of item entities and tell the client to create particles. However, this doesn't have much impact on the server. On the client, this is a much larger issue, because having lots of particles means lots of draw calls, which increase frame times and lower FPS. The fact that Meadow Guarder makes monsters fade out on death, which needs lots of transparency calculations, worsens the lag on the client, but not the server. (Transparency compositing is not a very efficient process and exponentially increase draw times)

That said, it's really just a network bottleneck combined with a setting that can be turned off to reduce lag, not the server struggling to process things.

SampleProvider commented 1 year ago

its the chat thats laggy ist because when tons of bosses are spawned and defeated the packet is not made into 1 packet and its tons so it lags