Find the performance killer
The performance optimization of online services is almost superstitious. A group of programmers faced a large amount of incomprehensible code, and guessed whether the other party was using all the cpu. Spend a lot of time recording logs, flipping through the massive logs day and night, trying to find the performance killer.
However, with fibjs, all this will become simpler. Because fibjs has powerful cpu and memory profiler support, and it is very convenient to use.
fibjs start cpu profiler is extremely simple, increase startup
--profoption. The default logging interval is 1000ms, with in-depth optimization, you'll need a more accurate analysis of the log, then you can use the
--prof-intervalset interval. The following example records fibjs work log every 10ms.
1fibjs --prof --prof-interval=10 main.js
After the end of normal operation, or use ctrl_c end of the process, the current directory will generate a log file, the file name is
fibjs-xxxx.log, at this time, you can use the
--prof-processlog processing generated:
1fibjs --prof-process fibjs-xxxx.log prof.svg
After running, use the browser to open prof.svg, you can view the flame map of this log: you can click to view the full-size image, in the full-size image, you can use the mouse to view more detailed information: prof. svg .
Interpretation of the flame map
In the generated flame graph, each color block represents a recording point. The longer the color block, the more times it has been recorded; each line represents a layer of call stack, and the more layers, the more layers are called; The stack is placed upside down, the lower the color block, the more the original function.