Reputation: 53
I made a simple shooting game in Meteor. I'm still pretty new with Javascript, so I'm quite sure my code isn't the most efficient.
Anyway, everything works great on localhost (of course), and it seems okay for the most part when I deploy. However, there are times where there will be a ton of lag and the client won't catch up for up to 30 seconds. The canvas updates every 10ms on the client, and 100ms on the server.
Here's the game: http://yujiangtham.com/jfleet/
Source: https://github.com/ytham/jfleet
I'm not sure where to start with debugging this. Could it be because:
a) Mongodb is not built for so many rapid read/writes?
b) Something somewhere is lagging and causing some sort of cascading lag?
c) Updating so many HTML elements on the canvas is causing the client to lag?
I'm honestly quite stumped. Any pointers in the right direction would be great. Thanks!
Upvotes: 0
Views: 807
Reputation: 53
So, I talked to a friend who had gone through something previously. Basically, the way to solve this is to not write so often to the database. It just can't handle that many writes in such a short period.
Basically, the way he told me to do this is by having the client and server compute all movement vectors separately. From there, the client and server should both predict where each sprite should be, and then have them compare every 200ms or so. Any differences should be overwritten by the server and written to the database. That data is then sent back to the client and overwrites any difference. I haven't actually implemented this yet since it requires a little bit of fancy math, but hopefully I'll get around to it soon enough...
Upvotes: 1