Skip to content

Commit f287340

Browse files
Hussein NasserHussein Nasser
authored andcommitted
cluster
1 parent fb0a6a1 commit f287340

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

20-streams/200-raw-request-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const http = require("node:http");
22
//request object is a writable stream
33
const req = http.request("http://example.com", { "method": "GET"});
4-
4+
55
req.on("response", res => {
66
//the data events implicity calls read for us
77
//response object is a readeable stream

20-streams/202-raw-httpserver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const http = require("node:http");
44
//run with default, send this request
55
// head -c 10240000 /dev/zero | curl -X POST --data-binary http://192.168.7.179:8080
66
//then run with the overriden hwm
7-
const server = http.createServer({"highWaterMark": 300_000} );
7+
const server = http.createServer({"highWaterMark": 200_000} );
88

99
//const server = http.createServer( );
1010

21-worker-threads/213-worker-thread-workdata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const WorkerThreads = require('node:worker_threads');;
1111
const MaxNumber = 100_000_000
1212
const os = require("os")
1313

14-
const threadCount = 16 //os.availableParallelism; //try to match the core count
14+
const threadCount = 2 //os.availableParallelism; //try to match the core count
1515
//use os.availableParallelism
1616
//spread MaxNumber on threads
1717
//each thread gets workSlice worth

21-worker-threads/214-worker-thread-connection.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ if (WorkerThreads.isMainThread) {
1010

1111
// Create a TCP server on the parent
1212
const server = net.createServer();
13-
14-
// Listen on the port with SO_REUSEPORT
13+
1514
server.listen({ port: PORT},
1615
() => {
1716
console.log(`parent process ${process.pid} is listening on port ${PORT}`);

22-child-process/220-child-process.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ const child_process = require('child_process');
1818
console.log("End parent initial phase")
1919
process.on("exit", ()=>console.log("Parent exit"))
2020
} else {
21-
//child thread gets its own loop
21+
//child Process gets its own loop
2222
setTimeout(()=> console.log("Child Timer"), 0)
23-
console.log("Start Thread's initial phase")
23+
console.log("Start Process's initial phase")
2424
console.log("I'm a worker process: " + process.pid)
2525

2626
for (let i =0; i< 10000000000;i++);
27-
console.log("End Thread's initial phase")
27+
console.log("End Process's initial phase")
2828
process.on("exit", ()=>console.log("Child exit"))
2929

3030
}

22-child-process/221-child-process-ipc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ const child_process = require('child_process');
2727
process.on("message", message => console.log(`Received message from parent '${message}'`))
2828

2929
process.send("hey dad")
30-
console.log("Start Thread's initial phase")
30+
console.log("Start Process's initial phase")
3131
console.log("I'm a worker process: " + process.pid)
3232

3333
for (let i =0; i< 100000000;i++);
34-
console.log("End Thread's initial phase")
34+
console.log("End Process's initial phase")
3535
process.on("exit", ()=>console.log("Child exit"))
3636

3737
setTimeout(()=> {
3838
console.log("Child Timer")
3939
//exit process
4040
//once we exit process is free to leave
41-
process.exit(0);
41+
//process.exit(0);
4242
}, 3000)
4343

4444

22-child-process/225-cluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const PORT = 3000;
1313
//the parent will call accept
1414
//the parent then sends accepted connection to a worker based
1515
//round robin algorithm
16-
cluster.schedulingPolicy= cluster.SCHED_RR ;
16+
cluster.schedulingPolicy= cluster.SCHED_NONE ;
1717

1818

1919
// Check if the current process is the master process

0 commit comments

Comments
 (0)