OpenAPITools / OpenAPITools/openapi-generator
[REQ][RUBY] Use `Faraday`'s Persistent HTTP Adapter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem?
When using standard Faraday, the default adapter is net-http. This uses Ruby's stdlib Net::HTTP / Faraday's Net::HTTP adapter to create a new TCP socket and close it upon every request.
Doing this every time for clients that make a high # of requests tend to add an extra latency span, since we are:
- Not re-using the TCP Socket.
- Creating and closing a TCP Socket for each request.
- Going through the TCP Network Protocol.
If you take a look here it calls http#start, then within the Ruby block, it calls opened_http#request.
Looking in Net::HTTP here the #start call ends up opening a new TCP Socket connection with the server.
Then we initiate the request again in Faraday, making two network hops each time.
Describe the solution you'd like
I believe there are a few things that would be needed. We would need to memoize the api client's connection instance. And we would also need to add Faraday's persistent adapter.
I believe using Faraday's net http persistent adapter alleviates this concern as it re-uses the TCP socket and keeps it open for subsequent client requests.
Describe alternatives you've considered
We've tried re-writing our own mustache templates to generate this, but it feels a bit hacky to constantly overwrite the upstream's templates. I haven't spent too much time digging into how the mustache templates work in this library yet - so unfortunately I'm not too familiar where to begin looking 😢
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Ruby Mustache templates in the generator, then compare Faraday's net_http adapter at lib/faraday/adapter/net_http.rb with Ruby Net::HTTP at lib/net/http.rb. Trace how generated clients create connections and determine how the persistent adapter and connection reuse should be integrated; done means repeated requests reuse an open connection without breaking generated clients.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100