Skip to content

Commit

Permalink
Merge pull request #119 from steadybit/fix/only_use_available_processors
Browse files Browse the repository at this point in the history
fix: use allowed cpus from target container
  • Loading branch information
joshiste authored Feb 5, 2025
2 parents 42116cb + 8e9fe47 commit fa4d8a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions exthost/action_stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/steadybit/action-kit/go/action_kit_api/v2"
"github.com/steadybit/action-kit/go/action_kit_commons/runc"
"github.com/steadybit/action-kit/go/action_kit_commons/stress"
"github.com/steadybit/action-kit/go/action_kit_commons/utils"
"github.com/steadybit/action-kit/go/action_kit_sdk"
"github.com/steadybit/extension-kit"
"github.com/steadybit/extension-kit/extutil"
Expand Down Expand Up @@ -97,6 +98,8 @@ func (a *stressAction) Prepare(ctx context.Context, state *StressActionState, re
return nil, extension_kit.ToError("Failed to prepare stress settings.", err)
}

adaptCpuHosts(&opts)

state.StressOpts = opts
state.Sidecar = stress.SidecarOpts{
TargetProcess: initProcess,
Expand All @@ -110,6 +113,19 @@ func (a *stressAction) Prepare(ctx context.Context, state *StressActionState, re
return nil, nil
}

func adaptCpuHosts(s *stress.Opts) {
if s.CpuWorkers == nil || *s.CpuWorkers != 0 {
return
}

//stress-ng will use all configured processors, we deem this to be wrong and expect all online cpus to be used.
if c, err := utils.ReadCpusAllowedCount("/proc/1/status"); err == nil {
s.CpuWorkers = extutil.Ptr(c)
} else {
log.Debug().Err(err).Msg("failed to read cpus allowed for pid 1")
}
}

func (a *stressAction) Start(ctx context.Context, state *StressActionState) (*action_kit_api.StartResult, error) {
s, err := stress.New(ctx, a.runc, state.Sidecar, state.StressOpts)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.33.0
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.7-0.20250131112718-3009f02a4b24
github.com/steadybit/action-kit/go/action_kit_commons v1.2.17
github.com/steadybit/action-kit/go/action_kit_commons v1.2.18
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.14
github.com/steadybit/action-kit/go/action_kit_test v1.3.2
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.7-0.20250131112718-3009f02a4b24 h1:yPAEDf9TdBo7AreM9oNguDKqj2aJ4XZsRQupP4x3X9Y=
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.7-0.20250131112718-3009f02a4b24/go.mod h1:5Zs3wQtBtda+ASXKYk1sfcDBFe+F2+V2H4EbZzjXhJQ=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.17 h1:NOKvnUA/iZo7mlcgSK+c8EHjxAEYCLSdyk8KVQSXmv8=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.17/go.mod h1:GFLcaf/WluBIqnq+iSCEGkEqxnfB9h1I16IBR1T7kNQ=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.18 h1:zg3c7b/Dl0M/odtNMbbhwVn/EbnvPZO14IPwbFy9WbY=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.18/go.mod h1:GFLcaf/WluBIqnq+iSCEGkEqxnfB9h1I16IBR1T7kNQ=
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.14 h1:x94RX+vh9Iyc0tS6BhiSpvknj+xE36AV0Nc3D5Yuub0=
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.14/go.mod h1:Tp/klK5b7k+BCvb3JTSDZSNcnpFBaHauhndzOarnMW4=
github.com/steadybit/action-kit/go/action_kit_test v1.3.2 h1:DFDznoWEbTGv+fiGYiRaq7tq5es9VTScjrWusRAbS08=
Expand Down

0 comments on commit fa4d8a6

Please sign in to comment.