Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Comparing Node.js
processes and threads
for clustering
HTTP, TCP, and UDP
Vitalii Kukhar
Full Stack Software Engineer at M...
Javascript is a single threaded language
Asynchronous I/O
● Rack: a Ruby Webserver Interface
● NGINX uses an asynchronous, event-driven approach
● an asynchronous ...
Performing CPU-intensive operations
● long-running JavaScript functions
● unresponsive page
● limit to perform new asynchr...
Inter process communication (IPC)
● child_process module
● cluster module
● net module (tcp client-server)
● BroadcastChan...
The worker_threads module
● enables to use threads
● execute JavaScript in parallel
● useful for performing CPU-intensive ...
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...
What the worker_threads module gave us(after)?
● one process
● multiple threads
● one event loop per thread
● one JS Engin...
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
○ t...
Configuration files
{
ports: [0, …, N],
hostname:’xxx.xxx.xxx.xxx’,
transportName: 'http',
concurrentConnection: 20,
}
{
p...
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', d...
UDP Client
const requesterAsync = port => {
socket.send('Run!', port, host);
socket.on('message', (msg, info) => {
if (con...
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
Upcoming SlideShare
Loading in …5
×

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

45 views

Published on

В этом докладе, я хочу сравнить кластеризацию HTTP, TCP, UDP на процессах и потоках в NodeJS. Оценить производительность и использование ресурсов при разных подходах.

Published in: Education
  • Be the first to comment

  • Be the first to like this

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

  1. 1. 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
  2. 2. Javascript is a single threaded language
  3. 3. 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
  4. 4. Performing CPU-intensive operations ● long-running JavaScript functions ● unresponsive page ● limit to perform new asynchronous I / O tasks ● bad user experience
  5. 5. Inter process communication (IPC) ● child_process module ● cluster module ● net module (tcp client-server) ● BroadcastChannel API, Web Storage API, etc. ● no shared memory
  6. 6. The worker_threads module ● enables to use threads ● execute JavaScript in parallel ● useful for performing CPU-intensive operations ● shared memory
  7. 7. Basic Concepts ● process ● thread ● multiprocessing ● multithreading
  8. 8. 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
  9. 9. 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
  10. 10. Tools for working with multithreading
  11. 11. Server Clusters ● high-availability ● load-balancing ● high performance computing
  12. 12. Our cluster
  13. 13. Experimental servers ● http ● tcp ● udp
  14. 14. Research ● CPU usage ● memory usage ● multiple instances of NodeJS ● worker_threads with I/O-intensive work
  15. 15. 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
  16. 16. 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
  17. 17. HTTP Client const requesterAsync = async port => { while (condition) { await requester(port); } };
  18. 18. TCP Client const requesterAsync = port => { socket.connect({ port, host }, () => socket.write('Run')); socket.on('data', data => { if (condition) { socket.write('Run') } }); };
  19. 19. UDP Client const requesterAsync = port => { socket.send('Run!', port, host); socket.on('message', (msg, info) => { if (condition) { socket.send('Run', info.port, info.address); } }); };
  20. 20. Server return { port, workerId || processId, count, memoryUsage }
  21. 21. Test #1 ● HTTP ● Server ○ 7 processes ○ 7 threads ● Client ○ 70 connections ○ ~3600 rps on port
  22. 22. HTTP: CPU Usage Processes vs Threads
  23. 23. HTTP: CPU Usage with disconnects Processes vs Threads
  24. 24. HTTP: Memory Usage Processes vs Threads
  25. 25. HTTP: RSS
  26. 26. Test #2 ● TCP ● Server ○ 7 processes ○ 7 threads ● Client ○ 140 connections ○ ~24000 rps on port
  27. 27. TCP: CPU Usage Processes vs Threads
  28. 28. TCP: CPU Usage with disconnects Processes vs Threads
  29. 29. TCP: Memory Usage Processes vs Threads
  30. 30. TCP: RSS Processes vs Threads
  31. 31. Test #3 ● UDP ● Server ○ 7 processes ○ 7 threads ● Client ○ 140 connections ○ ~24000 rps on port
  32. 32. UDP: CPU Usage Processes vs Threads
  33. 33. UDP: CPU Usage with stop/restart Processes vs Threads
  34. 34. UDP: Memory Usage Processes vs Threads
  35. 35. UDP: RSS Processes vs Threads
  36. 36. Thank you! Questions? kukhar.vitalii@gmail.com 8-9 NOVEMBER ‘19 KIEV, UKRAINEPROFESSIONAL JS CONFERENCE

×