WebRequest is very slow with IPV6 and server in IPv4 and IPv6

I have a machine configured to use IPv6 by default.

My server is located locally on an IPv4 machine.


My problem:

  • When I run the code below, it runs in the 21st.
  • When I change IPv6 to IPv4, the code runs in 127 ms.

Where is the mistake?

 [TestMethod()]
        public  void Test()
        {
            string url = "myurlserverIPv4";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Proxy = null;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    reader.ReadToEnd();
                }
            }

        }

Thank you in advance

Edit 1 : the machine responds with its ipv6 address

Edit 2 : Following “ user3193469 ”, I did additional tests

  • With an IPv4 address, code is executed for 80 ms

  • When mapping an IP address to a host name, the code is executed in 80 ms with the host name. Fixed

  • Without displaying in the host file, the code is executed for 21 ms.

So this is the problem of resolving the host name.

+4

Source: https://habr.com/ru/post/1607245/


All Articles