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
bug riskProne to bugsobservabilityIssues related to observability (metrics, dashboards, alerts, opentelemetry)s2Broken use cases or features (with a workaround). Only humans may set this.
We've noticed over the past several months the coder pods gradually run out of memory over time. Typically around 30 day mark but can't really say for sure. Here is our memory allocation for a 5 replica set in k8s.
What metric is being used here to calculate memory usage?
Do you have the GOGC or GOMEMLIMIT environment variables set?
There appear to be some marked jumps in memory usage in some of these processes; does this correlate to any events on your side?
Do your pods OOM once they reach 100%? If so, do you experience any downtime?
It would be helpful if you could share the Prometheus metrics of one of these processes with high memory usage as well as a pprof heap profile; that'll help us understand the problem more concretely.
Also, can you look inside the pod and determine which processes are using memory? Coder server runs provisioners by default which start additional processes as part of provisioning. It would be useful to understand whether it is the main server process that is using increasing memory.
we have not seen any pattern as the memory increases appear to be incremental
yes, all pods will evict when they reach their memory thresholds. However, it doesn't always happen. Sometimes they stay in kind of unusable state. not sure why.
We'll enable the prometheus ENV var during our next upgrade.
to get the pprof heap profile do I need to just shell into the coder pod and run from cmdline?
As you can see from the above graph, the top 2 did not have any spikes but are trending upwards around 80% now. The other 3 all have memory spikes exceeding 100%.
Unfortunately, we don't expose the individual pod IP addresses, so we can't navigate through the browser. Can we download heap and goroutine using kubectl exec instead?
I tried using the --output parameter but it seemed to save the file inside the pod
If your pod has curl you should be able to kubectl exec -n <namespace> <pod> -- curl http://localhost:6060/debug/pprof/heap > heap.out and similarly for goroutine (http://localhost:6060/debug/pprof/goroutine?debug=2)
I'm posting here the 6 memory spikes we had last week that went above 8GIG limit at
10:40 Thursday Oct 31
11:10 Thursday Oct 31
12:10 Friday Nov 1
12:40 Friday Nov 1
17:20 Friday Nov 1
18:00 Friday Nov 1
@spikecurtis sorry I had to restart the pods last night. Can I do this anytime? there doesn't seem to be any one event that causes this. Rather memory just increases over time without releasing it back.
It appears to be a slow build up of memory over time, so we need the profiles from when the pod is using a lot of memory. It won't be helpful to see the profiles right after a restart.
In that case we'll have to wait until this builds up again. However, if you look at the graph, there are clear instances where the memory gets bumped up and doesn't go back down. Should we be looking at these events? They happen all throughout the span of the graph and I could probably provide metrics for those events.
Here is the 3 day graph for one of them (coder-64f8cdcf6b-rr8kz)
The last 2 spikes both happened at 3:40AM EST. No correlations found in datadog or anywhere else.
The profiles each show about 60MB of in use heap memory, and approximately 1000 goroutines, neither of which strikes me as particularly high. Each Coder was talking to about 25 workspaces. Does that sound right to you---like with 5 replicas that's 125ish active workspaces?
If that 60MB heap size is accurate, I'm sort of at a loss to explain where 90% (of 8GiB) is going. Can you gather some metrics for one of the pods you sent the profiles for, including the time period where those profiles were generated, and let me know the approximate time of the profile capture?
Curtis, I collected the pprof metrics around the time I sent them to you right before I restarted those 2 pods. that was around 8:36AM. 25 workspaces sounds possible although at this time in the morning we only have about 70 workspaces running in total. and another 100 stopped. I took a look at the other metrics and did not see any correlations. What time period on Feb 7 would you like to see?
I'm also attaching the memory usage for the same pod during that same window of time. I would re-iterate again, that we need to focus on the events where the memory goes up and does not get released to go back down. It seems fairly obvious from the graph that this is what is causing the issue.
the other 3 pods are all in the 80s today and will probably need to restart soon. Here is the 7 day graph of one of them to serve as an example of the memory step-up events I'm referring to.
bug riskProne to bugsobservabilityIssues related to observability (metrics, dashboards, alerts, opentelemetry)s2Broken use cases or features (with a workaround). Only humans may set this.
Activity
dannykopping commentedon Oct 2, 2024
HI @mambon2,
Can you please clarify a few things for me?
GOGCorGOMEMLIMITenvironment variables set?It would be helpful if you could share the Prometheus metrics of one of these processes with high memory usage as well as a pprof
heapprofile; that'll help us understand the problem more concretely.spikecurtis commentedon Oct 3, 2024
Also, can you look inside the pod and determine which processes are using memory? Coder server runs provisioners by default which start additional processes as part of provisioning. It would be useful to understand whether it is the main server process that is using increasing memory.
mambon2 commentedon Oct 8, 2024
@dannykopping
dannykopping commentedon Oct 8, 2024
Thanks for the detail @mambon2
Regarding pprof, you'll need to enable
CODER_PPROF_ENABLEand then you can navigate to the address specified inCODER_PPROF_ADDRESS(e.g. http://localhost:6060/debug/pprof/) to download the heap & goroutine profiles.mambon2 commentedon Oct 21, 2024
Was not able to set the PPROF env but I do have some metrics for the past 7 days to show what the memory looks like for each of the 5 pods.
mambon2 commentedon Oct 21, 2024
As you can see from the above graph, the top 2 did not have any spikes but are trending upwards around 80% now. The other 3 all have memory spikes exceeding 100%.
mambon2 commentedon Oct 21, 2024
@dannykopping do I use localhost or external DNS for this?
mambon2 commentedon Oct 21, 2024
Unfortunately, we don't expose the individual pod IP addresses, so we can't navigate through the browser. Can we download heap and goroutine using kubectl exec instead?
I tried using the --output parameter but it seemed to save the file inside the pod
spikecurtis commentedon Oct 22, 2024
If your pod has
curlyou should be able tokubectl exec -n <namespace> <pod> -- curl http://localhost:6060/debug/pprof/heap > heap.outand similarly for goroutine (http://localhost:6060/debug/pprof/goroutine?debug=2)mambon2 commentedon Oct 22, 2024
I have enabled pprof now and pods have restarted and memory has gone back down. When do you want to me to collect these? anytime?
spikecurtis commentedon Oct 22, 2024
It would be most helpful to collect them once memory is anomalously high again.
mambon2 commentedon Nov 6, 2024
I'm posting here the 6 memory spikes we had last week that went above 8GIG limit at
10:40 Thursday Oct 31
11:10 Thursday Oct 31
12:10 Friday Nov 1
12:40 Friday Nov 1
17:20 Friday Nov 1
18:00 Friday Nov 1
72 remaining items
mambon2 commentedon Jan 17, 2025
@spikecurtis sorry I had to restart the pods last night. Can I do this anytime? there doesn't seem to be any one event that causes this. Rather memory just increases over time without releasing it back.
spikecurtis commentedon Jan 21, 2025
It appears to be a slow build up of memory over time, so we need the profiles from when the pod is using a lot of memory. It won't be helpful to see the profiles right after a restart.
mambon2 commentedon Jan 21, 2025
In that case we'll have to wait until this builds up again. However, if you look at the graph, there are clear instances where the memory gets bumped up and doesn't go back down. Should we be looking at these events? They happen all throughout the span of the graph and I could probably provide metrics for those events.
mambon2 commentedon Jan 21, 2025
Here is a clear example of this from the past week

mambon2 commentedon Feb 7, 2025
Good morning. We noticed today 2 pods hit over 90% memory and I've collected the pprof metrics before restarting them. Please take a look.
coder-64f8cdcf6b-rr8kz-goroutine.txt
coder-64f8cdcf6b-rr8kz-heap.txt
coder-64f8cdcf6b-vz84v-goroutine.txt
coder-64f8cdcf6b-vz84v-heap.txt
mambon2 commentedon Feb 7, 2025
Here is the 3 day graph for one of them (coder-64f8cdcf6b-rr8kz)
The last 2 spikes both happened at 3:40AM EST. No correlations found in datadog or anywhere else.
spikecurtis commentedon Feb 10, 2025
I'm looking at this now.
The profiles each show about 60MB of in use heap memory, and approximately 1000 goroutines, neither of which strikes me as particularly high. Each Coder was talking to about 25 workspaces. Does that sound right to you---like with 5 replicas that's 125ish active workspaces?
If that 60MB heap size is accurate, I'm sort of at a loss to explain where 90% (of 8GiB) is going. Can you gather some metrics for one of the pods you sent the profiles for, including the time period where those profiles were generated, and let me know the approximate time of the profile capture?
process_resident_memory_bytes
process_virtual_memory_bytes
go_memstats_heap_alloc_bytes
go_memstats_heap_idle_bytes
go_memstats_heap_inuse_bytes
go_memstats_heap_sys_bytes
go_memstats_stack_inuse_bytes
go_memstats_stack_sys_bytes
go_memstats_sys_bytes
mambon2 commentedon Feb 10, 2025
Curtis, I collected the pprof metrics around the time I sent them to you right before I restarted those 2 pods. that was around 8:36AM. 25 workspaces sounds possible although at this time in the morning we only have about 70 workspaces running in total. and another 100 stopped. I took a look at the other metrics and did not see any correlations. What time period on Feb 7 would you like to see?
mambon2 commentedon Feb 10, 2025
I'm attaching all morning 00-09AM of Feb7 metrics for pod coder-64f8cdcf6b-rr8kz
go_memstats_sys_bytes-data-2025-02-10 09_09_47.csv
process_virtual_memory_bytes-data-2025-02-10 09_08_42.csv
process_resident_memory_bytes-data-2025-02-10 09_08_20.csv
go_memstats_heap_sys_bytes-data-2025-02-10 09_07_50.csv
go_memstats_heap_inuse_bytes-data-2025-02-10 09_05_37.csv
go_memstats_heap_idle_bytes-data-2025-02-10 09_04_41.csv
go_memstats_heap_alloc_bytes-data-2025-02-10 09_03_46.csv
go_memstats_alloc_bytes-data-2025-02-10 09_02_13.csv
go_memstats_stack_inuse_bytes-data-2025-02-10 09_01_37.csv
go_memstats_stack_sys_bytes-data-2025-02-10 09_01_03.csv
go_goroutines-data-2025-02-10 08_59_55.csv
mambon2 commentedon Feb 10, 2025
I'm also attaching the memory usage for the same pod during that same window of time. I would re-iterate again, that we need to focus on the events where the memory goes up and does not get released to go back down. It seems fairly obvious from the graph that this is what is causing the issue.
extract-2025-02-10T14_26_53.501Z-Memory Usage by Pod.csv
mambon2 commentedon Feb 10, 2025
the other 3 pods are all in the 80s today and will probably need to restart soon. Here is the 7 day graph of one of them to serve as an example of the memory step-up events I'm referring to.
mambon2 commentedon Feb 10, 2025
Same graph from one of the new pods started last week. as you can see it jumped from 9% to 26% today without releasing the memory.
zenithwolf1000 commentedon Nov 16, 2026
Closing due to inactivity.