SlideShare a Scribd company logo
Comparing Node.js
processes and threads
for clustering
HTTP, TCP, and UDP
Vitalii Kukhar
Full Stack Software Engineer at Metarhia
8-9 NOVEMBER ‘19 KIEV, UKRAINEPROFESSIONAL JS CONFERENCE
Javascript is a single threaded language
Asynchronous I/O
● Rack: a Ruby Webserver Interface
● NGINX uses an asynchronous, event-driven approach
● an asynchronous event-driven JavaScript runtime
● JavaScript + asynchronous IO + HTTP server stuff
Performing CPU-intensive operations
● long-running JavaScript functions
● unresponsive page
● limit to perform new asynchronous I / O tasks
● bad user experience
Inter process communication (IPC)
● child_process module
● cluster module
● net module (tcp client-server)
● BroadcastChannel API, Web Storage API, etc.
● no shared memory
The worker_threads module
● enables to use threads
● execute JavaScript in parallel
● useful for performing CPU-intensive operations
● shared memory
Basic Concepts
● process
● thread
● multiprocessing
● multithreading
What the worker_threads module gave us(before)?
● one process
● one thread
● one event loop
● one JS Engine instance
● one NodeJS instance process
thread
V8 libuv
NodeJS
JavaScript
What the worker_threads module gave us(after)?
● one process
● multiple threads
● one event loop per thread
● one JS Engine Instance per thread
● one NodeJS Instance per thread process
thread
V8 libuv
NodeJS
JavaScript
thread
V8 libuv
NodeJS
JavaScript
Tools for working with multithreading
Server Clusters
● high-availability
● load-balancing
● high performance computing
Our cluster
Experimental servers
● http
● tcp
● udp
Research
● CPU usage
● memory usage
● multiple instances of NodeJS
● worker_threads with I/O-intensive work
Project structure
● transport
○ http.js
○ tcp.js
○ udp.js
● master.js
● worker.js
● config.js
● spawner
○ processes.js
○ threads.js
● transport
○ http.js
○ tcp.ja
○ udp.js
● master.js
● worker.js
● config.js
Client Server
Configuration files
{
ports: [0, …, N],
hostname:’xxx.xxx.xxx.xxx’,
transportName: 'http',
concurrentConnection: 20,
}
{
ports: [0, …, N],
hostname: '127.0.0.1',
spawnerName: 'processes',
transportName: http,
disconnect: 2
}
Client Server
HTTP Client
const requesterAsync = async port => {
while (condition) {
await requester(port);
}
};
TCP Client
const requesterAsync = port => {
socket.connect({ port, host }, () => socket.write('Run'));
socket.on('data', data => {
if (condition) {
socket.write('Run')
}
});
};
UDP Client
const requesterAsync = port => {
socket.send('Run!', port, host);
socket.on('message', (msg, info) => {
if (condition) {
socket.send('Run', info.port, info.address);
}
});
};
Server return
{
port,
workerId || processId,
count,
memoryUsage
}
Test #1
● HTTP
● Server
○ 7 processes
○ 7 threads
● Client
○ 70 connections
○ ~3600 rps on port
HTTP: CPU Usage Processes vs Threads
HTTP: CPU Usage with disconnects
Processes vs Threads
HTTP: Memory Usage Processes vs Threads
HTTP: RSS
Test #2
● TCP
● Server
○ 7 processes
○ 7 threads
● Client
○ 140 connections
○ ~24000 rps on port
TCP: CPU Usage Processes vs Threads
TCP: CPU Usage with disconnects
Processes vs Threads
TCP: Memory Usage Processes vs Threads
TCP: RSS Processes vs Threads
Test #3
● UDP
● Server
○ 7 processes
○ 7 threads
● Client
○ 140 connections
○ ~24000 rps on port
UDP: CPU Usage Processes vs Threads
UDP: CPU Usage with stop/restart
Processes vs Threads
UDP: Memory Usage
Processes vs Threads
UDP: RSS Processes vs Threads
Thank you!
Questions?
kukhar.vitalii@gmail.com
8-9 NOVEMBER ‘19 KIEV, UKRAINEPROFESSIONAL JS CONFERENCE

More Related Content

What's hot (20)

PDF
202107 - Orion introduction - COSCUP
Ronald Hsu
 
PDF
RIPE74 - ARouteServer - IXP Automation Made Easy
Pier Carlo Chiodi
 
PDF
ITB2019 CacheBox + LogBox 101 - Brad Wood
Ortus Solutions, Corp
 
PDF
nebulaconf
Pedro Dias
 
PPTX
Html5
Ahmed Jadalla
 
PDF
Meteor and Bitcoin (Lightning Talk)
Ryan Casey
 
PDF
WebRTC ... GWT & in-browser computation
JooinK
 
PDF
ScalaCache: simple caching in Scala
Chris Birchall
 
PDF
Phone Home: A client-side error collection system
Chris Birchall
 
PDF
Como o Javascript Funciona - TDC Floripa
Vinicius Kiatkoski Neves
 
PDF
Libbitcoin slides
swansontec
 
ODP
Node js - layout
Diego Sánchez
 
PPTX
NodeJS
Alok Guha
 
PDF
PHP client - Mongo db User Group Pune
Nishant Shrivastava
 
PDF
Learn backend java script
Tsuyoshi Maeda
 
PPTX
MongoDB backup service overview Boston MUG
MongoDB
 
PDF
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
NETWAYS
 
PPTX
Javascript basics
Falcon2018
 
PDF
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
NETWAYS
 
PDF
Ballerina Serverless with Kubeless
WSO2
 
202107 - Orion introduction - COSCUP
Ronald Hsu
 
RIPE74 - ARouteServer - IXP Automation Made Easy
Pier Carlo Chiodi
 
ITB2019 CacheBox + LogBox 101 - Brad Wood
Ortus Solutions, Corp
 
nebulaconf
Pedro Dias
 
Meteor and Bitcoin (Lightning Talk)
Ryan Casey
 
WebRTC ... GWT & in-browser computation
JooinK
 
ScalaCache: simple caching in Scala
Chris Birchall
 
Phone Home: A client-side error collection system
Chris Birchall
 
Como o Javascript Funciona - TDC Floripa
Vinicius Kiatkoski Neves
 
Libbitcoin slides
swansontec
 
Node js - layout
Diego Sánchez
 
NodeJS
Alok Guha
 
PHP client - Mongo db User Group Pune
Nishant Shrivastava
 
Learn backend java script
Tsuyoshi Maeda
 
MongoDB backup service overview Boston MUG
MongoDB
 
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
NETWAYS
 
Javascript basics
Falcon2018
 
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
NETWAYS
 
Ballerina Serverless with Kubeless
WSO2
 

Similar to JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP на процессах и потоках в NodeJS (20)

PPT
Server side JavaScript: going all the way
Oleg Podsechin
 
PDF
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Fwdays
 
PDF
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
PDF
Node, can you even in CPU intensive operations?
The Software House
 
PDF
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
PPT
JS everywhere 2011
Oleg Podsechin
 
PPTX
Node.js: A Guided Tour
cacois
 
PDF
Nodejs - A quick tour (v5)
Felix Geisendörfer
 
PDF
Introduction to Node.js
Richard Lee
 
PPTX
introduction to node.js
orkaplan
 
PDF
Frontend Track NodeJS
Marcelo Serpa
 
PDF
Nodeconf AR 18 Decomposition of the Main thread in Node.js to increase throug...
Nikolay Matvienko
 
KEY
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
 
PDF
Node.js scaling in highload
Timur Shemsedinov
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PPT
JavaScript Event Loop
Thomas Hunter II
 
PDF
NodeJS ecosystem
Yukti Kaura
 
PDF
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
PPT
New kid on the block node.js
Joel Divekar
 
PDF
About Node.js
Artemisa Yescas Engler
 
Server side JavaScript: going all the way
Oleg Podsechin
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Fwdays
 
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
Node, can you even in CPU intensive operations?
The Software House
 
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
JS everywhere 2011
Oleg Podsechin
 
Node.js: A Guided Tour
cacois
 
Nodejs - A quick tour (v5)
Felix Geisendörfer
 
Introduction to Node.js
Richard Lee
 
introduction to node.js
orkaplan
 
Frontend Track NodeJS
Marcelo Serpa
 
Nodeconf AR 18 Decomposition of the Main thread in Node.js to increase throug...
Nikolay Matvienko
 
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
 
Node.js scaling in highload
Timur Shemsedinov
 
node.js: Javascript's in your backend
David Padbury
 
JavaScript Event Loop
Thomas Hunter II
 
NodeJS ecosystem
Yukti Kaura
 
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
New kid on the block node.js
Joel Divekar
 
About Node.js
Artemisa Yescas Engler
 
Ad

More from JSFestUA (20)

PDF
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
JSFestUA
 
PDF
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
JSFestUA
 
PDF
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
PDF
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JSFestUA
 
PDF
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
JSFestUA
 
PDF
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Александр Товмач. JAMstack
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
JSFestUA
 
PDF
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
JSFestUA
 
PDF
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
PDF
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
JSFestUA
 
PDF
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
JSFestUA
 
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
JSFestUA
 
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
JSFestUA
 
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JSFestUA
 
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
JSFestUA
 
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
JSFestUA
 
JS Fest 2019/Autumn. Александр Товмач. JAMstack
JSFestUA
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
JSFestUA
 
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
JSFestUA
 
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
JSFestUA
 
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
JSFestUA
 
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
JSFestUA
 
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
JSFestUA
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JSFestUA
 
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
JSFestUA
 
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
JSFestUA
 
JS Fest 2019. Виктор Турский. 6 способов взломать твое JavaScript приложение
JSFestUA
 
Ad

Recently uploaded (20)

PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 

JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP на процессах и потоках в NodeJS