chore: add go.uber.org/automaxprocs
ci/woodpecker/push/govulncheck Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details

This commit is contained in:
Dawid Wysokiński 2024-03-29 06:58:31 +01:00
parent b2b8a5b802
commit 41ffbd4d67
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
9 changed files with 32 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"slices"
"github.com/urfave/cli/v2"
"go.uber.org/automaxprocs/maxprocs"
)
type appMode string
@ -29,8 +30,16 @@ var (
Usage: fmt.Sprintf("%s or %s", appModeProduction, appModeDevelopment),
EnvVars: []string{"APP_MODE"},
}
appFlagAutoMaxProcs = &cli.BoolFlag{
Name: "autoMaxProcs",
Usage: "whether to set GOMAXPROCS automatically to match Linux container CPU quota" +
" (https://github.com/uber-go/automaxprocs)",
Value: false,
EnvVars: []string{"AUTO_MAX_PROCS"},
}
appFlags = []cli.Flag{
appFlagMode,
appFlagAutoMaxProcs,
}
)
@ -56,6 +65,12 @@ func (a *appWrapper) handleBefore(c *cli.Context) error {
c.Context = loggerToCtx(c.Context, a.logger)
if c.Bool(appFlagAutoMaxProcs.Name) {
_, _ = maxprocs.Set(maxprocs.Logger(func(s string, v ...any) {
a.logger.Info(fmt.Sprintf(s, v...))
}))
}
a.logger.Debug("executing command", slog.Any("args", c.Args().Slice()))
return nil

1
go.mod
View File

@ -27,6 +27,7 @@ require (
github.com/uptrace/bun/driver/sqliteshim v1.1.17
github.com/uptrace/bun/extra/bundebug v1.1.17
github.com/urfave/cli/v2 v2.27.1
go.uber.org/automaxprocs v1.5.3
golang.org/x/sync v0.6.0
gopkg.in/yaml.v3 v3.0.1
)

4
go.sum
View File

@ -155,6 +155,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/realclientip/realclientip-go v1.0.0 h1:+yPxeC0mEaJzq1BfCt2h4BxlyrvIIBzR6suDc3BEF1U=
@ -220,6 +222,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -37,6 +37,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
resources:
requests:
cpu: 100m

View File

@ -34,6 +34,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
livenessProbe:
exec:
command: [cat, /tmp/live]

View File

@ -34,6 +34,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
livenessProbe:
exec:
command: [cat, /tmp/live]

View File

@ -34,6 +34,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
livenessProbe:
exec:
command: [cat, /tmp/live]

View File

@ -34,6 +34,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
livenessProbe:
exec:
command: [cat, /tmp/live]

View File

@ -34,6 +34,8 @@ spec:
secretKeyRef:
name: twhelp-secret
key: rabbitmq-connection-string
- name: AUTO_MAX_PROCS
value: "true"
livenessProbe:
exec:
command: [cat, /tmp/live]