I
I
Ivan Stroykin2017-08-22 23:15:32
Node.js
Ivan Stroykin, 2017-08-22 23:15:32

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.

app.js
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');

create-server.js
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, () => { ... });

models/Test.js

Здесь будут храниться миллионы записей
const Test = {};
module.exports = Test;


I’ve been writing on NodeJS recently, in general I’m writing on python
Found a rating - link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2017-08-22
@StivinKing

Use Redis (preferably not nodejs)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question