summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.rr.yaml6
-rw-r--r--CHANGELOG.md6
-rw-r--r--README.md6
-rw-r--r--service/container.go2
-rw-r--r--service/container_test.go8
-rw-r--r--service/entry.go4
-rw-r--r--service/http/service_test.go4
-rw-r--r--service/limit/controller.go20
-rw-r--r--service/limit/service.go1
-rw-r--r--service/limit/service_test.go99
-rw-r--r--service/static/service_test.go2
11 files changed, 128 insertions, 30 deletions
diff --git a/.rr.yaml b/.rr.yaml
index 3c5b98e1..481392e2 100644
--- a/.rr.yaml
+++ b/.rr.yaml
@@ -74,13 +74,13 @@ limit:
maxMemory: 100
# maximum time to live for the worker (soft)
- maxTTL: 0
+ TTL: 0
# maximum allowed amount of time worker can spend in idle before being removed (for weak db connections, soft)
- maxIdleTTL: 0
+ idleTTL: 0
# max_execution_time (brutal)
- maxExecTTL: 60
+ execTTL: 60
# static file serving. remove this section to disable static file serving.
static:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59091bc8..775f6c22 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,9 +9,9 @@ v1.4.0
- `real ip` resolution using X-Real-Ip and X-Forwarded-For (+cidr verification)
- automatic worker lifecycle manager (controller)
- maxMemory (graceful stop)
- - maxTTL (graceful stop)
- - maxIdleTTL (graceful stop)
- - maxExecTTL (brute, max_execution_time)
+ - ttl (graceful stop)
+ - idleTTL (graceful stop)
+ - execTTL (brute, max_execution_time)
- the ability to stop rr using `rr stop`
- `maxRequest` option has been deprecated in favor of `maxRequestSize`
- `/vendor/bin/rr get` to download rr server binary (symfony/console) by @Alex-Bond
diff --git a/README.md b/README.md
index 3c6e5807..5e7b74eb 100644
--- a/README.md
+++ b/README.md
@@ -37,9 +37,9 @@ Features:
- max jobs per worker
- worker lifecycle management (controller)
- maxMemory (graceful stop)
- - maxTTL (graceful stop)
- - maxIdleTTL (graceful stop)
- - maxExecTTL (brute, max_execution_time)
+ - TTL (graceful stop)
+ - idleTTL (graceful stop)
+ - execTTL (brute, max_execution_time)
- payload context and body
- protocol, worker and job level error management (including PHP errors)
- memory leak failswitch
diff --git a/service/container.go b/service/container.go
index ea1819d8..1cf4a5f6 100644
--- a/service/container.go
+++ b/service/container.go
@@ -94,7 +94,7 @@ func (c *container) Register(name string, service interface{}) {
c.services = append(c.services, &entry{
name: name,
svc: service,
- status: StatusRegistered,
+ status: StatusInactive,
})
}
diff --git a/service/container_test.go b/service/container_test.go
index 99cb75a3..8fcaede2 100644
--- a/service/container_test.go
+++ b/service/container_test.go
@@ -139,7 +139,7 @@ func TestContainer_Get(t *testing.T) {
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
- assert.Equal(t, StatusRegistered, st)
+ assert.Equal(t, StatusInactive, st)
s, st = c.Get("another")
assert.Nil(t, s)
@@ -227,7 +227,7 @@ func TestContainer_ConfigureNull(t *testing.T) {
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
- assert.Equal(t, StatusRegistered, st)
+ assert.Equal(t, StatusInactive, st)
}
func TestContainer_ConfigureDisabled(t *testing.T) {
@@ -245,7 +245,7 @@ func TestContainer_ConfigureDisabled(t *testing.T) {
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
- assert.Equal(t, StatusRegistered, st)
+ assert.Equal(t, StatusInactive, st)
}
func TestContainer_ConfigureError(t *testing.T) {
@@ -268,7 +268,7 @@ func TestContainer_ConfigureError(t *testing.T) {
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
- assert.Equal(t, StatusRegistered, st)
+ assert.Equal(t, StatusInactive, st)
}
func TestContainer_ConfigureTwice(t *testing.T) {
diff --git a/service/entry.go b/service/entry.go
index f2cbac28..b8da6514 100644
--- a/service/entry.go
+++ b/service/entry.go
@@ -8,8 +8,8 @@ const (
// StatusUndefined when service bus can not find the service.
StatusUndefined = iota
- // StatusRegistered hasStatus setStatus when service has been registered in container.
- StatusRegistered
+ // StatusInactive hasStatus setStatus when service has been registered in container.
+ StatusInactive
// StatusOK hasStatus setStatus when service has been properly configured.
StatusOK
diff --git a/service/http/service_test.go b/service/http/service_test.go
index 5b6d60d8..b3b001c7 100644
--- a/service/http/service_test.go
+++ b/service/http/service_test.go
@@ -57,7 +57,7 @@ func Test_Service_NoConfig(t *testing.T) {
s, st := c.Get(ID)
assert.NotNil(t, s)
- assert.Equal(t, service.StatusRegistered, st)
+ assert.Equal(t, service.StatusInactive, st)
}
func Test_Service_Configure_Disable(t *testing.T) {
@@ -71,7 +71,7 @@ func Test_Service_Configure_Disable(t *testing.T) {
s, st := c.Get(ID)
assert.NotNil(t, s)
- assert.Equal(t, service.StatusRegistered, st)
+ assert.Equal(t, service.StatusInactive, st)
}
func Test_Service_Configure_Enable(t *testing.T) {
diff --git a/service/limit/controller.go b/service/limit/controller.go
index 3e6aed4b..706197fa 100644
--- a/service/limit/controller.go
+++ b/service/limit/controller.go
@@ -32,11 +32,11 @@ type controllerConfig struct {
// TTL defines maximum time worker is allowed to live.
TTL int64
- // MaxIdleTTL defines maximum duration worker can spend in idle mode.
- MaxIdleTTL int64
+ // IdleTTL defines maximum duration worker can spend in idle mode.
+ IdleTTL int64
- // MaxExecTTL defines maximum lifetime per job.
- MaxExecTTL int64
+ // ExecTTL defines maximum lifetime per job.
+ ExecTTL int64
}
type controller struct {
@@ -56,13 +56,13 @@ func (c *controller) control(p roadrunner.Pool) {
now := time.Now()
- if c.cfg.MaxExecTTL != 0 {
+ if c.cfg.ExecTTL != 0 {
for _, w := range c.sw.find(
roadrunner.StateWorking,
- now.Add(-time.Second*time.Duration(c.cfg.MaxExecTTL)),
+ now.Add(-time.Second*time.Duration(c.cfg.ExecTTL)),
) {
eID := w.State().NumExecs()
- err := fmt.Errorf("max exec time reached (%vs)", c.cfg.MaxExecTTL)
+ err := fmt.Errorf("max exec time reached (%vs)", c.cfg.ExecTTL)
// make sure worker still on initial request
if p.Remove(w, err) && w.State().NumExecs() == eID {
@@ -73,12 +73,12 @@ func (c *controller) control(p roadrunner.Pool) {
}
// locale workers which are in idle mode for too long
- if c.cfg.MaxIdleTTL != 0 {
+ if c.cfg.IdleTTL != 0 {
for _, w := range c.sw.find(
roadrunner.StateReady,
- now.Add(-time.Second*time.Duration(c.cfg.MaxIdleTTL)),
+ now.Add(-time.Second*time.Duration(c.cfg.IdleTTL)),
) {
- err := fmt.Errorf("max idle time reached (%vs)", c.cfg.MaxIdleTTL)
+ err := fmt.Errorf("max idle time reached (%vs)", c.cfg.IdleTTL)
if p.Remove(w, err) {
c.report(EventMaxIdleTTL, w, err)
}
diff --git a/service/limit/service.go b/service/limit/service.go
index 99e2b1ee..6cbc22be 100644
--- a/service/limit/service.go
+++ b/service/limit/service.go
@@ -16,7 +16,6 @@ type controllable interface {
// Service to control the state of rr service inside other services.
type Service struct {
- cfg *Config
lsns []func(event int, ctx interface{})
}
diff --git a/service/limit/service_test.go b/service/limit/service_test.go
new file mode 100644
index 00000000..87c8046b
--- /dev/null
+++ b/service/limit/service_test.go
@@ -0,0 +1,99 @@
+package limit
+
+import (
+ "encoding/json"
+ "fmt"
+ "github.com/sirupsen/logrus"
+ "github.com/sirupsen/logrus/hooks/test"
+ "github.com/spiral/roadrunner/service"
+ rrhttp "github.com/spiral/roadrunner/service/http"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
+ "net/http"
+ "testing"
+ "time"
+)
+
+type testCfg struct {
+ httpCfg string
+ limitCfg string
+ target string
+}
+
+func (cfg *testCfg) Get(name string) service.Config {
+ if name == rrhttp.ID {
+ if cfg.httpCfg == "" {
+ return nil
+ }
+
+ return &testCfg{target: cfg.httpCfg}
+ }
+
+ if name == ID {
+ return &testCfg{target: cfg.limitCfg}
+ }
+
+ return nil
+}
+
+func (cfg *testCfg) Unmarshal(out interface{}) error {
+ err := json.Unmarshal([]byte(cfg.target), out)
+
+ if cl, ok := out.(*Config); ok {
+ // to speed up tests
+ cl.Interval = time.Millisecond
+ }
+
+ return err
+}
+
+func Test_Service_PidEcho(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rrhttp.ID, &rrhttp.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ httpCfg: `{
+ "address": ":6029",
+ "workers":{
+ "command": "php ../../tests/http/client.php pid pipes",
+ "pool": {"numWorkers": 1}
+ }
+ }`,
+ limitCfg: `{
+ "services": {
+ "http": {
+ "ttl": 1
+ }
+ }
+ }`,
+ }))
+
+ s, _ := c.Get(rrhttp.ID)
+ assert.NotNil(t, s)
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ req, err := http.NewRequest("GET", "http://localhost:6029", nil)
+ assert.NoError(t, err)
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ defer r.Body.Close()
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.NoError(t, err)
+ assert.Equal(t, getPID(s), string(b))
+}
+
+func getPID(s interface{}) string {
+ w := s.(*rrhttp.Service).Server().Workers()[0]
+ return fmt.Sprintf("%v", *w.Pid)
+}
diff --git a/service/static/service_test.go b/service/static/service_test.go
index d69b2fdd..d345b138 100644
--- a/service/static/service_test.go
+++ b/service/static/service_test.go
@@ -97,7 +97,7 @@ func Test_Disabled(t *testing.T) {
s, st := c.Get(ID)
assert.NotNil(t, s)
- assert.Equal(t, service.StatusRegistered, st)
+ assert.Equal(t, service.StatusInactive, st)
}
func Test_Files_Disable(t *testing.T) {