or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
NodeJS CPU heavy tick and memory leak debugging
https://hackmd.io/p/js-paris-nodejs
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Max Wu
CTO of HackMD
I love great product and build them.
I'm developing my dream with code.
Node.js
Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Node.js
ref.
It's super easy to write a Node.js application.
But it's hard to hunt the Ghost in the shell.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Once upon a time…
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →The CPU usage goes too high
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →It stops responsing to the requests
and recover after few minutes
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →It might be restarted by scheduler due to the unresponsiveness
(health check failed)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →We need to find out who's the killer
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Node.js profiling
built-in tool to profile the app
node --prof app.js
Use ApacheBench to make some load
ab -k -c 20 -n 250 "http://localhost:3000"
20 concurrent connections with 250 requests per each
Get the output of ApacheBench
Profiling tool will generate a log file
named like:
isolate-0xnnnnnnnnnnnn-v8.log
wait for a while to collect more data
Analyze the log file
process the log file the get the statistics by this command
node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt
View the result
The file is broken up into sections which are again broken up by language
Here you are!
We found the
marked
library that used for parsing markdown cause the problem.FlameGraph
might be another helpful option
ref.
Yet another story
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Once upon a time…
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →The Memory usage goes too high
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →It fills the instance memory every few hours
and been killed by the OS scheduler
Symptom
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →This problem is the well-known "Memory leaks"
We need to find out who's the killer
again
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →What tools we have
Enable the inspector
use the built-in inspector to understand your app
node --inspect app.js
Use ApacheBench to make some load
ab -k -c 20 -n 250 "http://localhost:3000"
20 concurrent connections with 250 requests per each
There is no graphic server on the production
Let's make the server generates the memory dump
memwatch-next
triggers events when the memory usage still growing after 5 consecutive GCs
View the heapdiff
It's better if we can have the whole heap to inspect
heapdump
dumping the memory stack of node.js app to a file to inspect later
Trigger dumping by USR2 signal
Load dump to Chrome Dev Tools
Look into the dev tools
Here you are!
We found the
gray-matter
library that used for generating the page title cause the problem.ref.
Everything now goes back to normal
Last but not least
the best debbuger of Node.js!
ndb
ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools
Install
npm install -g ndb
Opening ndb
ndb app.js
Placing Breakpoints
ref.
TL;DR
profiling
inspecting
memory dumping
ndb
Thanks for listening!
do you have any questions?
References
References