Saturday, 30 August 2014

Data Usage

ROBLOX has an API called Data Stores. It allows you to save information on a key/value basis that can later be accessed or used. This is useful for things like saving a player's settings, scores, and inventory.

However; using the API can cause problems because of ROBLOX's throttling rates on this service. Currently they allow 60 + (10 * number of players) DataStore accesses per minute, with left over requests being stacked. This means that you have to be very careful when using it - as a breach of the throttling rate will cause your script to error and the game to break (believe me, I have experience with this).

You cannot just request things from the data store willy-nilly. You should save things from the data store that are important to values or variables within your code, and then access the value/variable when needed later on, instead of the data stores. This would only work for things that aren't subject to rapid change, such as a user's score or settings to be loaded when they join the game and saved once more when they leave.

It is also important to consider when you should refer to the data store. You can't save and load things all the time, so you should carefully pick when to do so. Making your own counter of how many requests are available and subtracting from it whenever you access the store, adding to it every minute, and waiting until there are sufficient requests available before continuing may be a good idea. We've already acknowledged that we should load all pre-load game data at once at the start of the game to save it in values/variables, but what about after that point?

After you've loaded pre-load game data (preferably saved in a table/array/dictionary format for maximum DataStore efficiency) you probably won't need to actually load anything else, unless you're doing some funky cross-server communication thing - in which case the strain on the store will be so great there probably won't be room for much else. The only other real matter is deciding when to save. Saving all a player's data in a big chunk when they leave may leave you open to errors, crashes, and data loss if there is a lot of data to save and/or a lot of players leave at once. Therefore, you should save at strategic places throughout the game.

Modern games save most round-based data at the end of a round or mission. That way most of the non-critical data is saved here, so critical data can be saved later when a player leaves. That way extra data doesn't clog up the throttling rates. Therefore I will probably be saving some data at the end of a round or mission in Air:Force to free up my DataStore requests.

I'm not exactly sure why ROBLOX imposed these throttling rates (probably to do with their own server access limitations, we don't want to bring down ROBLOX's server farm after all), but at least they now stack. I only hope they invest in more servers so that us developers can save data more freely.

No comments:

Post a Comment