Skip to content

Commit

Permalink
Add doc for DisbleGCRuns
Browse files Browse the repository at this point in the history
  • Loading branch information
knylander-grafana committed Nov 1, 2024
1 parent 8bf1c83 commit 0a18496
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions docs/sources/configure-client/language-sdks/go_push.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ go get github.com/grafana/pyroscope-go
If you'd prefer to use Pull mode you can do so using [Grafana Alloy](https://grafana.com/docs/pyroscope/<PYROSCOPE_VERSION>/configure-client/grafana-alloy/).
{{% /admonition %}}

Then add the following code to your application:
Add the following code to your application:

```go
package main
Expand Down Expand Up @@ -110,7 +110,7 @@ To enable mutex profiling, you need to add the following code to your applicatio
runtime.SetMutexProfileFraction(rate)
```

`rate` parameter controls the fraction of mutex contention events that are reported in the mutex profile. On average 1/rate events are reported.
The `rate` parameter controls the fraction of mutex contention events that are reported in the mutex profile. On average, 1/rate events are reported.

### Block profiling

Expand All @@ -127,10 +127,20 @@ To enable block profiling, you need to add the following code to your applicatio
runtime.SetBlockProfileRate(rate)
```

`rate` parameter controls the fraction of goroutine blocking events that are reported in the blocking profile. The profiler aims to sample an average of one blocking event per rate nanoseconds spent blocked.
The `rate` parameter controls the fraction of goroutine blocking events that are reported in the blocking profile.
The profiler aims to sample an average of one blocking event per rate nanoseconds spent blocked.

## Send data to Pyroscope OSS or Grafana Cloud Profiles

To configure the Golang SDK to send data to Pyroscope, replace the `<URL>` placeholder with the appropriate server URL.
This could be the Grafana Cloud URL or your own custom Pyroscope server URL.

If you need to send data to Grafana Cloud, you'll have to configure HTTP Basic authentication.
Replace `<User>` with your Grafana Cloud stack user and `<Password>` with your Grafana Cloud API key.

If your Pyroscope server has multi-tenancy enabled, you'll need to configure a tenant ID.
Replace `<TenantID>` with your Pyroscope tenant ID.

```go
pyroscope.Start(pyroscope.Config{
ApplicationName: "example.golang.app",
Expand All @@ -150,11 +160,24 @@ pyroscope.Start(pyroscope.Config{
})
```

To configure the Golang SDK to send data to Pyroscope, replace the `<URL>` placeholder with the appropriate server URL. This could be the Grafana Cloud URL or your own custom Pyroscope server URL.
### Option for handling increased memory usage

Pyroscope may require additional when tracking a lot of objects. For example, a Go service that indexes large amounts of data requires more memory.
This tracking can lead to higher CPU usage and potential CPU throttling.

You can use `DisableGCRuns` in your Go configuration to disable automatic runtimes.
If this flag is enabled, there is less GC running and therefore less CPU resources spent.
However, the heap profile may be less precies.

If you need to send data to Grafana Cloud, you'll have to configure HTTP Basic authentication. Replace `<User>` with your Grafana Cloud stack user and `<Password>` with your Grafana Cloud API key.
Add `DisableGCRuns: true` to the pyroscope.Start(pyroscope.Config) block.

If your Pyroscope server has multi-tenancy enabled, you'll need to configure a tenant ID. Replace `<TenantID>` with your Pyroscope tenant ID.
```go
pyroscope.Start(pyroscope.Config{
ApplicationName: "example.golang.app",
ServerAddress: "<URL>",
// Disable automatic runtime.GC runs between getting the heap profiles.
DisableGCRuns: true,
```
## Golang profiling examples
Expand Down

0 comments on commit 0a18496

Please sign in to comment.