Skip to content
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

feat: agent pooling #86

Merged
merged 7 commits into from
Oct 9, 2019
Merged

feat: agent pooling #86

merged 7 commits into from
Oct 9, 2019

Conversation

callmehiphop
Copy link
Contributor

@callmehiphop callmehiphop commented Sep 27, 2019

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #84 🦕

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 27, 2019
@callmehiphop callmehiphop requested a review from a team September 27, 2019 22:23
@callmehiphop
Copy link
Contributor Author

Working on tests, but throwing it out there for early feedback!

@codecov
Copy link

codecov bot commented Sep 27, 2019

Codecov Report

Merging #86 into master will increase coverage by 3.32%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
+ Coverage   69.35%   72.68%   +3.32%     
==========================================
  Files           1        2       +1     
  Lines         359      399      +40     
  Branches       36       41       +5     
==========================================
+ Hits          249      290      +41     
+ Misses        109      108       -1     
  Partials        1        1
Impacted Files Coverage Δ
src/index.ts 67.65% <100%> (-1.71%) ⬇️
src/agents.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75cf110...d736d52. Read the comment docs.

@callmehiphop callmehiphop marked this pull request as ready for review October 8, 2019 18:14
@callmehiphop
Copy link
Contributor Author

@bcoe @JustinBeckwith @stephenplusplus I think I'm ready for a review here whenever some one gets a chance!

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

a few questions about the implementation.

if (!pool.has(key)) {
// tslint:disable-next-line variable-name
const Agent = isHttp ? HTTPAgent : HTTPSAgent;
pool.set(key, new Agent({keepAlive: true}));
Copy link
Contributor

Choose a reason for hiding this comment

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

if I"m reading this correctly, we only cache the agent if reqOpts.forever is true; should this logic be outside of the check for whether the forever key is to be appended.

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'm definitely open to that idea, do you have anything specific in mind?

if (proxy) {
// tslint:disable-next-line variable-name
const Agent = isHttp
? require('http-proxy-agent')
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason we couldn't cache the proxy agent?

Copy link
Contributor

Choose a reason for hiding this comment

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

Last time I suggested this, I think you told us node caches requires under the hood 🤣

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I meant in the Map being used for the pool, we return immediately if a proxy is in use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we could, but I'm not sure if we need to. My understanding for keepAlive (or in request world forever) is that it will pool the underlying sockets and re-use them. Currently neither of the proxy agents we use support such a feature so I don't know if pooling the proxy agents makes sense.

@callmehiphop callmehiphop merged commit b182f51 into googleapis:master Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent pooling/caching
4 participants