{"id":20499519,"url":"https://github.com/chobostar/go-oom-guard","last_synced_at":"2025-04-13T18:51:44.841Z","repository":{"id":165448293,"uuid":"538364321","full_name":"chobostar/go-oom-guard","owner":"chobostar","description":"It will set \"threshold notify\" mechanism for memory cgroup to receive notifications from the kernel. This reduces the chance of Postgres killing by OOM.","archived":false,"fork":false,"pushed_at":"2022-09-20T06:28:36.000Z","size":397,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T09:40:54.598Z","etag":null,"topics":["cgroups","oom","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chobostar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-19T06:32:19.000Z","updated_at":"2024-01-17T02:37:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e876430-06d8-4f35-ba63-915603897c11","html_url":"https://github.com/chobostar/go-oom-guard","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chobostar%2Fgo-oom-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chobostar%2Fgo-oom-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chobostar%2Fgo-oom-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chobostar%2Fgo-oom-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chobostar","download_url":"https://codeload.github.com/chobostar/go-oom-guard/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248765984,"owners_count":21158296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgroups","oom","postgresql"],"created_at":"2024-11-15T18:17:35.081Z","updated_at":"2025-04-13T18:51:44.805Z","avatar_url":"https://github.com/chobostar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-oom-guard\n\nIt creates [eventfd](https://man7.org/linux/man-pages/man2/eventfd.2.html) and register a notifier by given [threshold](https://lwn.net/Articles/529927/) in CGroup.\nThen it sends SIGINT or SIGTERM to top memory used process.\n\n![](demo/OOM_Guard.drawio.png)\n\n## Problem\nPostgres is unable to control memory usage by backends.\n\nCGroup OOM Killer triggered by some query causes whole database restart.\n\nHow to mitigate it?\n\n## Possible solutions\n\n1. Just monitor memory usage, make it less impact, [recommendations by CrunchyData](https://www.crunchydata.com/blog/deep-postgresql-thoughts-the-linux-assassin)\n2. LD_PRELOAD custom library, [solution by TimescaleDB Cloud](https://www.postgresql.eu/events/pgconfde2022/sessions/session/3692/slides/309/pgconf_de_2022_kliukin_talk.pdf)\n3. Register cgroup memory event before OOM triggers. A lot of solutions, [for example Tencent Cloud](https://www.tencentcloud.com/document/product/457/38709)\n\nThis repo is example of #3\n\n## Prerequisites\n\n- Docker\n- python3, psycopg2\n- psql\n- Go\n\n## Demo\nterminal #1:\n```\n$ make build\n$ make docker\n$ make docker-run\n```\nterminal #2:\n```\n$ docker exec -i postgres_oom_guarded ./go-oom-guard\n```\nterminal #3:\n```\nmake test-oom-execute\nmake test-oom-parse\n```\n\nand the try it without running `go-oom-guard`, stop terminal #2, and run commands in terminal #3 again.\n\n## Cautions\nIt's only POC, don't use it on production AS IS!\n\n## TODOs\n- how to get exactly postgres [backend's](https://www.interdb.jp/pg/pgsql02.html#:~:text=A%20backend%20process%2C%20which%20is,when%20the%20client%20gets%20disconnected.) pid ?\n\n## Links\n\n- https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt - see `9. Memory thresholds`\n- https://man7.org/linux/man-pages/man2/eventfd.2.html","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchobostar%2Fgo-oom-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchobostar%2Fgo-oom-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchobostar%2Fgo-oom-guard/lists"}