use automaxproc and automemlimit

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-10-06 13:50:59 +03:00
parent f1b8ecbdb3
commit 71fe0df73f
3 changed files with 75 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"sync"
"github.com/KimMachineGun/automemlimit/memlimit"
_ "go.uber.org/automaxprocs"
"go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/config"
@@ -17,6 +19,18 @@ import (
"go.unistack.org/micro/v3/tracer"
)
func init() {
memlimit.SetGoMemLimitWithOpts(
memlimit.WithRatio(0.9),
memlimit.WithProvider(
memlimit.ApplyFallback(
memlimit.FromCgroup,
memlimit.FromSystem,
),
),
)
}
// Service is an interface that wraps the lower level components.
// Its works as container with building blocks for service.
type Service interface {