Skip to content

Commit 023994c

Browse files
committed
Fixing clusterization options and added to the config file
1 parent ea415c9 commit 023994c

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

db/chat.db

0 Bytes
Binary file not shown.

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ const database = await createDB(config);
3131
* if the clusters are enabled, the primary process will fork the workers
3232
* otherwise, the server will run in a single process
3333
*/
34-
if (cluster.isPrimary && config.clusters) {
34+
if (cluster.isPrimary) {
3535
const numCPUs = availableParallelism();
3636
database.init();
37-
for (let i = 0; i < numCPUs; i++) {
37+
let cpus = config.clusters ? numCPUs: 1;
38+
for (let i = 0; i < cpus; i++) {
3839
cluster.fork({
3940
PORT: config.basePort + i
4041
});
4142
}
4243
setupPrimary();
4344
} else {
44-
4545
const app = express();
4646
const server = createServer(app);
4747
const io = new Server(server, {

src/config/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default
44
properties: {
55
basePort: { type: "number", format: "int32", default: 3000, minimum: 1800, maximum: 65535, multipleOf: 1, description: "The base port number"},
66
dbFileName: { type: "string", format:"uri-reference", description: "The name of the database file"},
7+
clusters: { type: "boolean", default: true, description: "If true, there will be as many worker processes as CPUs"},
78
freshStart: { type: "boolean", default: false, description: "If true, the database will be reinitialized"}
89
},
910
required: ["basePort", "dbFileName"]

0 commit comments

Comments
 (0)