Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Delay on value retrieval

Discussion in 'Scripting' started by Serellyn, Jul 2, 2013.

  1. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    Hey guys,

    I'm having this kind of weird issue on a system I'm creating.
    I'm sending a value to a PHP script which retrieves data from the database, it works and within the editor it works pretty fast.
    But, I noticed after building the application to an executable, it takes around 3 seconds to retrieve data from the database.

    So basicly, running from within the editor the data is retrieved in 0.4 seconds, so that's pretty good. But running the executable it takes 3 seconds to retrieve the data. Any idea how and why this would happen? I really need to sort this out.

    I'm using the following code
    Code (csharp):
    1.  
    2.     public IEnumerator CheckRFID (string RFIDtag) {
    3.         print("Start CheckRFID: " + myTimer);
    4.         string full_url = connectionURL + checkRegisteredURL + "tag=" + RFIDtag;
    5.         WWW post = new WWW(full_url);
    6.         yield return post;
    7.         print("Result received: " + myTimer);
    8.         ...
    9.     }
    10.  
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    I have not answer to the main question. But I think, if you work with web server, you should be ready to get answer with lag, and 3 seconds is not very big lag. What'll happen if server won't response?

    The reason can depends on the environment/ caching or server location. Could you post more details?
     
  3. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    Hey Patico,

    thanks for responding.
    It it indeed a web server, located in the USA while I'm accessing it from Europe.
    I know a bit of lag is normal, but I really think 3 seconds is excessive and why does it only take 0.3 seconds in the unity environment.

    Here are some details
    My OS: Windows 7 x64
    My location: Europe
    Server location: USA
    Connection between application and server: PHP

    While accessing the PHP file directly it takes 0.045 seconds to return a value
    While using the php file from within the Unity environment it takes 0.3 seconds
    While using it through a build from the applicatie it takes 3 seconds.

    A bit of lag is pretty normal and okay for me, but why the major difference between running it from within the editor and build... it bugs me.
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    The first thing I would do is fire up Fiddler or Wireshark and look at the actual request. See how much time the request actually takes. What you need to determine is whether there is a delay before the request is actually sent out (in this case when firing off the Post, Unity (or Mono in this case) may have some delay before the network request actually goes out) or the other case in which the server is just slow to respond. If the time between request and response is consistent with the editor results, then the slowness is coming from the net implementation... but if the request is slow, then it's the communication with the server that's the issue. Out of curiosity... when building the application as an executable, are you building it in Developer / Debug mode or in production mode? Make sure any DLLs you might be compiling and including as part of your plugins are compiled in Release mode (if you're using any) and that you're not building your app in Development mode and then see if there is a difference as well.