Re-use TCP connections across API calls#214
Merged
Merged
Conversation
- Rename Analytics::Request -> Analytics::Transport - Rename Transport#post -> Transport#send - Add Tranport#shutdown to close persistent connections - Re-use Transport object in Analytics::Worker
lubird
approved these changes
Dec 11, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #148.
Summary of changes
Analytics::Request->Analytics::Transportshutdownmethod.Transportseemed like a better nameTransport#post->Transport#sendTransportobject's interface doesn't have to be HTTP-aware, justsendshould do.Tranport#shutdownto close persistent connectionsTransportobject inAnalytics::WorkerFor a commit-wise split of changes, see this diff.
Context
There was a previous failed attempt to fix this in #149. That had to be reverted because of #167. The error happened when many
Analytics::Clientobjects were created, instead of a singleton client (a valid use-case, although uncommon).I was able to trigger the error with this command:
sh -c "ulimit -n 7 && ruby debug.rb"where
debug.rbis this script:(
ulimit -n <number>places a limit on how many files the process can keep open)When I use the old PR (#149), this errors out:
On
master, this runs successfully but takes 24s:Using the code in this PR, the script runs in 12s: