Guide Development Guide

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.

fibjs --prof --prof-interval=10 main.js

Processing log

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:

fibjs --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:prof 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.

There are two types of color blocks, one is red and the other is blue. In the profiler of fibjs, red represents JavaScript operations, and blue represents io operations or Native operations. Depending on the problem you need to solve, the area you need to focus on will be different. For example, if you need to solve the problem of high CPU occupancy, you need to pay attention to the red color block at this time; and if your application, the cpu occupancy is not high, but the response is slow, you need to pay attention to the blue color block. The larger the color block near the top, the more important it needs to be concerned and optimized.