Update: This only happens with requests that have fairly large responses (around 30kb).
It is regularly taking on the order of 20 seconds to get a response from our servers while running our game in the editor (2019.1.6f1).
Notes:
- Sending requests using the same user data from a python script and it takes around 2 seconds.
- Requests are fast on my iOS device when running the same project.
- The engineers next to me do not have this issue using the same Unity and MacOS versions.
- I have also tried a fresh client repo and resetting my user data and starting the game from scratch. None of this helps.
I have searched and found various other reports of this issue through the years but have not found a solution.
Anybody else seeing this or know of a solution?
Here is the code. The times I am reporting are Time.time - lastRequestTime. It’s about 20 seconds for the average request. One thing that I have noticed is that we return fairly large responses on success, and requests that result in an error are fairly fast. So it seems to have to do with the size of the response. But again, only in the editor and only on my MacBook Pro (2017 2.9 Ghz 16GB RAM).
lastRequestTime = Time.time;
request.SendWebRequest();
while (!request.isDone)
{
yield return new WaitForSeconds(0.1f);
}
Debug.Log($"Request took {Time.time - lastRequestTime} seconds");
Are you running the request in editor mode or in play mode?
What download handler are you using?
Try printing request progress information in a loop (with time), that might help you to pinpoint whether it’s connect, upload or download issue.
I am using UnityEngine.Networking.DownloadHandlerBuffer
I have added some debug output. Sending the request takes virtually no time at all. The time is spent between after sending the request, before request.isDone is set.
lastRequestTime = Time.time;
request.SendWebRequest();
Debug.Log($"Request send took {Time.time - lastRequestTime} seconds");
while (!request.isDone)
{
yield return new WaitForSeconds(0.1f);
Debug.Log($"Request so far took {Time.time - lastRequestTime} seconds");
}
Debug.Log($"Request took {Time.time - lastRequestTime} seconds");
“Request send took” line reports 0 seconds
“Request so far took” lines keep reporting 0.1 seconds more up to 7.15 seconds for me
That is expected, SendWebRequest only launches everything on the other thread. You should be monitoring donwload/upload progress properties of the request.
One more thing you can try is setting request.useHttpContinue to false, maybe that’s the reason (blind guess).