From 76bb361393730f32fbde36c2db6c5d28742f2abf Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sun, 15 Mar 2020 23:33:12 +0100 Subject: [PATCH] docs: add built-in profiler --- README.md | 1 + docs/profiling.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 docs/profiling.md diff --git a/README.md b/README.md index 21e7a744..afa2d196 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Fully featured and highly configurable SFTP server, written in Go - [Web based administration interface](./docs/web-admin.md) to easily manage users and connections. - Easy [migration](./scripts#convert-users-from-other-stores) from Linux system user accounts. - [Portable mode](./docs/portable-mode.md): a convenient way to share a single directory on demand. +- Performance analysis using built-in [profiler](./docs/profiling.md). - Configuration format is at your choice: JSON, TOML, YAML, HCL, envfile are supported. - Log files are accurate and they are saved in the easily parsable JSON format ([more information](./docs/logs.md)). diff --git a/docs/profiling.md b/docs/profiling.md new file mode 100644 index 00000000..2f477aa7 --- /dev/null +++ b/docs/profiling.md @@ -0,0 +1,23 @@ +# Profiling SFTPGo + +The built-in profiler lets you collect CPU profiles, traces, allocations and heap profiles that allow to identify and correct specific bottlenecks. +You can enable the built-in profiler using the `--profiler` command flag. + +Profiling data are exposed via HTTP/HTTPS in the format expected by the [pprof](https://github.com/google/pprof/blob/master/doc/README.md) visualization tool. You can find the index page at the URL `/debug/pprof/`. + +The following profiles are available, you can obtain them via HTTP GET requests: + +- `allocs`, a sampling of all past memory allocations +- `block`, stack traces that led to blocking on synchronization primitives +- `goroutine`, stack traces of all current goroutines +- `heap`, a sampling of memory allocations of live objects. You can specify the `gc` GET parameter to run GC before taking the heap sample +- `mutex`, stack traces of holders of contended mutexes +- `profile`, CPU profile. You can specify the duration in the `seconds` GET parameter. After you get the profile file, use the `go tool pprof` command to investigate the profile +- `threadcreate`, stack traces that led to the creation of new OS threads +- `trace`, a trace of execution of the current program. You can specify the duration in the `seconds` GET parameter. After you get the trace file, use the `go tool trace` command to investigate the trace + +Let's see some examples: + +- download a 30 seconds CPU profile from the URL `/debug/pprof/profile?seconds=30` +- download a sampling of memory allocations of live objects from the URL `/debug/pprof/heap?gc=1` +- download a sampling of all past memory allocations from the URL `/debug/pprof/allocs` \ No newline at end of file