File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
examples/2016.11.30-cluster Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ for(( i= 1 ;i<= 4 ;i++ )) ; do
4
+ curl http://127.0.0.1:3000
5
+ echo " "
6
+ done
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ if(cluster.isMaster){
8
8
}
9
9
} else {
10
10
http . createServer ( function ( req , res ) {
11
- res . end ( 'ok' ) ;
11
+ res . end ( `response from worker ${ process . pid } ` ) ;
12
12
} ) . listen ( 3000 ) ;
13
+
14
+ console . log ( `Worker ${ process . pid } started` ) ;
13
15
}
Original file line number Diff line number Diff line change @@ -33,11 +33,34 @@ if(cluster.isMaster){
33
33
}
34
34
}else {
35
35
http .createServer (function (req , res ){
36
- res .end (' ok ' );
36
+ res .end (` response from worker ${ process . pid } ` );
37
37
}).listen (3000 );
38
+
39
+ console .log (` Worker ${ process .pid } started` );
38
40
}
39
41
```
40
42
43
+ 客户端发送请求:` ./req.sh `
44
+
45
+ ``` bash
46
+ #! /bin/bash
47
+
48
+ # req.sh
49
+ for(( i= 1 ;i<= 4 ;i++ )) ; do
50
+ curl http://127.0.0.1:3000
51
+ echo " "
52
+ done
53
+ ```
54
+
55
+ 输出如下:
56
+
57
+ ``` bash
58
+ response from worker 23735
59
+ response from worker 23731
60
+ response from worker 23729
61
+ response from worker 23730
62
+ ```
63
+
41
64
## 实现原理
42
65
43
66
主要搞清楚三个问题:
You can’t perform that action at this time.
0 commit comments