SlideShare a Scribd company logo
Фатальный недостаток
Node.js
Алексей Охрименко - IPONWEB
Алексей Охрименко
twitter: @Ai_boy
Фатальный недостаток Node.js
Фатальный недостаток Node.js
Фатальный недостаток Node.js
99.9%
Фатальный недостаток Node.js
Фатальный недостаток Node.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello Worldn');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Фатальный недостаток Node.js
Фатальный недостаток Node.js
Фатальный недостаток Node.js
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
async / await
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
async / await promise
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
async / await promise замыкания
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
async / await promise замыкания
stacktraces
https://www.future-processing.pl/blog/on-problems-with-threads-in-node-js/
https://www.dynatrace.com/blog/all-you-need-to-know-to-really-understand-the-node-js-event-loop-and-its-metrics/
Фатальный недостаток Node.js
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
???
После uncaughtException
• Immediate Shutdown

• Graceful Shutdown
Immediate Shutdown (убиться сразу)
Immediate Shutdown (убиться сразу)
Immediate Shutdown (убиться сразу)
500 500 500
Immediate Shutdown (убиться сразу)
500 200 200
10 секунд подождать
Graceful Shutdown (убиться красиво)
Graceful Shutdown (убиться красиво)
Graceful Shutdown (убиться красиво)
5 лет спустя
Graceful Shutdown (убиться красиво)
200 200
Graceful Shutdown (убиться красиво)
200 200
Graceful Shutdown (убиться красиво)
200 200
10 секунд уже потрачено
500
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
???
Сделай сам!
я-ж программист!
Фатальный недостаток Node.js
https://github.com/mattinsler/longjohn
Uncaught Error: foo
at f (index.html:24:23)
----------------------------------------
at setTimeout
at onload (index.html:28:40)
Uncaught Error: foo
at USER_NAME_MASHA (index.html:24:23)
----------------------------------------
at setTimeout
at onload (index.html:28:40)
Uncaught Error: foo
at USER_NAME_MASHA (index.html:24:23)
----------------------------------------
at setTimeout
at onload (index.html:28:40)
rename function 1000 callbacks 10 callbacks
Clusters
Clusters
Clusters
Clusters
Clusters
Domains
Domains
Async-Listeners
Node.js 0.11.x
Async-Wrap / Async-Hooks
Experimental
Для Async-Hooks - все
ресурс (объект)
setTimeout(() => {})
setTimeout(() => {})
init
setTimeout(() => {})
init
before
setTimeout(() => {})
init
before
after
setTimeout(() => {})
init
before
after
destroy
new Promise((res, rej) => {})
init
before
after
destroy
async_hooks.createHook({ init, before, after, destroy })
setTimeout(() => {})
AsyncID: 0
setTimeout(() => {})
AsyncID: 1
setTimeout(() => {})
AsyncID: 2
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 0
AsyncID: 0
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 1
AsyncID: 0
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 1
AsyncID: 1
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 1
AsyncID: 2
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 1
AsyncID: 2 TriggerID: 1
setTimeout(() => {
setTimeout(() => {})
})
AsyncID: 1
AsyncID: 2 TriggerID: 1
TCPWRAP(2): trigger: 1 execution: 1
TickObject(3): trigger: 2 execution: 1
before: 3
Timeout(4): trigger: 3 execution: 3
TIMERWRAP(5): trigger: 3 execution: 3
after: 3
destroy: 3
before: 5
before: 4
TTYWRAP(6): trigger: 4 execution: 4
SIGNALWRAP(7): trigger: 4 execution: 4
TTYWRAP(8): trigger: 4 execution: 4
>>> 4
TickObject(9): trigger: 4 execution: 4
after: 4
after: 5
before: 9
after: 9
destroy: 4
destroy: 9
destroy: 5
API очень низкоуровневое
LISP (time travel debugger)
Zone (stage 0)
https://github.com/domenic/zones
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);
}
setTimeout(someCallback, 0);
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);
}
setTimeout(someCallback, 0);
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);
}
setTimeout(someCallback, 0);
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);TRUE
}
setTimeout(someCallback, 0);
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);
}
setTimeout(someCallback, 0);
Zone
Zone.current.fork({}).run(function () {
Zone.current.inTheZone = true;
setTimeout(someCallback, 0);
});
function someCallback() {
console.log(Zone.current.inTheZone);FALSE
}
setTimeout(someCallback, 0);
А что делать простым
смертным?
Алексей Охрименко
twitter: @Ai_boy
http://bit.ly/2vZKN6k

More Related Content

PDF
Node.JS
PDF
Kruskal algorithm
KEY
How to stop writing spaghetti code - JSConf.eu 2010
DOCX
Novatadas en java
PDF
Modern Mobile Web Apps
PDF
Java script.trend(spec)
PPTX
es6.concurrency()
DOC
Correcion
Node.JS
Kruskal algorithm
How to stop writing spaghetti code - JSConf.eu 2010
Novatadas en java
Modern Mobile Web Apps
Java script.trend(spec)
es6.concurrency()
Correcion

What's hot (20)

PPTX
Rubyslava2102
DOCX
DOCX
JAVA Program in NetBeans
PDF
Sockets java
PDF
Week 7 unit3 (chapter 10-11)
PDF
Java AWT Calculadora
PDF
Gaztea Tech 2015: 4. GT Drawbot Control
PPTX
JavaScript Assíncrono
DOCX
Linklist through struct
DOCX
Caculadora pacho (1)
PDF
aggregation and indexing with suitable example using MongoDB.
PDF
商派信息安全解决方案
PPTX
OpenResty/Lua 70+ Advanced Programming Skills and Optimization tips
DOCX
PDF
Java Thread Cronometro
PPT
PDF
Тененёв Анатолий, Boost.Asio в алгоритмической торговле
PDF
L’enfer des callbacks
PDF
I will be callback/JS同步與非同步
Rubyslava2102
JAVA Program in NetBeans
Sockets java
Week 7 unit3 (chapter 10-11)
Java AWT Calculadora
Gaztea Tech 2015: 4. GT Drawbot Control
JavaScript Assíncrono
Linklist through struct
Caculadora pacho (1)
aggregation and indexing with suitable example using MongoDB.
商派信息安全解决方案
OpenResty/Lua 70+ Advanced Programming Skills and Optimization tips
Java Thread Cronometro
Тененёв Анатолий, Boost.Asio в алгоритмической торговле
L’enfer des callbacks
I will be callback/JS同步與非同步
Ad

Фатальный недостаток Node.js