Support configurable maxSockets for HTTP agents#260
Open
jackie-nooks wants to merge 1 commit intomixpanel:masterfrom
Open
Support configurable maxSockets for HTTP agents#260jackie-nooks wants to merge 1 commit intomixpanel:masterfrom
jackie-nooks wants to merge 1 commit intomixpanel:masterfrom
Conversation
The SDK creates HTTP agents with keepAlive: true but uses the Node.js
default maxSockets: Infinity. In high-throughput server environments,
concurrent track() calls can open an unbounded number of TCP connections
to Mixpanel's API, which can exhaust file descriptors or trigger rate
limits.
This adds support for a maxSockets init config option that gets passed
through to the underlying http.Agent / https.Agent. When not set,
behavior is unchanged (defaults to Infinity).
Usage:
var mixpanel = Mixpanel.init('token', { maxSockets: 10 });
Confab-Link: https://confab.nooks.in/sessions/e7243277-5942-4965-8abe-99b18914a204
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.
Summary
The SDK creates HTTP agents with
keepAlive: truebut uses the Node.js defaultmaxSockets: Infinity. In high-throughput server environments, concurrenttrack()calls can open an unbounded number of TCP connections to Mixpanel's API, which can exhaust file descriptors or trigger rate limits.This PR adds support for a
maxSocketsinit config option that gets passed through to the underlyinghttp.Agent/https.Agent. When not set, behavior is unchanged (defaults toInfinity).Usage
Changes
lib/mixpanel-node.js: ReadmaxSocketsfrom init config and pass to Agent constructorstest/send_request.js: Test verifyingmaxSocketsis forwarded to the Agentreadme.md: Usage example📝 Confab link