GithubHelp home page GithubHelp logo

chobostar / go-oom-guard Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 2.0 397 KB

It will set "threshold notify" mechanism for memory cgroup to receive notifications from the kernel. This reduces the chance of Postgres killing by OOM.

License: Apache License 2.0

Dockerfile 2.31% Makefile 5.88% Go 91.81%
cgroups oom postgresql

go-oom-guard's Introduction

go-oom-guard

It creates eventfd and register a notifier by given threshold in CGroup. Then it sends SIGINT or SIGTERM to top memory used process.

Problem

Postgres is unable to control memory usage by backends.

CGroup OOM Killer triggered by some query causes whole database restart.

How to mitigate it?

Possible solutions

  1. Just monitor memory usage, make it less impact, recommendations by CrunchyData
  2. LD_PRELOAD custom library, solution by TimescaleDB Cloud
  3. Register cgroup memory event before OOM triggers. A lot of solutions, for example Tencent Cloud

This repo is example of #3

Prerequisites

  • Docker
  • python3, psycopg2
  • psql
  • Go

Demo

terminal #1:

$ make build
$ make docker
$ make docker-run

terminal #2:

$ docker exec -i postgres_oom_guarded ./go-oom-guard

terminal #3:

make test-oom-execute
make test-oom-parse

and the try it without running go-oom-guard, stop terminal #2, and run commands in terminal #3 again.

Cautions

It's only POC, don't use it on production AS IS!

TODOs

  • how to get exactly postgres backend's pid ?

Links

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.