Giter VIP home page Giter VIP logo

Comments (3)

SydneyDrone avatar SydneyDrone commented on August 22, 2024

Turns out to be a local network environment issue. Closed.

from godotenv.

SydneyDrone avatar SydneyDrone commented on August 22, 2024

Turns out to be a local network environment issue. Closed.

More specificly speaking, the DNS of raw.githubusercontent.com is polluted and it will point to localhost. By default the HttpClient.cs uses IE proxy settings, but the proxy setting will bypass localhost. In that case, we have to declare the proxy explicitly when instanciating HttpClient's creation to solve this problem.
Now since the DNS Pollution is not my personal scienario but happens in the whole Mainland China, I think it's valuable to add proxy support for godotenv, hence reopening this issue.

from godotenv.

SydneyDrone avatar SydneyDrone commented on August 22, 2024

Now after adding the explicit proxy support, the WebRequestGetAsync() function in NetworkClient well looks like this:

public async Task<HttpResponseMessage> WebRequestGetAsync(string url, string? proxyUrl = null) {
  var proxy = string.IsNullOrEmpty(proxyUrl) ? WebRequest.GetSystemWebProxy() : new WebProxy(proxyUrl);
  var factory = new ServiceCollection()
    .AddHttpClient(Options.DefaultName)
    .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { Proxy = proxy })
    .Services
    .BuildServiceProvider()
    .GetService<IHttpClientFactory>();

  var client = factory.CreateClient();

  return await client.GetAsync(url);
}

Now we can see that there might be potential performance issue, since we cached the http client in the current version, but create a factory each time the function is executed. So what is the real situation?

I have used BenchmarkDotNet to get the same 3 pages in 3 ways: no cache, cache the factory, cache the client, and the result looks like that:

Method Mean Error StdDev
TestNoCache 1,634.2 ms 32.55 ms 72.80 ms
TestCacheFactory 359.0 ms 6.82 ms 7.29 ms
TestCacheClient 351.5 ms 6.10 ms 5.41 ms

Need to mention that this is the result of the second time, the first time I run this test, the mean time of TestCacheClient goes to 600ms.

from godotenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.