Search Unity

UWP DNS failing during/after scene load [Case 1169779]

Discussion in 'Windows' started by z000z, Jul 15, 2019.

  1. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    We have a problem where on the UWP platform all network access using HttpClient or WebClient is having DNS issues and throwing exceptions, the exceptions get caught but this causes the loading to be very slow since we have to retry all the network activity until we the DNS starts working (can take as long as 5 minutes after the scene load), also the exceptions being thrown and caught cause the application to run very sluggishly on UWP because exception throwing seems to cause performance problems in UWP.

    I've created a small test case that runs a bunch of web requests through http client and web client and times their performance during the awake function of a mono behavior, and then lets you load a scene that will do it again. I submitted this in case 1169779.

    So far I've tested this in Unity 2019.1.8, I plan on trying the latest 2019.1.10 and also the latest beta and alpha versions to see if it's any different/better in any of those. Thanks.
     
  2. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    I verified that 2019.1.10, 2019.2.0b9, 2019.3.0a8 all still have this issue as well.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,351
    Thanks for the bug report, we'll take a look.

    On a related note, does the performance issue with exceptions happens when debugger isn't attached too? On Windows in general, exception handling is very slow when a debugger is attached.
     
  4. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    @Tautvydas-Zilys Yes, it does help to not have it attached but it still seems to cause a decent slow down with it not attached still.
     
  5. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    @Tautvydas-Zilys
    It turned out in the test project I forgot to set some of the UWP flags, we did have those flags set though in our actual project.

    I did some more investigation though and was able to track down what was the cause of our issue. It turns out we had a bunch of long running tasks that were being started when our scene loaded, these were getting created using Task.Run. I switched these to Task.Factory.StartNew so that we can pass in the LongRunning flag and that seems to have cleared it up for us.

    I've added an updated test project to the case that adds a script that starts 50 tasks in it's awake and that seems to have duplicated the issue we were seeing. The odd thing about this issue is it only shows up the very first time you load the scene, if you load a different scene and re-load the problem scene it's fine. Also to duplicate the issue in the Unity Editor you have to restart the Editor to see the issue again, it only happens once per editor start.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,351
    Ah, that makes sense. When you do Task.Run, it doesn't spawn new threads unless the queue gets too long. So your requests likely sat in the queue while the threadpool waited for your long running tasks to complete.
     
  7. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    Yeah that makes sense, although it's a little weird that it only shows up the very first time you load the scene. Would expect it to do it each scene load.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,351
    It probably has spawned more threads by that point and your long running tasks don't starve the threadpool anymore.
     
  9. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    Yeah that could explain it. If the task thread pool dynamically sizes but for some reason takes a while to decide to upsize the first time it would explain the long pause and why the long pause doesn't return. Thanks!
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,351
  11. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    73
    Oh cool thanks, interesting to see how that works.

    Yeah looks like the combination of needing to get enough samples to make an accurate decision and also not increasing threads while the cpu utilization is high (which seems likely to be the case right at the load of that scene for a bit) is likely to delay it upping the thread count for a bit until things calm down enough and then it unsticks itself.