metauni / metaboard

Multiplayer drawing boards for sharing knowledge in Roblox.
Mozilla Public License 2.0
28 stars 6 forks source link

Persistent boards save only on server shutdown #20

Closed dmurfet closed 2 years ago

dmurfet commented 2 years ago

At the moment persistent boards write their contents to the DataStore on server shutdown using DataModel:BindToClose (https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose). This is the officially recommended practice, but note that there is a 30sec timeout in total for all functions bound to BindToClose.

Since the DataStore writing involves network access, and there are an arbitrary number of persistent boards around with arbitrarily many curves, I think we could easily hit this limit.

Proposal: the server keeps a record of the last time anyone interacted with a board (in the sense that any drawing task was executed on it). We keep a loop running on the server which looks at these times every 5-10sec, and if a board hasn't been touched in some amount of time we write out its contents to the DataStore. Then the board is marked as "synced". Any interaction with the board marks it as "unsynced".

Then on server shutdown we know we only need to write out those boards marked as unsynced, which should be a small number (or at least it's much better than the current situation).

sheepish12 commented 2 years ago

From what I can tell, the 30 second limit being passed because of too many boards is only possible currently because the boards are saved synchronously. If we were to save them asynchronously using task.spawn then there should be no difference in save time between a single board and many.

There's still value in auto-saving as you suggested though. If Roblox's data store service goes down while a server is up, then the server shuts down, currently no changes will be saved. With auto-saving the changes made prior to the service going down will still persist.

I'll make a PR for my suggestion

dmurfet commented 2 years ago

That would be great, thanks!

dmurfet commented 2 years ago

Resolved by https://github.com/BenSBk/metaboard/commit/ee37a6e623b16abc93d900023d881fb224a0a97c.