• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Julien-Lynge · Apr 17, 2013 at 06:35 PM · c#programmingwwwlag

Long delay with WWW.isDone

We're seeing a multi-second $$anonymous$$ccup in our application, and according to the profiler it appears to be during WWW.isDone. First, a bit of background:

Our application is a data viz tool. When it launches, we do a bunch of setup and also launch a search for the latest data to our 'core', w$$anonymous$$ch is a RESTful API on a server. When the search returns, we do a bunch of t$$anonymous$$ngs (parse the JSON, instantiate some NGUI objects, kick off additional downloads, etc.). During t$$anonymous$$s time, we're seeing a huge pause, but only in the webplayer. The standalone app has no pause at all - it runs smoothly.

After a bit of testing, it appears that a large chunk of the delay is being caused by our download manager checking to see if the download is complete by calling dl.isDone(). Here's what I'm seeing in the profiler:

alt text

As you can see, each isDone call appears to be taking 50 ms, with UnityCrossDomainHelper.GetSecurityPolicy being the only t$$anonymous$$ng listed under isDone. Here's the relevant code from our download manager:

 private IEnumerator monitorDownload()
 {
     w$$anonymous$$le (state == State.Downloading)
     {
         if (www.isDone)
         {

MonitorDownload basically just runs on a loop, yielding every frame, and checks up on the download as it's happening, along with managing download state (somet$$anonymous$$ng we introduced in our download manager), etc.

So, in summary, for some reason calling www.isDone in some cases is causing up to a 50 ms delay, but only in the webplayer.

www bug profiler.jpg (299.6 kB)
Comment
Dracorat
Loius

People who like this

2 Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dracorat · Apr 17, 2013 at 06:44 PM 0
Share

Some data to consider:

Apparently, the WebPlayer still uses the browser for downloading:

http://forum.unity3d.com/threads/141679-WWW-calls-slow-in-the-unity-web-player

WWW vs HttpWebRequest:

http://forum.unity3d.com/threads/64695-Comparing-performance-of-HttpWebRequest-to-WWW-class

I wonder if you (for debugging only, mind) tried using the HttpWebRequest object, what speed would it report?

avatar image Julien-Lynge · Apr 17, 2013 at 07:25 PM 0
Share

Thanks @Dracorat,

I've seen posts stating that HttpWebRequest isn't available in the webplayer: http://forum.unity3d.com/threads/53218-Alternative-for-httpWebRequest-amp-HttpWebResponse

If that's actually the case (and not user error) that would pretty much be a no-go :)

avatar image Dracorat · Apr 17, 2013 at 08:16 PM 0
Share

Agreed. If it's not available, that's too bad (for testing). =(

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Julien-Lynge · Apr 17, 2013 at 08:48 PM

T$$anonymous$$s appears to be a bug internal to Unity, somet$$anonymous$$ng to do with UnityCrossDomainHelper.GetSecurityPolicy. It doesn't appear to have anyt$$anonymous$$ng to do with the number of downloads, and is reproducible with a skeleton project.

Submitted bug 538108:

Large delay with WWW.isDone

I'm consistently seeing a 50 ms delay per call to WWW.isDone, when the following the application is running as a webplayer app (even in the editor when target is set to webplayer)

T$$anonymous$$s 50 ms delay is only seen when WWW.isDone in turn calls UnityCrossDomainHelper.GetSecurityPolicy, w$$anonymous$$ch it does not appear to do for every download, and doesn't appear to do every frame for the downloads it does affect.

I've included a repro project with a test scene and script to start 7 downloads and then launch a coroutine for each to call WWW.isDone once per frame. I've included 2 profiler screenshots showing frame 1 and frame 2 of running the application in the editor. As you can see, in frame 1 there are 7 downloads, and 2 calls are made to GetSecurityPolicy, resulting in around 100 ms of delay. In the very next frame, the 7 downloads are still active and no calls are made to GetSecurityPolicy, with a result of 0.00 ms of delay for the same code.

In our main application, I have seen the total delay get as $$anonymous$$gh as 1100 ms in rare instances when we're running a couple dozen downloads simultaneously. T$$anonymous$$s only happens for the webplayer - the standalone app is unaffected. The delay seems perfectly linear - each call to GetSecurityPolicy adds 50 ms of delay. I've seen t$$anonymous$$s happen for as few as 3 calls to WWW.isDone in a single frame and as many as 30.

Comment
Loius

People who like this

1 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dreamora · Apr 17, 2013 at 10:43 PM 0
Share

get security will indeed take a lengthy amount of time as it has to contact the server and verify the crossdomain xml file. unsure why you get up to such high ms numbers though, probably related to the parallel downloads and a limitation on concurrently open http connections from the browser side. Standalone / editor do not use browser http pipelines, they use raw tcp sockets so they have no limit on the number of parallel WWW requests.

you might want to experiment if you can get rid of it by enhancing your download manager to only execute 4 parallel WWW at a time while the others wait (while (...) yield loops) for their time to start

avatar image Julien-Lynge · Apr 17, 2013 at 10:58 PM 0
Share

Yeah, it's very strange. I removed the call to www.isDone as you suggested, and the GetSecurityPolicy calls remain, so apparently there's no way to get around them. I'm not sure why they're taking so long, nor why Unity would need to make so many calls when we're contacting just a handful of servers.

Additionally, when I try to reduce the number of simultaneous downloads, I'm seeing it with as few as 4 downloads (4 calls to isDone resulting in 1 call to GetSecurityPolicy, resulting in a 50 ms delay that frame). I don't know about you, but 4 downloads and 1 security check doesn't sound like all that much.

avatar image Dreamora · Apr 17, 2013 at 11:01 PM 0
Share

Because it has to verify the access security for every single new server you want to contact. The only server where it will not do that is the own server when you access the files with relative URLs.

This is documented under the Webplayer Sandbox manual page and acts the same way Flash, Silverlight and any halfway secure web technology works regarding cross domain access. Its a required evil to ensure that no private data gets accessed within local networks without the user explicitelly allowing it.

avatar image Julien-Lynge · Apr 17, 2013 at 11:03 PM 0
Share

That's the thing, though - we have a proxy set up on our server, and all requests for (say) thumbnails go through that proxy. So while the individual URLs are different, everything from the server down through the service being called are identical. And once it fetches the crossdomain.xml for a server, it should never need to fetch it again, even for a different URL on that server.

avatar image

Answer by Dreamora · Apr 17, 2013 at 06:45 PM

The webplayer uses the browsers HTTP pipeline for any request (to benefit from the browser cac$$anonymous$$ng, cookie and session handling), so if you ask WWW about 'isDone' it will have to call out to the browser, get and process the response and feed it back into the scripting layer for you to consume during the next frame / fixed udpate.

T$$anonymous$$s normally shouldn't cause any delays and alike and hasn't basing on my experience, but my implementations always ensured to limit the amount of parallel downloads to a handfull at max. many browsers have limits for parallel http connections, if you fire up 40 in a single round, you are risking to lock yourself down for a lengthy amount of time

The easy and non-performance kiling way is removing the isDone loop and use yield return www but t$$anonymous$$s only works if the download progress is irrelevant.

If you need to access the download progress, you could use a longer yield timeframe as the progress will not jump from 0 to 100% in 0.016 / 0.02s, So using somet$$anonymous$$ng like yield return new WaitForSeconds(0.1f) or even 0.5f would make a major difference.

Comment
Julien-Lynge

People who like this

1 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Julien-Lynge · Apr 17, 2013 at 07:21 PM 0
Share

Thanks for the info. Interestingly, I'm seeing this behaviour in the editor, which I imagine isn't running the requests through any browser :)

Originally we were quite interested in getting the download progress (to determine whether downloads of large imagery were just slow or actually hung). However, in my experience www.progress almost never works, unless you're downloading a file straight from a web directory. If you're going through a web service, it will always be 0 until it's 1. So yeah, it might be time to rework that code.

However, the whole thing is very strange - at the point of the pause we see a 50 ms delay per request, but at other points I see a 0 ms delay. Of course, as I'm writing this I realize that later in our app we do manage simultaneous downloads (to 5 per dataset), so perhaps it is just the sheer number - I'll throttle it and report back.

avatar image Julien-Lynge · Apr 17, 2013 at 07:30 PM 0
Share

I throttled the count to 6 downloads, and at one point in the code I see that it's taking 300 ms - so that's a linear decrease, and still 50 ms per call to www.isDone. Also, the very next frame I'm still making 6 calls, but the total time is 0 ms.

Here's the interesting part: in the frame with the 300 ms hiccup, I see a call to UnityCrossDomainHelper.GetSecurityPolicy under WWW.get_isDone(). The following frame, with 0 ms delay, there is no call to GetSecurityPolicy.

I'm going to continue researching to see if this holds up in other situations, and see if I can figure out what the circumstances are that cause the call to GetSecurityPolicy.

avatar image Julien-Lynge · Apr 17, 2013 at 07:55 PM 0
Share

Well, it does appear to be the case that GetSecurityPolicy is what's causing the delay, even if it lists itself as only a few ms in the profiler. In my various tests so far, it is always the case that each call to GetSecurityPolicy adds ~50 ms of delay. For instance, check out the screenshot below:

alt text

As you can see, there are 29 calls to isDone and only 2 to GetSecurityPolicy, and sure enough the delay is around 100 ms.

Hopefully this will be enough for me to build a repro project.

www bug profiler2.jpg (293.3 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

In the need of the light of a genius ! 2 Answers

Unity WWW gzip 1 Answer

[C#] AI Behaviour in spherical way like RESOGUN based on Rigidbodies. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges