HttpClient vs YARP Direct Forwarding #2220
-
I vaguely remember reading somewhere about suggesting to use YARP Direct Forwarding for performance reasons in cases where an API needs to call another API without much business logic. I couldn't locate the source, nor do I recollect where I came across it. Recently, our team stumbled upon a very similar scenario and I was wondering may be should this be one of the options to optimize the API. But, since YARP internally uses HTTPClient anyways, I was little doubtful as to the performance gain it can offer. So, I went on to test it out and see how they both compare. This is the repo I created with a minimal sample - as can be seen in readme.md, the test results produced have very similar results for both cases with non-YARP method having better throughput & response time as the load increases. Wanted to understand,
Sample Repo URL: https://github.com/jjkcharles/Yarp-HttpClient-Performance-Analysis |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If direct forwarding is adequate for your needs then yes, it can save a few layers of abstraction/middleware. However, this isn't going to show up in the perf benchmarks for your average application, your scale would have to be huge for it to be relevant. |
Beta Was this translation helpful? Give feedback.
Wait, sorry, I completely misread that 🥱😂. Direct forwarding will only be faster than using HttpClient directly if our implementation is more optimized than yours. We do lots of tricks like streaming, zero-byte reads, buffer pooling, etc. that your average application wouldn't attempt. You also need to hit a pretty high scale before it's relevant.