Skip to content

Profiling

Jens Alfke edited this page Oct 21, 2013 · 5 revisions

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.

Generating a Profile

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

Interpreting a Profile

  1. 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.)
  2. From a shell run go tool pprof /path/to/sync_gateway gateway.prof, where the 4th parameter is the path to the sync_gateway binary and the fifth is the path to the generated profile dump.
  3. 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.
Clone this wiki locally