M
M
Mikhail2017-06-17 21:13:06
PHP
Mikhail, 2017-06-17 21:13:06

How to do clustering correctly?

Hello. Wrote a telegram bot on node.js. I ran into a problem at the stage of creating clustering manually. The code is the following:

const cluster = require("cluster");
const os = require("os");
const count = os.cpus().length;
cluster.setupMaster({exec: 'main.js'});
for (let i = 0; i < count; i++) {
    cluster.fork();
}
cluster.on('exit', (worker) => {
    console.log(`worker ${worker.process.pid} died`);
});
console.log('Кластерзация работает');

At startup NODE_DEBUG=cluster node main.js, clustering does not work, as I understand it, because the console is empty. When launched NODE_DEBUG=cluster node boost.js, the desired message is displayed in the console, but at the same time, 4 identical ones from the bot come in response to each user message, but only one should. That is, for one incoming request, the same handler is triggered, but 4 times.
What am I doing wrong?
Z. Y. I understand that I could use PM2 and its built-in clustering, but I would like to figure it out myself

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xtress, 2018-11-06
@xtress

editor='".$my['id']."'

What editor? Where is editor from? The database and user table don't know anything about this "column".
What the, umm, interesting things are going on in the second and 3rd queries? Your final query looks like Why is this all? Of course, I understand that this is from ignorance, but ... In general, I have not worked with mysql_query for a long time, so I'll just get by with the direction: 1) We delete lines from 5 to the end; 2) While or whatever, we get all id from the first request; 3) Read the manual at https://dev.mysql.com/doc/refman/8.0/en/comparison... ; 4) make a request using IN and all news id; 5) We pull out all the data with one request without, as you put it, crutches; ps
well, or use JOIN as you were advised above.

D
Dmitry Larin, 2018-11-06
@fanrok

Maybe this option

select id from art where user_id in (select id from users where moderator_id = 2)

R
RidgeA, 2017-06-17
@RidgeA

see the example in the doc https://nodejs.org/api/cluster.html#cluster_cluster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question