Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loadtest

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadtest - npm Package Compare versions

Comparing version 8.0.2 to 8.0.3

45

bin/tcp-performance.js
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')
}

2

package.json
{
"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.",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc