question

Omer Faruk Sayilir avatar image
Omer Faruk Sayilir asked

Are C# SDK Async api calls thread blocker ?

Hi, i am developing server side of a unity based project, server program is not a unity project, so we are using c# sdk. As you may know difference between unity and c# sdk is asyncronous pattern. Unity SDK is using callback and c# SDK is using async await pattern. My problem with c# SDK is when you call multiple API calls, lets sey 100 times of "PlayFabServerAPI.DeletePlayerAsync". It is much slower than Unity SDK one. Slowness is not caused by the response time, its because Async methods are being queued up somehow. They are being processed 4 by 4 batches on my computer (Probably because it has 4 cores) . But in Unity SDK, it is processing all them toghather and giving each response independenty that causes to finish all job much more faster than c# sdk.

I am new to async await patter. Am i doing something wrong ?

sdks
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image Sarah Zhang commented ·

In theory, the differences in the run speed won’t be caused by the differences in async patterns. Could you provide the possible main sample code of “100 times of "PlayFabServerAPI.DeletePlayerAsync"”?

0 Likes 0 ·
Omer Faruk Sayilir avatar image Omer Faruk Sayilir Sarah Zhang commented ·
//Here how i used it. 

for (int i = 0; i < playerProfiles.Count; i++) { PlayerProfile item = playerProfiles[i]; DeletePlayer(item.PlayerId); }

public async void DeletePlayer(string playfabId) { var request = new DeletePlayerRequest { PlayFabId = playfabId }; var result = await PlayFabServerAPI.DeletePlayerAsync(request); if (result.Error == null) { Debug.Log("deleted"); playerProfiles.RemoveAll(p => p.PlayerId == playfabId); Repaint(); } else { Debug.Log("User delete error: " + result.Error.ErrorMessage); } }
0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

The possible reason to block threads is the maximum number of concurrent connections allowed by a ServicePoint object is limited. The default connection limit is 10 for ASP.NET hosted applications and 2 for all others. The possible workaround is to set the ServicePointManager.DefaultConnectionLimit manually or use .net core instead of .net framework. .net Core doesn't have such a default limit now. You can refer to the following code.

using System.Net;

...

ServicePointManager.DefaultConnectionLimit = 100;

...
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.