loadtest 8.0.2 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tcp-performance.js +40 -5
- package/package.json +1 -1
package/bin/tcp-performance.js
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
import {loadTest, startServer} from '../index.js'
|
|
2
|
+
const cluster = await import('cluster')
|
|
3
|
+
import {getHalfCores} from '../lib/cluster.js'
|
|
2
4
|
|
|
3
|
-
const port =
|
|
5
|
+
const port = 7360;
|
|
4
6
|
const serverOptions = {port}
|
|
5
7
|
|
|
8
|
+
if (cluster.isPrimary) {
|
|
9
|
+
await runTcpPerformanceTest()
|
|
10
|
+
} else {
|
|
11
|
+
await runServer()
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
async function runTcpPerformanceTest() {
|
|
8
|
-
const
|
|
15
|
+
const workers = await startWorkers()
|
|
9
16
|
const options = {
|
|
10
17
|
url: `http://localhost:${port}`,
|
|
11
18
|
method: 'GET',
|
|
12
19
|
tcp: true,
|
|
20
|
+
concurrency: 10,
|
|
13
21
|
};
|
|
14
22
|
const result = await loadTest(options)
|
|
15
|
-
await server.close()
|
|
16
|
-
console.log(`Requests received: ${server.totalRequests}`)
|
|
17
23
|
result.show()
|
|
24
|
+
console.log(`Test finished; closing server on ${workers.length} cores`)
|
|
25
|
+
await stopServer(workers)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function startWorkers() {
|
|
29
|
+
return new Promise(resolve => {
|
|
30
|
+
const cores = getHalfCores()
|
|
31
|
+
const workers = []
|
|
32
|
+
for (let i = 0; i < cores; i++) {
|
|
33
|
+
const worker = cluster.fork()
|
|
34
|
+
worker.on('message', async () => {
|
|
35
|
+
workers.push(worker)
|
|
36
|
+
if (workers.length != cores) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
console.log(`Server started on ${workers.length} cores`)
|
|
40
|
+
return resolve(workers)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
18
44
|
}
|
|
19
45
|
|
|
20
|
-
|
|
46
|
+
function stopServer(workers) {
|
|
47
|
+
for (const worker of workers) {
|
|
48
|
+
worker.kill('SIGTERM')
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function runServer() {
|
|
53
|
+
await startServer(serverOptions)
|
|
54
|
+
process.send('server ready')
|
|
55
|
+
}
|
|
21
56
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadtest",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"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.",
|
|
6
6
|
"homepage": "https://github.com/alexfernandez/loadtest",
|