We have added a cloudscript end point where we want to make decisions based on statistics for one of our matchmaking queues. We call this end point very seldom (once every few minutes per user). And as long as there is only one player using this we are fine, but when there are more than one we start being throttled. It seems the limit is imposed per queue, rather than per player. We could circumvent this by having the player get the statistics (that works without throttle) and post that the script, but that seems dumb.
I attach a screenshot here where you can see the pattern. It all succeeds until two players happens to use the end point within a minute, then it fails. The error message we see is attached below
"apiError": { "code": 429, "status": "429", "error": "MatchmakingRateLimitExceeded", "errorCode": 2054, "errorMessage": "The rate of get queue statistics requests for title!C6A22 has exceeded the limit and is temporarily throttled.", "errorHash": null, "errorDetails": null }
Answer by Rick Chen · Oct 27, 2020 at 09:19 AM
There is a limit of Number of GetQueueStatistics API requests an entity can make per queue within a period of 1 minute. You can check it in [Game Manager]->[Your Title]->[Title Settings]->[Limit], the limit’s name is “Queue statistic gets per minute”. The limit is usually 1. The GetQueueStatistics API should be called by the server in your CloudScript, not by user. Therefore, no matter which user executes the CloudScript, the GetQueueStatistics API is called by the same server entity. And calling 2 GetQueueStatistics APIs in 1 minute produce the limit error.
It is not recommended to allow players to call GetQueueStatistics API via CloudScript.
So it is not recommended to use queue statistics in cloud scripts? I do not understand that limitation, but I guess I can work around it.
The GetQueueStatistics API returns the matchmaking statistics for a queue. And the statistics are refreshed once every 5 minutes. Although GetQueueStatistics is an entity API, it is designed for servers only. You could use it in CloudScript, and one way to work around is to cache the result when GetQueueStatistics API is successfully called, and when it is not successful, catch the error and use the cache, for example:
handlers.GetQueueStat = function(args,context){
try{
result = multiplayer.GetQueueStatistics({QueueName: args.QueueName});
title_data_result = server.SetTitleData({Key:"NumberOfPlayersMatching", Value:result.NumberOfPlayersMatching});
return result.NumberOfPlayersMatching;
}
catch(error){
result = server.GetTitleData({Keys:["NumberOfPlayersMatching"]});
return result.Data.NumberOfPlayersMatching;
}
}
Question about Matchmaking and some bits about CloudScript 1 Answer
[VERY URGENT] Unity Matchmaking with Mirror cannot connect to server 2 Answers
Use Statistics value of Player Entity for MatchMaking rule 1 Answer
Unable to call ExecuteCloudScript from Thunderhead server 4 Answers
How would I use match-making (preview) for my game ? 1 Answer