• 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
0
Question by YianC · Dec 16, 2021 at 02:51 AM · networkwebrequesthttpwebrequest

UnityWebRequest very slow

We found that when we built a project with Unity 2020.3.22 and noticed that the duration of sending a webRequest and receiving the response is really long!

We also tried to build the project with Unity 2021.2.4 (the latest version) but the duration is still long. So we tried to build it with Unity 2020.3.7 and found that the duration is short!

In this case, we call the same address “https://www.google.com/” and we are in the same predicament when we call the game server.

Here’s the details for your reference.

     /// <summary>
     /// connect url
     /// </summary>
     [SerializeField]
     string _url = "https://www.google.com/";
 
     /// <summary>
     /// Send UnityWebRequest
     /// </summary>
     public void SendGetRequest()
     {
         if (_Coroutine == null)
         {
             _startTime = Time.realtimeSinceStartup;
             
             _Coroutine = StartCoroutine(SendGet());
         }
     }
 
     IEnumerator SendGet()
     {
         UnityWebRequest webRequest = UnityWebRequest.Get(_url);
         //webRequest.timeout = _timeOut;
         webRequest.useHttpContinue = false;
         yield return webRequest.SendWebRequest();
 
         if (webRequest.result == UnityWebRequest.Result.ProtocolError ||
             webRequest.result == UnityWebRequest.Result.ConnectionError)
             _OnLogEvent.Invoke(string.Format("[Log] UnityWebRequest error \n -url = {0} \n -result = {1}", _url, webRequest.error));
         else
         {
             float spendTime = Time.realtimeSinceStartup - _startTime;
             _OnLogEvent.Invoke(string.Format("[Log] UnityWebRequest success \n -url = {0} \n -spendTime = {1}", _url, spendTime));
         }
         _Coroutine = null;
 
         yield return null;
     }![alt text][1]


[1]: /storage/temp/190021-testtime.jpg

testtime.jpg (446.6 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Dec 16, 2021 at 11:22 AM

You seem to have a strange view what is long and what is short. When I load google in Firefox and check the network tab (and the time sub tab) how long the response just for the main page took, it's about 143ms on my machine. The difference between your tests is under twice the time. There could be countless reasons for that. It's possible that Unity changed the security layer. When testing inside my browser google uses elliptic curve cryptography while in the past (and still used today) RSA was more common. HTTPS is "relatively" slow by definition since it always includes a TLS connection which is the main part which makes the request slow. Also since you use a coroutine ,which is absolutely correct, the response can only be processed at the next frame after the response arrived. So you get an additional 0 up to detlaTime seconds delay per request. So on average half the frame time.


Furthermore your current test is violating google's terms of services because the website is meant for human interaction and extensive bot usage is not allowed. So google "may" even detect the user agent of the Unity player and artificially delay the response to trottle traffic. You said you have a similar issue when connecting to your own server? As I said, webrequests are inherently slow, especially when doing seperate requests. While for certain game types using HTTP / HTTPS is fine, it's certainly not suitable for most realtime environments. So I'm not sure what you're asking here. Technologies changes and you will always see differences between Unity versions. Though the response times are completely in the reasonable range for HTTPS, so I'm not sure what you expect.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

161 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityWebRequest returns different errors for right urls 0 Answers

Try catch alternative for HTTP request 1 Answer

Capturing and Tracing All HTTP Requests in Unity project 0 Answers

What is a good cross-platform alternative to WWW? 0 Answers

About Implemented host name resolution with IPv6 in Unity 4.6.9 release-notes. 0 Answers


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