Coder Social home page Coder Social logo

Comments (19)

abergs avatar abergs commented on May 18, 2024 1

I used https://github.com/codesenberg/bombardier to generate the load and fetched a HTML url that weighs around 10kb with 125 concurrent connections for 7m.

Before i run proxykit i just read a string value from the headers with a date, like "deployment-190624-1111".

It ran on my laptop (with other apps running) so the benchmark should not be treated like a sure thing and would probably vary a lot depending on profiling.
However, the reflection caused a lot of queued Finalization so the optimization is probably a good thing. The "GetRequiredService" should probably not be done by the client but somewhere "up the chain" in ProxyKit (not in the hotpath) or cached in a sane manner.

Spec:
Win 10 Enterprise latop
CPU: i7 7820 @ 2,90 GHz 4 cores, 8 logical.
16GB ram.

from proxykit.

rynowak avatar rynowak commented on May 18, 2024 1

Thanks for the report, I'm following up on this.

from proxykit.

abergs avatar abergs commented on May 18, 2024

I cloned the repo and made a (perhaps) ugly test by adding ProxyKitClient as a optional argument in the Forwardto-method.
image

I instead initialized it once in startup and re-use that instance.

This removed the Finalized objects observed earlier.
Still seeing bumpy memory allocations though.

Edit: It also improved througput with ~12% (4MB/s to 4,6MB/s)

from proxykit.

damianh avatar damianh commented on May 18, 2024

Awesome report!

Can you share your test project on github? I feel the total request count is a bit on the low side 🤔 . I'd like to locally reproduce what you are seeing.

Thanks!

from proxykit.

abergs avatar abergs commented on May 18, 2024

@damianh Do you mean the fork of ProxyKit or "my application" using it? The application is unfortunately not something I can open source... but it's a small .net core app that maps a route, does some header parsing and then forwardsTo.

from proxykit.

damianh avatar damianh commented on May 18, 2024

Post the fork changes to a branch on your repo for a start. I don't need your application but maybe some indication of what it does so I can put the total requests into some context. If you can, please share your proxy config (header parsing etc), what tool you are using to generate the load and maybe some indication of the system it is being run on.

Would like to get to as like-for-like as possible.

from proxykit.

damianh avatar damianh commented on May 18, 2024

v2.2.1 is on nuget.org with this specific issue addressed. I'll do further profiling in a subsequent release.

from proxykit.

saithis avatar saithis commented on May 18, 2024

@damianh Doesn't this now only instantiate HttpClient once and always use this single intance? If I remember correctly, then this has the sideeffect, that DNS ttl is ignored.

Last time I checked, the HttpClientFactory switched the HttpClientHandler (which resolves each DNS only once) for new HttpClients every few minutes so that the DNS ttl is respected, but that doesn't work if the HttpClient is kept as a singleton.

from proxykit.

damianh avatar damianh commented on May 18, 2024

Hmm, thought it rebuilt the handlers internally..
Will check asap and revert if so.

from proxykit.

damianh avatar damianh commented on May 18, 2024

I've unlisted the 2.1.1 package pending investigation.

from proxykit.

damianh avatar damianh commented on May 18, 2024

Yes, it seems that HttpClient (via ProxyKitClient) needs to be considered transient and activated and retrieved on per-request basis. I've reverted #125 and related changes.

I'll profile things to see what can be done wrt allocations.

from proxykit.

saithis avatar saithis commented on May 18, 2024

Maybe you can inject the IHttpClientFactory (which is a singleton) and call CreateClient() when needed to get the HttpClient. If that doesn't solve the allocation problem, then you could probably cache the created HttpClient for a short duration. A setting for the duration would then be useful with duration 0/null equals no caching.

from proxykit.

damianh avatar damianh commented on May 18, 2024

That is what I am currently thinking except it means I can't use a typed client. (May or may not be an issue).

Am gonna profile before first so I have some local data to work with

from proxykit.

damianh avatar damianh commented on May 18, 2024

Did a mini profile and the difference between resolving a typed client and named client is surprisingly large:

image

Thus I don't think it's GetRequiredService<> per se, but activation of the typed client.

I'm going to move to using named client.

from proxykit.

damianh avatar damianh commented on May 18, 2024

It's not a cache warm up issue either

image

from proxykit.

damianh avatar damianh commented on May 18, 2024

Regarding the rest of the bumpy memory usage, I suspect it's heavily related to allocation regarding HttpClient usage. I don't know how much I can optimize there from the outside (i.e. object pooling) but will dig in separately.

from proxykit.

damianh avatar damianh commented on May 18, 2024

@abergs 2.1.2 on nuget.org. Thanks again for the report.

from proxykit.

damianh avatar damianh commented on May 18, 2024

Further validation that the problem appears to be in HttpClientFactory

from proxykit.

abergs avatar abergs commented on May 18, 2024

Fixed here: dotnet/extensions#2063

from proxykit.

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.