File tree Expand file tree Collapse file tree 5 files changed +11
-18
lines changed
frameworks/JavaScript/express Expand file tree Collapse file tree 5 files changed +11
-18
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
const cluster = require ( 'cluster' ) ,
7
- physicalCpuCount = require ( 'physical-cpu-count' ) ,
7
+ numCPUs = require ( 'os' ) . cpus ( ) . length ,
8
8
express = require ( 'express' ) ;
9
9
10
10
const bodyParser = require ( 'body-parser' ) ;
@@ -13,7 +13,7 @@ if (cluster.isPrimary) {
13
13
console . log ( `Primary ${ process . pid } is running` ) ;
14
14
15
15
// Fork workers.
16
- for ( let i = 0 ; i < physicalCpuCount ; i ++ ) {
16
+ for ( let i = 0 ; i < numCPUs ; i ++ ) {
17
17
cluster . fork ( ) ;
18
18
}
19
19
@@ -41,7 +41,5 @@ if (cluster.isPrimary) {
41
41
app . get ( '/plaintext' , ( req , res ) =>
42
42
res . header ( 'Content-Type' , 'text/plain' ) . send ( 'Hello, World!' ) ) ;
43
43
44
- app . listen ( 8080 , ( ) => {
45
- console . log ( 'listening on port 8080' ) ;
46
- } ) ;
44
+ app . listen ( 8080 ) ;
47
45
}
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
const cluster = require ( 'cluster' ) ,
7
- physicalCpuCount = require ( 'physical-cpu-count' ) ,
7
+ numCPUs = require ( 'os' ) . cpus ( ) . length ,
8
8
express = require ( 'express' ) ,
9
9
mongoose = require ( 'mongoose' ) ,
10
10
conn = mongoose . connect ( 'mongodb://tfb-database/hello_world' ) ;
@@ -33,7 +33,7 @@ const FortuneSchema = new mongoose.Schema({
33
33
34
34
if ( cluster . isPrimary ) {
35
35
// Fork workers.
36
- for ( let i = 0 ; i < physicalCpuCount ; i ++ ) {
36
+ for ( let i = 0 ; i < numCPUs ; i ++ ) {
37
37
cluster . fork ( ) ;
38
38
}
39
39
@@ -101,7 +101,5 @@ if (cluster.isPrimary) {
101
101
res . send ( results ) ;
102
102
} ) ;
103
103
104
- app . listen ( 8080 , ( ) => {
105
- console . log ( 'listening on port 8080' ) ;
106
- } ) ;
104
+ app . listen ( 8080 ) ;
107
105
}
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
const cluster = require ( 'cluster' ) ,
7
- physicalCpuCount = require ( 'physical-cpu-count' ) ,
7
+ numCPUs = require ( 'os' ) . cpus ( ) . length ,
8
8
express = require ( 'express' ) ,
9
9
Sequelize = require ( 'sequelize' ) ;
10
10
@@ -45,7 +45,7 @@ const Fortune = sequelize.define('Fortune', {
45
45
46
46
if ( cluster . isPrimary ) {
47
47
// Fork workers.
48
- for ( let i = 0 ; i < physicalCpuCount ; i ++ ) {
48
+ for ( let i = 0 ; i < numCPUs ; i ++ ) {
49
49
cluster . fork ( ) ;
50
50
}
51
51
@@ -127,7 +127,5 @@ if (cluster.isPrimary) {
127
127
res . send ( results ) ;
128
128
} ) ;
129
129
130
- app . listen ( 8080 , ( ) => {
131
- console . log ( 'listening on port 8080' ) ;
132
- } ) ;
130
+ app . listen ( 8080 ) ;
133
131
}
Original file line number Diff line number Diff line change 11
11
"mysql2" : " 2.2.5" ,
12
12
"pg" : " 8.5.0" ,
13
13
"pg-promise" : " 10.7.3" ,
14
- "physical-cpu-count" : " ^2.0.0" ,
15
14
"pug" : " 2.0.1" ,
16
15
"sequelize" : " 5.15.1"
17
16
}
Original file line number Diff line number Diff line change 2
2
* Module dependencies.
3
3
*/
4
4
const cluster = require ( 'cluster' ) ,
5
- physicalCpuCount = require ( 'physical-cpu-count' ) ,
5
+ numCPUs = require ( 'os' ) . cpus ( ) . length ,
6
6
express = require ( 'express' ) ,
7
7
helper = require ( './helper' ) ;
8
8
@@ -51,7 +51,7 @@ const randomWorldPromise = () => {
51
51
52
52
if ( cluster . isPrimary ) {
53
53
// Fork workers.
54
- for ( let i = 0 ; i < physicalCpuCount ; i ++ ) {
54
+ for ( let i = 0 ; i < numCPUs ; i ++ ) {
55
55
cluster . fork ( ) ;
56
56
}
57
57
You can’t perform that action at this time.
0 commit comments