From ed56a3990c2b85828c2c5e49b6d46a291abdfeb2 Mon Sep 17 00:00:00 2001 From: eddienubes Date: Sat, 10 Feb 2024 17:39:58 +0100 Subject: [PATCH 1/2] feat: added superagent to benchmark.js --- benchmarks/benchmark.js | 11 +++++++++++ package.json | 2 ++ 2 files changed, 13 insertions(+) diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index 32b761a8a56..6a2d9e8a082 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -10,6 +10,7 @@ const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..') let nodeFetch const axios = require('axios') +const superagent = require('superagent') let got const util = require('node:util') @@ -318,6 +319,16 @@ if (process.env.PORT) { }).catch(console.log) }) } + + experiments.superagent = () => { + return makeParallelRequests(resolve => { + superagent.get(dest.url).pipe(new Writable({ + write (chunk, encoding, callback) { + callback() + } + })).on('finish', resolve) + }) + } } async function main () { diff --git a/package.json b/package.json index 1ce1a058b1b..7e4f45594d4 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "@matteo.collina/tspl": "^0.1.1", "@sinonjs/fake-timers": "^11.1.0", "@types/node": "^18.0.3", + "@types/superagent": "^8.1.3", "abort-controller": "^3.0.0", "axios": "^1.6.5", "borp": "^0.9.1", @@ -128,6 +129,7 @@ "sinon": "^17.0.1", "snazzy": "^9.0.0", "standard": "^17.0.0", + "superagent": "^8.1.2", "tap": "^16.1.0", "tsd": "^0.30.1", "typescript": "^5.0.2", From 9cf1023781791f9479cfa53d985d6e22f3c97f3f Mon Sep 17 00:00:00 2001 From: eddienubes Date: Sun, 11 Feb 2024 10:15:09 +0100 Subject: [PATCH 2/2] feat: added custom http agent to superagent --- benchmarks/benchmark.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index 6a2d9e8a082..f63ece5ed16 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -10,7 +10,7 @@ const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..') let nodeFetch const axios = require('axios') -const superagent = require('superagent') +let superagent let got const util = require('node:util') @@ -86,6 +86,11 @@ const requestAgent = new http.Agent({ maxSockets: connections }) +const superagentAgent = new http.Agent({ + keepAlive: true, + maxSockets: connections +}) + const undiciOptions = { path: '/', method: 'GET', @@ -337,6 +342,9 @@ async function main () { nodeFetch = _nodeFetch.default const _got = await import('got') got = _got.default + const _superagent = await import('superagent') + // https://github.com/ladjs/superagent/issues/1540#issue-561464561 + superagent = _superagent.agent().use((req) => req.agent(superagentAgent)) cronometro( experiments,