Notice: file_put_contents(): Write of 5208 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 17496 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Node.JS [ru] | Серверный JavaScript@we_use_js P.4194
WE_USE_JS Telegram 4194
⚙️ Что такое Cluster в Node.js?

Cluster — это модуль Node.js, позволяющий создавать несколько процессов (воркеров) для выполнения кода параллельно. Это полезно для улучшения производительности на многопроцессорных системах, так как Node.js работает в однопоточном режиме.

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
// Создание воркеров на основе числа ядер процессора
console.log(`Master ${process.pid} is running`);

for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', (worker, code, signal) => {
console.log(`Worker ${worker.process.pid} died`);
});
} else {
// Каждый воркер будет запускать сервер
http.createServer((req, res) => {
res.writeHead(200);
res.end(`Hello from worker ${process.pid}\n`);
}).listen(8000);

console.log(`Worker ${process.pid} started`);
}


➡️ Cluster позволяет создавать несколько экземпляров сервера на каждом ядре процессора, увеличивая масштабируемость и производительность приложений на Node.js.


🖥 Подробнее тут
Please open Telegram to view this post
VIEW IN TELEGRAM
👍7🤝2



tgoop.com/we_use_js/4194
Create:
Last Update:

⚙️ Что такое Cluster в Node.js?

Cluster — это модуль Node.js, позволяющий создавать несколько процессов (воркеров) для выполнения кода параллельно. Это полезно для улучшения производительности на многопроцессорных системах, так как Node.js работает в однопоточном режиме.

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
// Создание воркеров на основе числа ядер процессора
console.log(`Master ${process.pid} is running`);

for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', (worker, code, signal) => {
console.log(`Worker ${worker.process.pid} died`);
});
} else {
// Каждый воркер будет запускать сервер
http.createServer((req, res) => {
res.writeHead(200);
res.end(`Hello from worker ${process.pid}\n`);
}).listen(8000);

console.log(`Worker ${process.pid} started`);
}


➡️ Cluster позволяет создавать несколько экземпляров сервера на каждом ядре процессора, увеличивая масштабируемость и производительность приложений на Node.js.


🖥 Подробнее тут

BY Node.JS [ru] | Серверный JavaScript


Share with your friend now:
tgoop.com/we_use_js/4194

View MORE
Open in Telegram


Telegram News

Date: |

Telegram is a leading cloud-based instant messages platform. It became popular in recent years for its privacy, speed, voice and video quality, and other unmatched features over its main competitor Whatsapp. The administrator of a telegram group, "Suck Channel," was sentenced to six years and six months in prison for seven counts of incitement yesterday. Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. With the “Bear Market Screaming Therapy Group,” we’ve now transcended language. Each account can create up to 10 public channels
from us


Telegram Node.JS [ru] | Серверный JavaScript
FROM American