gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

README.md (1482B)


      1 # automemlimit
      2 
      3 [![Go Reference](https://pkg.go.dev/badge/github.com/KimMachineGun/automemlimit.svg)](https://pkg.go.dev/github.com/KimMachineGun/automemlimit)
      4 [![Go Report Card](https://goreportcard.com/badge/github.com/KimMachineGun/automemlimit)](https://goreportcard.com/report/github.com/KimMachineGun/automemlimit)
      5 [![Test](https://github.com/KimMachineGun/automemlimit/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/KimMachineGun/automemlimit/actions/workflows/test.yml)
      6 
      7 Automatically set `GOMEMLIMIT` to match Linux [cgroups(7)](https://man7.org/linux/man-pages/man7/cgroups.7.html) memory limit.
      8 
      9 See more details about `GOMEMLIMIT` [here](https://tip.golang.org/doc/gc-guide#Memory_limit).
     10 
     11 ## Installation
     12 
     13 ```shell
     14 go get github.com/KimMachineGun/automemlimit@latest
     15 ```
     16 
     17 ## Usage
     18 
     19 ```go
     20 package main
     21 
     22 // By default, it sets `GOMEMLIMIT` to 90% of cgroup's memory limit.
     23 // You can find more details of its behavior from the doc comment of memlimit.SetGoMemLimitWithEnv.
     24 import _ "github.com/KimMachineGun/automemlimit"
     25 ```
     26 
     27 or
     28 
     29 ```go
     30 package main
     31 
     32 import "github.com/KimMachineGun/automemlimit/memlimit"
     33 
     34 func init() {
     35 	memlimit.SetGoMemLimitWithEnv()
     36 	memlimit.SetGoMemLimit(0.9)
     37 	memlimit.SetGoMemLimitWithProvider(memlimit.Limit(1024*1024), 0.9)
     38 	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroup, 0.9)
     39 	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV1, 0.9)
     40 	memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV2, 0.9)
     41 }
     42 ```