A
A
axeax2013-09-05 14:53:48
Node.js
axeax, 2013-09-05 14:53:48

Sharing memory between processes in Nodejs?

Habr! I need your help!
I will explain the essence of the problem with an example:
In Nodejs, I launch several workers through cluster.
There is an array A.
And for example, A[1] is stored in the first worker, and A[2] in the second. Is there any way to share an array between all workers without using redis etc.? That is, ideally, when executing console.log(A[2]) in the first worker, I got a real value and not undefined.
Please do not offer transport between workers, you need the fastest solution. (although everything is physically located on the same machine with 8 cores that all need to be used).
I thought about creating some kind of sandbox for processes, in which everything will be visible ... Or maybe there are ready-made solutions?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timur Shemsedinov, 2013-09-05
@MarcusAurelius

There is no such possibility and cannot be! This is a well-known task, high-speed transports like 0MQ were invented for it, look in this direction zeromq.org/bindings :node-js

V
Vyacheslav Slinko, 2013-09-06
@KeepYourMind

Processes are isolated.
If you need shared data with 8 cores but no transport (like 0MQ), then you need any other multi-threaded programming language.

V
Vyacheslav Saratovsky, 2014-05-27
@super-developer

Maybe this is not quite right, but I used the ws
module in the first process

var WebSocketServer = require('ws').Server
    , wss = new WebSocketServer({
        port: 9090
    });

wss.on('connection', function(ws){
    console.info("Установлено соединение с модулем");
    ws.send("Шлем данные второму процессу");
    startExpress(ws);
});

In the second
var WebSocket = require('ws');

// Конектимся
var onDutyWs = new WebSocket('ws://127.0.0.1:9090');
onDutyWs.on('open', function(ws) {
    ws.send("Шлем данные первому процессу");
    console.log("Подключились!");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question