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 side used 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 is extremely simple to start the cpu profiler, just add the
--prof option when starting. The default log interval is 1000ms. With the deepening of optimization, you will need to analyze logs with higher accuracy. At this time, you can use
--prof-interval set the interval. In the following example, the fibjs work log is recorded every 10ms.
1fibjs --prof --prof-interval=10 main.js
After the operation ends normally, or the process is terminated with ctrl_c, a log file will be generated in the current directory, the file name is
fibjs-xxxx.log , at this time, you can use
--prof-process process the generated log:
1fibjs --prof-process fibjs-xxxx.log prof.svg
At the end of the operation, open prof.svg with a browser to view the flame diagram of this log: You can click to view the full-size picture. In the full-size picture, you can use the mouse to check more detailed information: prof.svg .
Flame diagram interpretation
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 row represents a layer of call stack, and the more layers, the more layers are called; The placement of the stack is inverted, the lower the color block, the more the original function.