Comments (19)
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.
Thanks for the report, I'm following up on this.
from proxykit.
I cloned the repo and made a (perhaps) ugly test by adding ProxyKitClient as a optional argument in the Forwardto-method.
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.
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.
@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.
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.
v2.2.1 is on nuget.org with this specific issue addressed. I'll do further profiling in a subsequent release.
from proxykit.
@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.
Hmm, thought it rebuilt the handlers internally..
Will check asap and revert if so.
from proxykit.
I've unlisted the 2.1.1 package pending investigation.
from proxykit.
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.
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.
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.
Did a mini profile and the difference between resolving a typed client and named client is surprisingly large:
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.
It's not a cache warm up issue either
from proxykit.
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.
@abergs 2.1.2 on nuget.org. Thanks again for the report.
from proxykit.
Further validation that the problem appears to be in HttpClientFactory
- https://twitter.com/thoemmi/status/1149655040686055425
- https://twitter.com/davidfowl/status/1149648815147741184
from proxykit.
Fixed here: dotnet/extensions#2063
from proxykit.
Related Issues (20)
- 502 Bad Gateway - Azure HOT 8
- Reverse proxy failing for upstream with invalid certificate HOT 1
- 301 response from upstream service causes InvalidOperationException HOT 1
- Is this project dead? HOT 3
- Can I simulate post to log in a website and then reverse it? HOT 1
- Drop TestServer HOT 2
- Run on dedicated endpoint HOT 2
- ProxyKit, YARP and planned obsolescence. HOT 2
- Incorrect forwarding of multiple cookies HOT 4
- Is it possible to route requests to multiple domains? HOT 1
- Is it possible to create end-point along proxying request to upstream services. HOT 1
- Catching WebSocketException HOT 1
- How to set proxy IP with webapi in upstream request? HOT 2
- ForwardTo to a VPN with NetworkCredentials? HOT 1
- How to proxy requests with routing to controllers? HOT 1
- Does that API support to function as a normal http proxy (forward proxy)? HOT 1
- Caching Forwarded Responses HOT 2
- hey! guys, I proxy the web api, how can I delete the response header? HOT 1
- How to log errors? HOT 1
- Migrate to YARP - step by step HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxykit.