Giter VIP home page Giter VIP logo

golang-garbage-collection's Introduction

GO Garbage Collection 1.19 Demo

This is a simple go/Gin project that explores the practical use of GOMEMLIMIT and visualizes the changes to heap memory in realtime.

Table of Contents
  1. Setup
  2. Usage
  3. Technical Essay
  4. References

Setup

Prerequisites

General

  • Go >= v1.19
  • Docker

Windows

  • WSL / cygwin / git bash (to run shell scripts)

Configuring

The estimated memory required to run the http server is around 5-10 MiB, hence the ideal initial memory limit should be set to be more than 20 MiB to prevent GC from constantly running, leaving no space for new heap allocation.

Default configuration

GOMEMLIMIT=30MiB   # soft memory limit for the runtime in human readable bytes
GOGC=100           # initial garbage collection target percentage, 100 => 100% => 2x
GODEBUG=gctrace=1  # enables debug mode with garbage collection tracing

(back to top)

Usage

Run the docker container.

# builds image and run container
$ ./scripts/run.sh

Run tests.

$ ./scripts/test.sh

API Endpoints

By default the gin app will listen on port 8080 on localhost. The base_url mentioned from here should be http://localhost:8080 unless explicitly modified. Refer to API Docs for more detailed documentation.

(back to top)

Glossary

Heap: Subset of memory that’s managed by GC.

  • Memory requested by the application that the GO Compiler couldn’t find a place for in compile time.
  • Non-heap memory includes memory for GO Routine stacks, GC metadata, and other various GO Runtime data structures.

Live: Memory reachable by program.

  • Memory that the GC discovers is actively used by the program.
  • GC is basically a bunch of code that needs to be executed to make this discovery.

New: New Memory that may or may not be live.

  • Memory that the application has asked runtime to allocate for it since the last time the GC ran. Hence, the liveness of it has not yet been determined.

Total Heap Memory: Total heap memory = Live heap + New heap memory

Total GC CPU Cost: derived from GC Cost Model Total GC CPU cost = (GC CPU cost per cycle) * (GC frequency) * Time Period, T

(back to top)

Technical Essay

(back to top)

References

(back to top)

golang-garbage-collection's People

Contributors

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