Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.4"]
php: ["8.5"]
go: [stable]
os: ["ubuntu-latest"]
steps:
Expand Down
99 changes: 0 additions & 99 deletions CLAUDE.md

This file was deleted.

48 changes: 24 additions & 24 deletions fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ import (

// NewFSM returns new FSM implementation based on initial state
func NewFSM(initialState int64, log *zap.Logger) *Fsm {
return &Fsm{
log: log,
currentState: &initialState,
}
f := &Fsm{log: log}
f.currentState.Store(initialState)
return f
}

// Fsm is general https://en.wikipedia.org/wiki/Finite-state_machine to transition between worker states
type Fsm struct {
log *zap.Logger
numExecs uint64
numExecs atomic.Uint64
// to be lightweight, use UnixNano
lastUsed uint64
currentState *int64
lastUsed atomic.Uint64
currentState atomic.Int64
}

// CurrentState (see interface)
func (s *Fsm) CurrentState() int64 {
return atomic.LoadInt64(s.currentState)
return s.currentState.Load()
}

func (s *Fsm) Compare(state int64) bool {
return atomic.LoadInt64(s.currentState) == state
return s.currentState.Load() == state
}

/*
Expand All @@ -43,12 +42,12 @@ func (s *Fsm) Transition(to int64) {
return
}

atomic.StoreInt64(s.currentState, to)
s.currentState.Store(to)
}

// String returns current StateImpl as string.
func (s *Fsm) String() string {
switch atomic.LoadInt64(s.currentState) {
switch s.currentState.Load() {
case StateInactive:
return "inactive"
case StateReady:
Expand All @@ -73,34 +72,34 @@ func (s *Fsm) String() string {
return "ttlReached"
case StateMaxMemoryReached:
return "maxMemoryReached"
default:
return "undefined"
}

return "undefined"
}

// NumExecs returns number of registered WorkerProcess execs.
func (s *Fsm) NumExecs() uint64 {
return atomic.LoadUint64(&s.numExecs)
return s.numExecs.Load()
}

// IsActive returns true if WorkerProcess not Inactive or Stopped
func (s *Fsm) IsActive() bool {
return atomic.LoadInt64(s.currentState) == StateWorking ||
atomic.LoadInt64(s.currentState) == StateReady
return s.currentState.Load() == StateWorking ||
s.currentState.Load() == StateReady
}

// RegisterExec register new execution atomically
func (s *Fsm) RegisterExec() {
atomic.AddUint64(&s.numExecs, 1)
s.numExecs.Add(1)
}

// SetLastUsed Update last used time
func (s *Fsm) SetLastUsed(lu uint64) {
atomic.StoreUint64(&s.lastUsed, lu)
s.lastUsed.Store(lu)
}

func (s *Fsm) LastUsed() uint64 {
return atomic.LoadUint64(&s.lastUsed)
return s.lastUsed.Load()
}

// Acceptors (also called detectors or recognizers) produce binary output,
Expand All @@ -113,23 +112,24 @@ func (s *Fsm) recognizer(to int64) error {
case StateInactive:
// from
// No-one can transition to Inactive
if atomic.LoadInt64(s.currentState) == StateDestroyed {
if s.currentState.Load() == StateDestroyed {
return errors.E(op, errors.Errorf("can't transition from state: %s", s.String()))
}
// to from StateWorking/StateInactive only
case StateReady:
// from
switch atomic.LoadInt64(s.currentState) {
switch s.currentState.Load() {
case StateWorking, StateInactive:
return nil
default:
return errors.E(op, errors.Errorf("can't transition from state: %s", s.String()))
}

return errors.E(op, errors.Errorf("can't transition from state: %s", s.String()))
// to
case StateWorking:
// from
// StateWorking can be transitioned only from StateReady
if atomic.LoadInt64(s.currentState) == StateReady {
if s.currentState.Load() == StateReady {
return nil
}

Expand All @@ -146,7 +146,7 @@ func (s *Fsm) recognizer(to int64) error {
StateMaxMemoryReached,
StateExecTTLReached:
// from
if atomic.LoadInt64(s.currentState) == StateDestroyed {
if s.currentState.Load() == StateDestroyed {
return errors.E(op, errors.Errorf("can't transition from state: %s", s.String()))
}
// to
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/roadrunner-server/pool

go 1.25
go 1.26

require (
github.com/roadrunner-server/errors v1.4.1
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8Ol49K4=
github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4=
github.com/tklauser/go-sysconf v0.3.16 h1:frioLaCQSsF5Cy1jgRBrzr6t502KIIwQ0MArYICU0nA=
github.com/tklauser/go-sysconf v0.3.16/go.mod h1:/qNL9xxDhc7tx3HSRsLWNnuzbVfh3e7gh/BmM179nYI=
github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso=
github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ=
github.com/tklauser/numcpus v0.11.0 h1:nSTwhKH5e1dMNsCdVBukSZrURJRoHbSEQjdEbY+9RXw=
github.com/tklauser/numcpus v0.11.0/go.mod h1:z+LwcLq54uWZTX0u/bGobaV34u6V7KNlTZejzM6/3MQ=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
Expand All @@ -42,16 +38,12 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading
Loading