0

任何人都知道为什么我的集群没有优化?

文件:

const http = require('http');

require('dotenv').config();

const express = require('express');

const cassandra = require('./src/db/db');

const os = require('os');

const cluster = require('cluster');

const app = express();

const PORT = process.env.PORT;

const siege = require('node-siege');

if(cluster.isMaster) {
  const n_cpus = os.cpus().length;
  console.log(`FORKING ${n_cpus} CPUs`);
  for(let i = 0; i < n_cpus; i++) {
    cluster.fork();
  }
} else {
const pid = process.pid;
const routes = require('./src/routes/index');

const cors = require('cors');

app.use(cors());

app.use(express.json());

app.use(routes);

const server = http.createServer(app);

  server.listen(PORT, () => {
    console.log(`Server listen on port ${PORT} `);
  });  

}

攻城令:

siege -c100 -r1 http://localhost:3001/

Output:

With cluster:
Transactions:                    100 hits
Availability:                 100.00 %
Elapsed time:                   1.10 secs
Data transferred:               0.00 MB
Response time:                  0.03 secs
Transaction rate:              90.91 trans/sec
Throughput:                     0.00 MB/sec
Concurrency:                    2.82
Successful transactions:         100
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:           0.01

WITHOUT CLUSTER:
Transactions:                    100 hits
Availability:                 100.00 %
Elapsed time:                   1.09 secs
Data transferred:               0.00 MB
Response time:                  0.03 secs
Transaction rate:              92.08 trans/sec
Throughput:                     0.00 MB/sec
Concurrency:                    2.47
Successful transactions:         100
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:           0.00

为什么它没有效果?

..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ...................................

4

0 回答 0