Answer the question
In order to leave comments, you need to log in
How to "download" NodeJS?
Good day,
With a friend we are thinking how to "rock" nodejs. There is data (several million). If there are 2 tasks: take one record by id and take n records according to some condition.
For the test, we store the data in memory. Arranged as an object, where key = record id. Thus it is easy to pull on id. But looking for records by condition is a horror :) in general, it processes about 21 requests per second. This is a kapets, judging by the performance indicators of 99%, what needs to be written differently, but how is it better?
A bit of code. I can't show you everything, unfortunately.
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => process.exit(1));
} else require('./create-server');
const http = require('http');
const parser = require('url');
// ...
module.exports = http.createServer((req, res) => {
res.setHeader('Content-Type', 'application/json');
let url = parser.parse(req.url, true);
// routes ...
}).listen(10000, () => { ... });
const Test = {};
module.exports = Test;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question