-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorder * Separate derived results * Move compute percentiles from latency to result * Start test server in half the cores by default * Refactor a bit * Move multicore code to its own file * Run single-core if cores=1 * Run loadtest in multicore with --cores * Do not use deprecated api * Moved multicore to cluster * Make cluster work with scheduling policy none * Aggregate all results from all workers * Function to combine results * Reject result when there is an error in the cluster * New test to combine results * New test for results * Combine results in map * Add test for empty and complex results * Show how many cores the test run on * Combine histogram correctly * Reset all values before combining * Check elapsed seconds * Show results from workers * Share values amongst cores * Reorder * Wait for server to start * Remove traces * Divide max requests and rps by cores only if present * Share requests and rps properly among cores * Share rps and max requests properly between cores * Show target and effective rps * Show effective rps last * Rename * Store start and end times in ns and ms * Compute elapsed seconds as derivative of start and end times * Improve docs for result * Show cores only if specified * Document --cores * v6.3.0 * Clarify --cores in the API
- Loading branch information
1 parent
93f2d5c
commit ee36172
Showing
11 changed files
with
389 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
process.env.NODE_CLUSTER_SCHED_POLICY = 'none' | ||
|
||
import {cpus} from 'os' | ||
// dynamic import as workaround: https://github.com/nodejs/node/issues/49240 | ||
const cluster = await import('cluster') | ||
|
||
|
||
export function getHalfCores() { | ||
const totalCores = cpus().length | ||
return Math.round(totalCores / 2) || 1 | ||
} | ||
|
||
export async function runTask(cores, task) { | ||
if (cores == 1) { | ||
return [await task()] | ||
} | ||
if (cluster.isPrimary) { | ||
return await runWorkers(cores) | ||
} else { | ||
const result = await task(cluster.worker.id) | ||
process.send(result) | ||
} | ||
} | ||
|
||
function runWorkers(cores) { | ||
return new Promise((resolve, reject) => { | ||
const results = [] | ||
for (let index = 0; index < cores; index++) { | ||
const worker = cluster.fork() | ||
worker.on('message', message => { | ||
results.push(message) | ||
if (results.length === cores) { | ||
return resolve(results) | ||
} | ||
}) | ||
worker.on('error', error => { | ||
return reject(error) | ||
}) | ||
} | ||
}) | ||
} | ||
|
Oops, something went wrong.