fix(customs): Update customs axios maxSockets and timeoutMs

This commit is contained in:
Vijay Budhram 2024-02-07 14:22:45 -05:00
parent 4e79b11733
commit b8eab28c4a
No known key found for this signature in database
GPG Key ID: 9778545895B2532B
4 changed files with 78 additions and 8 deletions

View File

@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Load testing script for the FxA Auth Server.
*
* 1. Ensure `k6` is installed. [official k6 installation guide](https://k6.io/docs/getting-started/installation/)
* 3. Execute the script with the command: `k6 run script.js`.
*
*/
import http from 'k6/http';
export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: '30s',
};
export default function() {
const url = 'http://127.0.0.1:9000/v1/account/status';
// const url = 'https://api-accounts.stage.mozaws.net/v1/account/status';
const payload = JSON.stringify({
'email': 'a@aa.com',
'thirdPartyAuthStatus': true,
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
http.post(url, payload, params);
}

View File

@ -340,6 +340,28 @@ const convictConf = convict({
default: 'http://localhost:7000',
env: 'CUSTOMS_SERVER_URL',
},
customsHttpAgent: {
maxSockets: {
doc: 'The maximum number of sockets to be opened per host',
default: 10000,
env: 'CUSTOMS_MAX_SOCKETS',
},
maxFreeSockets: {
doc: 'The maximum number of free sockets to keep open for a host',
default: 10,
env: 'CUSTOMS_MAX_FREE_SOCKETS',
},
timeoutMs: {
doc: 'The timeout in milliseconds for the sockets',
default: 30000,
env: 'CUSTOMS_TIMEOUT_MS',
},
freeSocketTimeoutMs: {
doc: 'The time in milliseconds for which a socket should remain open while unused',
default: 15000,
env: 'CUSTOMS_FREE_SOCKET_TIMEOUT_MS',
},
},
contentServer: {
url: {
doc: 'The url of the corresponding fxa-content-server instance',

View File

@ -21,11 +21,23 @@ class CustomsClient {
this.log = log;
this.error = error;
this.statsd = statsd;
const customsHttpAgent = config.get('customsHttpAgent');
if (url !== 'none') {
this.axiosInstance = axios.create({
baseURL: url,
httpAgent: createHttpAgent(),
httpsAgent: createHttpsAgent(),
httpAgent: createHttpAgent(
customsHttpAgent.maxSockets,
customsHttpAgent.maxFreeSockets,
customsHttpAgent.timeoutMs,
customsHttpAgent.freeSocketTimeoutMs
),
httpsAgent: createHttpsAgent(
customsHttpAgent.maxSockets,
customsHttpAgent.maxFreeSockets,
customsHttpAgent.timeoutMs,
customsHttpAgent.freeSocketTimeoutMs
),
});
}
}

View File

@ -14,10 +14,10 @@ import Agent from 'agentkeepalive';
* @returns {Agent} An instance of Agent, configured with the specified settings.
*/
export function createHttpAgent(
maxSockets = 100,
maxSockets = 1000,
maxFreeSockets = 10,
timeoutMs = 60000,
freeSocketTimeoutMs = 30000
timeoutMs = 30000,
freeSocketTimeoutMs = 15000
) {
return new Agent({
maxSockets,
@ -37,10 +37,10 @@ export function createHttpAgent(
* @returns {Agent.HttpsAgent} An instance of Agent.HttpsAgent, configured with the specified settings.
*/
export function createHttpsAgent(
maxSockets = 100,
maxSockets = 1000,
maxFreeSockets = 10,
timeoutMs = 60000,
freeSocketTimeoutMs = 30000
timeoutMs = 30000,
freeSocketTimeoutMs = 15000
) {
return new Agent.HttpsAgent({
maxSockets,