metauni / metaboard

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

Persistence parallel BindToClose #70

Closed blinkybool closed 1 year ago

blinkybool commented 1 year ago

From DataModel:BindToClose

Multiple functions can be bound using BindToClose if it is called repeatedly. The game will wait a maximum of 30 seconds for all bound functions to complete running before shutting down. After 30 seconds, the game will shut down regardless if all bound functions have completed or not. Bound functions will be called in parallel, meaning they will run at the same time.

Saving a board to the datastore involves serialising the data, then writing it to the datastore. I think we are only concerned about the total cost of the serialisation step across all the boards being stored, since the actual SetAsync is performed within a task.spawn. That step I think is quite fast, but is doing it 100 times < 30 seconds? Probably yes still... but why risk it if we can do them all in parallel?

By the way, if the budget for setAsync is <150 when OnClose is triggered, it will get increased to 150, so we should always be able to store at least 150 (single chunk) boards. Source: https://devforum.roblox.com/t/details-on-datastoreservice-for-advanced-developers/175804 (see "Extra budgets when the server closes (OnClose)")

dmurfet commented 1 year ago

I don't know what "in parallel" means. If you mean, you yield so another one can run, be aware that if they all yield in this way then you'll "run out the bottom of" BindToClose and the server will just shutdown (I believe you know this, just making sure). I don't think there is really such a thing as "in parallel" in this situation, you might as well just have a loop doing them serially.

blinkybool commented 1 year ago

I read this as saying that they actually run them separately on different hardware threads at the same time. I think Roblox speaks of "asynchronous" and "parallel" as separate concepts.

Bound functions will be called in parallel, meaning they will run at the same time.

blinkybool commented 1 year ago

I couldn't replicate the truly parallel behaviour. We'll return to this if it seems possible.