Skip to content

Commit 2c0c18e

Browse files
committed
Add comments to the implementation
1 parent 293a22c commit 2c0c18e

5 files changed

Lines changed: 15 additions & 1 deletion

File tree

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { createLightship } = require('lightship');
77
* https://nodejs.org/api/cluster.html
88
*/
99
const cluster = require('cluster');
10+
//Get the number of CPUs available
1011
const CPUs = require('os').cpus().length;
1112

1213
/**
@@ -15,6 +16,10 @@ const CPUs = require('os').cpus().length;
1516
*/
1617
const ls = createLightship();
1718

19+
/**
20+
* If the cluster module is avaible
21+
* and the process is the master
22+
*/
1823
if(config.get('App.cluster.enabled') && cluster.isMaster) {
1924
log.info(`Master ${process.pid} is running`);
2025

src/routes/threads.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ router.get('/fibonacciThreadedShared', async (req, res) => {
2727
* Uses shared SharedArrayBuffer to share data with the workers
2828
*/
2929
const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
30-
for(let i= 0; i< 4; i++) {
30+
for (let i = 0; i < 4; i++) {
3131
runFibonacciShared({ iterations: 1000, position: i, arr: sharedUint8Array }).then(result => console.log(result));
3232
}
3333
res.send('processing');

src/workers/fibonacciWorker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const runFibonacci = workerData => {
1212
});
1313
};
1414

15+
/**
16+
* If it's not the main thread it's one of the Worker threads
17+
*/
1518
if (!isMainThread) {
1619
const result = fb.iterate(workerData.iterations);
1720
parentPort.postMessage(result);

src/workers/fibonacciWorkerPool.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const runFibonacci = workerData => {
1818
});
1919
};
2020

21+
/**
22+
* If it's not the main thread it's one of the Worker threads
23+
*/
2124
if (!isMainThread) {
2225
const result = fb.iterate(workerData.iterations);
2326
parentPort.postMessage(result);

src/workers/fibonacciWorkerShared.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const runFibonacci = workerData => {
1212
});
1313
};
1414

15+
/**
16+
* If it's not the main thread it's one of the Worker threads
17+
*/
1518
if (!isMainThread) {
1619
const sharedArray = workerData.arr;
1720
const result = fb.iterate(workerData.iterations);

0 commit comments

Comments
 (0)