Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions clients/javascript/lib/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
sanitizeErrorData,
} from './helpers/errors'
import type cacheableLookupType from 'cacheable-lookup'
import type httpsType from 'node:https'
import type httpType from 'node:http'
import type * as agentkeepaliveModuleType from 'agentkeepalive'

/**
* Configuration for the keep alive feature
Expand All @@ -40,10 +39,6 @@ export type KeepAliveConfig = {
* Maximum number of free sockets to keep alive
*/
maxFreeSockets?: number
/**
* Keep alive milliseconds (how long to keep the connection alive)
*/
keepAliveMsecs?: number
}

/**
Expand Down Expand Up @@ -419,13 +414,15 @@ export const createAxiosInstanceBackend = async (

if (args.baseUrl.startsWith('https')) {
// Import the module here to avoid loading this module in the browser
const https: typeof httpsType = require('node:https')
const agentkeepalive: typeof agentkeepaliveModuleType = require('agentkeepalive')
// Default values are what we evaluated to be good for our load
const httpsAgent = new https.Agent({
const httpsAgent = new agentkeepalive.HttpsAgent({
keepAlive: true,
maxSockets: args.keepAlive.maxSockets ?? 75,
maxFreeSockets: args.keepAlive.maxFreeSockets ?? 10,
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
freeSocketTimeout: 15000, // closes idle connections after 15s
socketActiveTTL: 600000, // force recycle even active sockets after 10min
timeout: 60000, // timeout after 1min
})

if (args.keepAlive.useCacheableLookupDNS) {
Expand All @@ -434,13 +431,15 @@ export const createAxiosInstanceBackend = async (
config.httpsAgent = httpsAgent
} else {
// Import the module here to avoid loading this module in the browser
const http: typeof httpType = require('node:http')
const agentkeepalive: typeof agentkeepaliveModuleType = require('agentkeepalive')
// Default values are what we evaluated to be good for our load
const httpAgent = new http.Agent({
const httpAgent = new agentkeepalive.HttpAgent({
keepAlive: true,
maxSockets: args.keepAlive.maxSockets ?? 75,
maxFreeSockets: args.keepAlive.maxFreeSockets ?? 10,
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
freeSocketTimeout: 15000, // closes idle connections after 15s
socketActiveTTL: 600000, // force recycle even active sockets after 10min
timeout: 60000, // timeout after 1min
})

if (args.keepAlive.useCacheableLookupDNS) {
Expand Down
1 change: 1 addition & 0 deletions clients/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"agentkeepalive": "4.6.0",
"axios": "1.12.2",
"axios-retry": "4.5.0",
"cacheable-lookup": "^6.1.0",
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.