Skip to content

Expose pool_size as a option for the NetHttpPersistent adapter #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 26, 2018

Conversation

col
Copy link
Contributor

@col col commented Nov 23, 2018

Expose pool_size as a connection option for the NetHttpPersistent adapter

Fixes: #833

Description

  • Note: connection pool was only added to net-http-persistent from version 3.0
  • The pool_size constructor param in Net::HTTP::Persistent has a default value so I've been careful to ensure this will still use the default behaviour when the pool_size adapter option is not provided.

Todos

List any remaining work that needs to be done, i.e:

  • Tests
  • Documentation

Additional Notes

...

Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test coverage, however I believe the implementation can be improved and simplified a bit.
Please see my comment below and let me know your thoughts.

Net::HTTP::Persistent.new(name: 'Faraday')
options = {}
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
Net::HTTP::Persistent.new(name: 'Faraday', **options)
Copy link
Member

@iMacTia iMacTia Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above can be rewritten as:

options = {name: 'Faraday'}.merge(@connection_options.slice(:name, :pool_size)
Net::HTTP::Persistent.new(options)

This way we:

  • Simplify the filtering using slice
  • Allow to override the connection name
  • Fix the issue with Ruby 1.9.3 which supports named parameters but doesn't support the double split operator (**)

proxy would also be a valid key, but I'd not slice it in as Faraday manages the proxy separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe slice is only available in rails.

I've updated the the PR but only with a small improvement to fix the 1.9.3 issue.
Out of time now but feel free to refactor if you have any other ideas.

Copy link
Member

@iMacTia iMacTia Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it in the console to be sure and it worked, but I just found out that's because it was also added to Ruby 2.5 🤦‍♂️.
You're right, it's not available in Ruby 2.4 or before unless using activesupport.
The new implementation doesn't allow to customise name though, but that was never part of the issue you opened so I guess we can leave that out for now 👍

@col
Copy link
Contributor Author

col commented Nov 23, 2018 via email

@iMacTia
Copy link
Member

iMacTia commented Nov 23, 2018

Why not, sounds like a great idea 😃

@iMacTia iMacTia merged commit f18a248 into lostisland:master Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants