Skip to content

Coder pods running out of memory #14881

Closed as not planned
Closed as not planned

Description

@mambon2

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.

    resources:
      limits:
        cpu: 4000m
        memory: 8Gi
      requests:
        cpu: 4000m
        memory: 8Gi

and here is a datadog screenshot of the memory usage around 30 day mark

Screenshot 2024-09-23 at 7 15 33 PM

Coder V2.13.4
We don't keep the k8s logs so not able to share those.

Activity

  1. added
    observability
    on Sep 30, 2024
  2. dannykopping commented on Oct 2, 2024

    @dannykopping
    Collaborator

    HI @mambon2,

    Can you please clarify a few things for me?

    1. What metric is being used here to calculate memory usage?
    2. Do you have the GOGC or GOMEMLIMIT environment variables set?
    3. There appear to be some marked jumps in memory usage in some of these processes; does this correlate to any events on your side?
    4. 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.

  3. spikecurtis commented on Oct 3, 2024

    @spikecurtis
    Collaborator

    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.

  4. mambon2 commented on Oct 8, 2024

    @mambon2
    Author

    @dannykopping

    1. metric is kubernetes.memory.usage_pct
    2. no we don't have either one
    3. we have not seen any pattern as the memory increases appear to be incremental
    4. 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.
    5. We'll enable the prometheus ENV var during our next upgrade.
    6. to get the pprof heap profile do I need to just shell into the coder pod and run from cmdline?
  5. dannykopping commented on Oct 8, 2024

    @dannykopping
    Collaborator

    Thanks for the detail @mambon2

    Regarding pprof, you'll need to enable CODER_PPROF_ENABLE and then you can navigate to the address specified in CODER_PPROF_ADDRESS (e.g. http://localhost:6060/debug/pprof/) to download the heap & goroutine profiles.

  6. mambon2 commented on Oct 21, 2024

    @mambon2
    Author

    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.

    Image
    Image
    Image
    Image
    Image

  7. mambon2 commented on Oct 21, 2024

    @mambon2
    Author

    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%.

  8. mambon2 commented on Oct 21, 2024

    @mambon2
    Author

    Thanks for the detail @mambon2

    Regarding pprof, you'll need to enable CODER_PPROF_ENABLE and then you can navigate to the address specified in CODER_PPROF_ADDRESS (e.g. http://localhost:6060/debug/pprof/) to download the heap & goroutine profiles.

    @dannykopping do I use localhost or external DNS for this?

  9. mambon2 commented on Oct 21, 2024

    @mambon2
    Author

    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

  10. spikecurtis commented on Oct 22, 2024

    @spikecurtis
    Collaborator

    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)

  11. mambon2 commented on Oct 22, 2024

    @mambon2
    Author

    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?

  12. spikecurtis commented on Oct 22, 2024

    @spikecurtis
    Collaborator

    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?

    It would be most helpful to collect them once memory is anomalously high again.

  13. mambon2 commented on Nov 6, 2024

    @mambon2
    Author

    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

    Image

  14. 72 remaining items

  15. mambon2 commented on Jan 17, 2025

    @mambon2
    Author

    @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.

  16. spikecurtis commented on Jan 21, 2025

    @spikecurtis
    Collaborator

    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.

  17. mambon2 commented on Jan 21, 2025

    @mambon2
    Author

    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.

  18. mambon2 commented on Jan 21, 2025

    @mambon2
    Author

    Here is a clear example of this from the past week
    Image

  19. mambon2 commented on Feb 7, 2025

    @mambon2
    Author

    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

  20. mambon2 commented on Feb 7, 2025

    @mambon2
    Author

    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.

    Image
  21. spikecurtis commented on Feb 10, 2025

    @spikecurtis
    Collaborator

    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

  22. mambon2 commented on Feb 10, 2025

    @mambon2
    Author

    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?

  23. mambon2 commented on Feb 10, 2025

    @mambon2
    Author

    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

    Image
  24. mambon2 commented on Feb 10, 2025

    @mambon2
    Author

    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.

    Image
  25. mambon2 commented on Feb 10, 2025

    @mambon2
    Author

    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.

    Image
  26. zenithwolf1000 commented on Nov 16, 2026

    @zenithwolf1000
    Collaborator

    Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug riskobservabilitys2

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions