Giter VIP home page Giter VIP logo

gogctuner's Introduction

gogctuner: GC Tuner for Go Applications

gogctuner is a Go library designed to automatically adjust the garbage collection (GC) parameters to optimize CPU usage based on the target memory usage percentage.

How it works

  • Pre Go1.19 Versions: Utilizes a tuning strategy inspired by Uber's article, which adjusts the GOGC parameter based on the live heap size and target memory limit.
  • Go1.19 and Later: Takes advantage of the soft memory limit feature introduced in Go 1.19, offering more granular control over GC behavior.

Features

  • Memory Usage Based Tuning: Automatically adjusts GC parameters to maintain a specified percentage of memory usage.
  • Cross-Version Compatibility: Compatible with Go versions below 1.19 and leverages the SetMemoryLimit features in Go 1.19 and above.
  • cgroups Support: Works seamlessly with both cgroups and cgroupsv2 for enhanced resource management.
  • Cross-OS Compatibility: Ensures functionality across multiple operating systems.

Usage

Static Configuration

Use static configuration by setting the MaxRAMPercentage at the initialization of your application:

package main

import (
  "github.com/fangwentong/gogctuner"
)

func main() {
  gogctuner.EnableGCTuner(
    gogctuner.WithStaticConfig(gogctuner.Config{MaxRAMPercentage: 90}),
  )
  // Your application code here
}

Dynamic Configuration

For dynamic configuration that allows runtime updates, you can use a configurator:

package main

import (
  "github.com/fangwentong/gogctuner"
)

func main() {
  configurator := gogctuner.NewGcConfigurator()

  // Integrate with your dynamic config implementation here:
  conf := readFromYourConfigCenter("your_config_key")
  configurator.SetConfig(conf) // set initial config
  // register config updates callback
  registerConfigUpdateCallback("your_config_key", func(conf gogctuner.Config) {
    configurator.SetConfig(conf)
  })

  gogctuner.EnableGCTuner(
    gogctuner.WithConfigurator(configurator),
  )
  // Your application code here
}

Reference

License

This project is licensed under the MIT License, see the LICENSE file for details.

gogctuner's People

Contributors

fangwentong avatar

Stargazers

 avatar 华华 avatar

Watchers

 avatar

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.