Go App Profiling uses the pprof for sampling
pprof is bundled within the auto-instrument agent and corresponds to In-Process Profiling.
It is delivered to the agent in the form of a task, allowing it to be enabled or disabled dynamically. When service encounters performance issues (CPU usage, memory allocation, etc.), pprof task can be created. When the agent receives a task, it enables pprof for sampling. After sampling is completed, the sampling results are analyzed by requesting the server to render a flame graph for performance analysis to determine the specific business code lines that cause performance problems. Note, tracing profiling in the Go agent relies on the Go runtime’s global CPU sampling used by pprof. Since only one CPU profiler can run at a time within the same instance, tracing and pprof CPU profiling cannot be enabled simultaneously. If both are activated on the same instance, one task may fail to start.
OAP and the agent use a brand-new protocol to exchange pprof data, so it is necessary to start OAP with the following configuration:
receiver-pprof: selector: ${SW_RECEIVER_PPROF:default} default: # Used to manage the maximum size of the pprof file that can be received, the unit is Byte, default is 30M pprofMaxSize: ${SW_RECEIVER_PPROF_MAX_SIZE:31457280} # Used to determine whether to receive pprof in memory file or physical file mode # # The memory file mode have fewer local file system limitations, so they are by default. But it costs more memory. # # The physical file mode will use less memory when parsing and is more friendly to parsing large files. # However, if the storage of the tmp directory in the container is insufficient, the oap server instance may crash. # It is recommended to use physical file mode when volume mounting is used or the tmp directory has sufficient storage. memoryParserEnabled: ${SW_RECEIVER_PPROF_MEMORY_PARSER_ENABLED:true}
To use the pprof feature, please follow these steps:
Create an pprof task to notify some go-agent instances in the execution service to start pprof for data collection.
When creating a task, the following configuration fields are required:
When the Agent receives a pprof task from OAP, it automatically generates a log to notify that the task has been acknowledged. The log contains the following field information:
At this point, pprof will trace the events you selected when you created the task:
Finally, the agent will upload the pprof file produced by pprof to the oap server for online performance analysis.
Wait for pprof to complete data collection and upload successfully. We can query the execution logs of the pprof task and the task status, which includes the following information:
Once some agents completed the task, we can analyze the data through the following query:
After the query, the following data would be returned to render a flame graph: