简体   繁体   English

如何在 HTTP 请求后使用 pprof 查看 web 服务器对 memory 的使用情况

[英]How to use pprof to see memory usage by web server after HTTP requests

The documentation for net/http/pprof explains how to create a 30-second CPU profiling session and analyze the outcome. net/http/pprof 的文档解释了如何创建 30 秒 CPU 分析 session 并分析结果。

This allows me to initiate one or more HTTP requests and see the resulting CPU utilization of my web application.这允许我发起一个或多个 HTTP 请求并查看我的 web 应用程序的 CPU 利用率。

I see a route for generating a heap profile, but since the profiling doesn't occur over something like a 30-second window, I'm unsure conceptually how this interacts with my web application.我看到了生成堆配置文件的路线,但由于分析不会发生在像 30 秒 window 之类的东西上,我在概念上不确定这如何与我的 web 应用程序交互。

How can I "coordinate" the heap profiler so that it corresponds with one or more HTTP requests?如何“协调”堆分析器,使其与一个或多个 HTTP 请求相对应?

I don't think you can scope the profiler exactly to a request, but a common methodology is to take multiple, intentionally timed, heap profiles.我不认为你可以 scope 探查器完全满足一个请求,但一种常见的方法是采用多个有意定时的堆配置文件。 For example:例如:

  • Take a single profile of your application at an empty state to set a baseline在空的 state 处获取应用程序的单个配置文件以设置基线
  • Take a profile (or multiple profiles) while the application is loaded with a request (or multiple requests)在应用程序加载一个请求(或多个请求)时获取一个配置文件(或多个配置文件)
  • Take a profile afterwards之后进行个人资料

The powerful part of heap profiles is that pprof allows you to "diff" a profile by specifying 2 profiles!堆配置文件的强大部分是 pprof 允许您通过指定 2 个配置文件来“区分”一个配置文件! a base profile and a secondary profile to compare the base to!一个基础配置文件和一个辅助配置文件来比较基础!

Using this it becomes easy to see the difference in allocated objects or total bytes.使用它可以很容易地看到分配对象或总字节数的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM