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 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.

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

Processing log

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:

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

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.

👉 [ Rapid development of desktop applications ]