-
Notifications
You must be signed in to change notification settings - Fork 138
Profiling
The Sync Gateway has some built-in support for generating Go CPU profiles. These can help identify what's slowing down a particular operation, but interpreting them requires knowledge of Go and of the gateway's architecture.
To start CPU profiling, send an HTTP POST
to /_profile
. The body of the request should be a JSON document with a property "file"
whose value is the path where you want the profile output to go. (The typical filename extension is .prof
but you don't have to use that.)
To end profiling, send another HTTP POST
to /_profile
, but with no "file"
property. The profiler will dump its output to the file you initially specified.
NOTE: You probably don't want to turn profiling on for more than a few seconds, or the amount of generated data will get huge and hard to interpret.
- Make sure Go is installed, ideally the same version of Go that was used to compile the Sync Gateway (generally this will be the latest release, e.g. 1.1.2 as of this writing.)
- From a shell run
go tool pprof /path/to/sync_gateway gateway.prof
, where the 4th parameter is the path to thesync_gateway
binary and the fifth is the path to the generated profile dump. - The Go profile tool will start up its own CLI. From here the most useful commands are:
-
top10
will show the top ten functions that the most time was spent in -
web
will generate a flowchart/graph of the control flow, render it to a SVG file, and open it in your web browser. -
help
will show more info about commands, but it's pretty terse.
Send an HTTP POST
to /_heap
. As with _profile
, the body of the request should be a JSON document with a property "file"
whose value is the path where you want the profile output to go.
Open the file the same way: go tool pprof /path/to/sync_gateway heap.prof
Curl Example
curl -X POST -H "Content-Type: application/json" -d '{"file":"heap.profile"}' http://localhost:4985/_heap