You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sources/configure-client/language-sdks/go_push.md
+42-6Lines changed: 42 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ go get github.com/grafana/pyroscope-go
39
39
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/).
40
40
{{% /admonition %}}
41
41
42
-
Then add the following code to your application:
42
+
Add the following code to your application:
43
43
44
44
```go
45
45
package main
@@ -110,7 +110,7 @@ To enable mutex profiling, you need to add the following code to your applicatio
110
110
runtime.SetMutexProfileFraction(rate)
111
111
```
112
112
113
-
`rate` parameter controls the fraction of mutex contention events that are reported in the mutex profile. On average 1/rate events are reported.
113
+
The `rate` parameter controls the fraction of mutex contention events that are reported in the mutex profile. On average, 1/rate events are reported.
114
114
115
115
### Block profiling
116
116
@@ -127,10 +127,20 @@ To enable block profiling, you need to add the following code to your applicatio
127
127
runtime.SetBlockProfileRate(rate)
128
128
```
129
129
130
-
`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.
130
+
The `rate` parameter controls the fraction of goroutine blocking events that are reported in the blocking profile.
131
+
The profiler aims to sample an average of one blocking event per rate nanoseconds spent blocked.
131
132
132
133
## Send data to Pyroscope OSS or Grafana Cloud Profiles
133
134
135
+
To configure the Golang SDK to send data to Pyroscope, replace the `<URL>` placeholder with the appropriate server URL.
136
+
This could be the Grafana Cloud URL or your own custom Pyroscope server URL.
137
+
138
+
If you need to send data to Grafana Cloud, you'll have to configure HTTP Basic authentication.
139
+
Replace `<User>` with your Grafana Cloud stack user and `<Password>` with your Grafana Cloud API key.
140
+
141
+
If your Pyroscope server has multi-tenancy enabled, you'll need to configure a tenant ID.
142
+
Replace `<TenantID>` with your Pyroscope tenant ID.
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.
163
+
### Option: Use `DisableGCRuns` for handling increased memory usage
164
+
165
+
Pyroscope may require additional resources when tracking a lot of objects. For example, a Go service that indexes large amounts of data requires more memory.
166
+
This tracking can lead to higher CPU usage and potential CPU throttling.
167
+
168
+
You can use `DisableGCRuns` in your Go configuration to disable automatic runtimes.
169
+
If this flag is activated, there is less GC running and therefore less CPU resources spent.
170
+
However, the heap profile may be less precise.
171
+
172
+
#### Background
173
+
174
+
In Go's pprof heap profiling, forcing garbage collection (GC) ensures accurate memory usage snapshots by removing uncollected objects.
175
+
Without this step, the heap profile may include memory that has been allocated but is no longer in use--objects that stay in memory simply because they haven't been collected yet.
176
+
This can mask or mimic memory leaks and introduce bias into the profiles, complicating their analysis.
177
+
Therefore, Pyroscope defaults to forcing GC every time a heap profile is collected.
154
178
155
-
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.
179
+
However, in some cases, forcing GC can increase CPU usage, especially if there are many live objects in the heap.
180
+
This issue is reflected by the appearance of the `runtime.GC` function in the CPU profile.
181
+
If the problem has manifested, and some inaccuracy in the heap profile is acceptable, then it is advisable to disable this option to avoid performance degradation.
156
182
157
-
If your Pyroscope server has multi-tenancy enabled, you'll need to configure a tenant ID. Replace `<TenantID>` with your Pyroscope tenant ID.
183
+
#### Activate `DisableGCRuns`
184
+
185
+
Add `DisableGCRuns: true` to the `pyroscope.Start(pyroscope.Config)` block.
186
+
187
+
```go
188
+
pyroscope.Start(pyroscope.Config{
189
+
ApplicationName: "example.golang.app",
190
+
ServerAddress: "<URL>",
191
+
// Disable automatic runtime.GC runs between getting the heap profiles.
0 commit comments