@jcyrss/hyload
v0.1.4
Published
Node.js performance testing framework
Maintainers
Readme
hyload
hyload is a Node.js library for writing HTTP/API load test scripts.
Install
npm install @jcyrss/hyloadExports
import {
Stats,
HttpClient,
HttpResponse,
runTask,
waitForTasksDone,
sleep
} from '@jcyrss/hyload';Quick Start
import { Stats, HttpClient, runTask, waitForTasksDone, sleep } from '@jcyrss/hyload';
Stats.start();
async function behavior(username, password) {
const client = new HttpClient({ timeout: 10000, connections: 4 });
try {
const res = await client.post('http://127.0.0.1/api/mgr/signin', {
data: { username, password }
});
if (res.statusCode !== 200) {
Stats.one_error('signin failed');
}
} finally {
await client.close();
}
}
for (let i = 0; i < 10; i++) {
runTask(behavior, `user${i}`, '88888888');
await sleep(1000);
}
await waitForTasksDone();HttpClient options
timeout: request timeout in milliseconds, default10000connections: max connections per origin within the selected pool scope, default1000poolScope: connection reuse scope, one ofclient(default),global, ornonepipeliningis fixed to1debug: set totrueto print request and response URL, headers, and body
client reuses keep-alive connections only inside the current HttpClient instance, which is the default and better matches one virtual user owning one client session. global keeps the old process-wide shared pool behavior. none disables keep-alive reuse and sends requests with Connection: close.
If you create short-lived HttpClient instances, call await client.close() when the virtual user finishes so idle sockets are released promptly.
Monitor
stats_center is a local Node.js monitor for loading existing stats files, merging per-second data, and showing charts in the browser.
Start
npx hyload-stats-centerBy default it listens on http://127.0.0.1:14799.
You can change the host and port with environment variables:
set STATS_CENTER_HOST=0.0.0.0
set STATS_CENTER_PORT=14799
npx hyload-stats-centerYou can also pass command line arguments directly:
npx hyload-stats-center --host 0.0.0.0 --port 14799On Windows PowerShell, the generated
hyload-stats-center.ps1shim may be blocked. If that happens, runhyload-stats-center.cmdorcmd /c hyload-stats-centerinstead.
Features
- Displays listening address and health status
- Draws
rps/tps/tops/eps/avgRespTimewith ECharts - Shows aggregated sender counts
- Provides
PlotandClearbuttons
