Issue with a large amount of SetAsyncs

i just recently realised that i have A LOT of SetAsyncs in my game, and the issue is that the cap limit for SetAsync per minute is 60 + (NumOfPlayers x 10), which for me is basically 60 + (10x10)
= 160

so per minute its 160 SetAsyncs for the entire server, and i currently have (for each player) 24 set asyncs which is already an issue because for a full server it would be 240 set asyncs which already exceeds the limit,

and thats not just it because i have a house furniture system that for each house the player owns, it datastores the furniture and the number of houses i have in my game is 12 so if a player owns all the houses in the game that means it would be 12 more set asyncs, and i dont just datastore the furniture i also datastore placed electronics for each house so that means its an another 12 set asyncs.

so if we do some calculations (supposing if ALL players owned all 12 houses and all the players got kicked from the server due to an update or an issue) :

24 asyncs that are basically the houses
24 asyncs for the other datastores

and if we add it, it would be 48 datastores and we need to multiply it by 10 (the amount of players left the game)

and ultimatially it will be 480 request keys which that exceeds the limit by A LOT

i dont think im able to decrease the amount of datastores in my game, and even if i combined some datastores with others, it would still be a lot more than the limit

note i cant update the player cap count, because i have 10 plots in my game and i cant really squeeze more in, so 10 is the MAX

any help will be appreciated !!

Hello!

I am replying to this partially to learn about datastores, but why so many requests? I save a lot of data in my game aswell and I cannot figure out why you would need to make that many calls to the datastore. I use set async only after I have added every single thing I need to the table that is tied to the players key.

More information regarding how this is being done (pieces of scripts maybe, or other info regarding the structure) would be really helpful regarding breaking this issue down.

Hopefully this helps!

1 Like

In almost all cases, you should be saving all of each player’s data in the same datastore call.

The only case where you don’t save a player’s data all at once is if the data is shared (e.g. a guild, group, or game-wide save file, which crosses multiple players).

For example, your houses should have all their data in one datastore. The furniture, items, and house details should all be saved at once.

Your players should also have all their data saved at once: all their houses, player items, currency, etc should be saved in the same SetAsync call.

1 Like

Ok wait so instead of having an async for each house, what if you just saved the values in a table, thats now 1 async, and you should only have to call it when the player first loads in, and save it when they leave.

This should help!

1 Like

well the issue is that each datastore key holds 4mb of memory and if i make ALL 12 houses and its details and furniture inside 1 key it will exceed the memory limit, or it would restrict the player from placing as much furniture as they like. because it would be more memory than 4mb, thats why i made a key for each house so each house has 4mb (which is a lot for 1 house) and not 4mbs for ALL houses which will not be enough

(and im also considering to add more houses in the future so it might even be 20 houses)

i did reply to @frodev1002 about the details of my issue, and hopefully it clarifies the problems with making all houses and details inside it in 1 key

i only set async when the player leaves, and im just picturing a scenario where if all the players got kicked (due to a server shut down) at once, all players need to set async and if so then it would need to set async more than 160 times which is more than the limit,

im trying to reduce the set asyncs in my game which is the main issue

@Ethanaut, @BendsSpace, @FroDev1002

i also apologise for the late responses, i posted the topic late at night and no one replied for 3 hours so i slept…

Ok,for setasync() this can only be used once!

If u want to use it again.Use httpservice

HttpserviceJscEncode()

im not sure how httpservice can save data?

can you show me code please?

Hmm well there has got to be a way to shorten up the data you are using, what does the data look like that you are saving?

2 Likes

I would try to reduce your data usage. Some games store entire worlds in one key. Each furniture item can probably be represented as just a CFrame, type, and color, for example.

just furniture, electronics, and wall placements,

furnitures are basically stored by having the scale (because they are models) the cframe and colors of the furniture

and basically the same thing applies with the electronics

i understand that but for example blox burg each plot has its own data memory usage which means that they are for each plot a data key, and you can literally buy unlimited plots ,and thats pretty weird cuz its a unlimited

1 Like

I believe it’s more effective and less error prone to load player data at login and save it at logout, while using a temporary version for managing changes during gameplay. So for me the correct amount is 1.

Can you have unlimited plots open at once? Also, the plots should only need to be updated when they have changes, so if there’s only one plot open at a time, then only one plot needs to be saved.

Another thing you could do is only save plots when they’re edited. This way, unless every player edits 10 separate plots in the same minute, you have enough SetAsync calls. (And if the server crashes or the player leaves, then only save the plot being currently edited.)


TL;DR:

  • Save houses every few minutes if (and only if) it has new changes.
  • The house save should have all the house information and furniture data.
  • If you save modified houses every minute, every player would need to edit 10 different houses in the same minute to have problems.
  • If this edge case is a concern, you could just limit each player to only being able to edit 9 houses in the same minute (which would probably be very difficult without teleporting or something)

If the server stops (which is the worst case), you’d need to save the house currently being edited, the player’s data (which should be in a single store) and any houses that have unsaved changes. This should fit in the SetAsync budget fairly easily.

Also note that you could get about 2-3 minutes when a game ends by yielding (e.g. if you run out of SetAsyncs you can wait and the server (typically) will stay open for a minute or two longer), which increases your limit by 2-3 times in most cases (I don’t think it’s totally guaranteed for this to work). Thank you for the correct information, @Tomi1231. It’s 30 seconds, not 3 minutes.

2 Likes

Game:BindToClose() can only yield for a maximum of 30 second before the server shuts down
However, when servers closes due to an update, it can wait a bit before kicking everyone, to give more time to save data

2 Likes

i appreciate the help @BendsSpace, and appreciate all the people who tried to help me in this topic!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.