Comparing version 8.0.2 to 8.0.3
import {loadTest, startServer} from '../index.js' | ||
const cluster = await import('cluster') | ||
import {getHalfCores} from '../lib/cluster.js' | ||
const port = 7359; | ||
const port = 7360; | ||
const serverOptions = {port} | ||
if (cluster.isPrimary) { | ||
await runTcpPerformanceTest() | ||
} else { | ||
await runServer() | ||
} | ||
async function runTcpPerformanceTest() { | ||
const server = await startServer(serverOptions) | ||
const workers = await startWorkers() | ||
const options = { | ||
@@ -13,10 +20,38 @@ url: `http://localhost:${port}`, | ||
tcp: true, | ||
concurrency: 10, | ||
}; | ||
const result = await loadTest(options) | ||
await server.close() | ||
console.log(`Requests received: ${server.totalRequests}`) | ||
result.show() | ||
console.log(`Test finished; closing server on ${workers.length} cores`) | ||
await stopServer(workers) | ||
} | ||
await runTcpPerformanceTest() | ||
function startWorkers() { | ||
return new Promise(resolve => { | ||
const cores = getHalfCores() | ||
const workers = [] | ||
for (let i = 0; i < cores; i++) { | ||
const worker = cluster.fork() | ||
worker.on('message', async () => { | ||
workers.push(worker) | ||
if (workers.length != cores) { | ||
return | ||
} | ||
console.log(`Server started on ${workers.length} cores`) | ||
return resolve(workers) | ||
}) | ||
} | ||
}) | ||
} | ||
function stopServer(workers) { | ||
for (const worker of workers) { | ||
worker.kill('SIGTERM') | ||
} | ||
} | ||
async function runServer() { | ||
await startServer(serverOptions) | ||
process.send('server ready') | ||
} | ||
{ | ||
"name": "loadtest", | ||
"version": "8.0.2", | ||
"version": "8.0.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Run load tests for your web application. Mostly ab-compatible interface, with an option to force requests per second. Includes an API for automated load testing.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149407
2863