diff options
author | Valery Piashchynski <[email protected]> | 2021-05-14 09:19:00 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-05-14 09:19:00 +0300 |
commit | f76b2392cd5b0c4e9f38736323a29b46f9451f0e (patch) | |
tree | b463fd9267323bec1ed8a63f871686ed99843611 /pkg | |
parent | fef96198ee6cc1f23bc869050944aa3071667ae7 (diff) | |
parent | e1ff9daead5033b537296ffb071e551b95af91ab (diff) |
Merge remote-tracking branch 'origin/master' into feature/websockets-plugin
# Conflicts:
# plugins/http/plugin.go
# plugins/static/etag.go
Diffstat (limited to 'pkg')
-rwxr-xr-x | pkg/pool/static_pool.go | 22 | ||||
-rwxr-xr-x | pkg/pool/static_pool_test.go | 4 | ||||
-rw-r--r-- | pkg/pool/supervisor_test.go | 28 |
3 files changed, 51 insertions, 3 deletions
diff --git a/pkg/pool/static_pool.go b/pkg/pool/static_pool.go index 54192262..d57cc95c 100755 --- a/pkg/pool/static_pool.go +++ b/pkg/pool/static_pool.go @@ -170,6 +170,10 @@ func (sp *StaticPool) Exec(p payload.Payload) (payload.Payload, error) { // Be careful, sync with pool.Exec method func (sp *StaticPool) execWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error) { const op = errors.Op("static_pool_exec_with_context") + if sp.cfg.Debug { + return sp.execDebugWithTTL(ctx, p) + } + ctxAlloc, cancel := context.WithTimeout(ctx, sp.cfg.AllocateTimeout) defer cancel() w, err := sp.getWorker(ctxAlloc, op) @@ -243,7 +247,6 @@ func defaultErrEncoder(sp *StaticPool) ErrorEncoder { return func(err error, w worker.BaseProcess) (payload.Payload, error) { const op = errors.Op("error encoder") // just push event if on any stage was timeout error - switch { case errors.Is(errors.ExecTTL, err): sp.events.Push(events.PoolEvent{Event: events.EventExecTTL, Payload: errors.E(op, err)}) @@ -296,14 +299,31 @@ func (sp *StaticPool) newPoolAllocator(ctx context.Context, timeout time.Duratio } } +// execDebug used when debug mode was not set and exec_ttl is 0 func (sp *StaticPool) execDebug(p payload.Payload) (payload.Payload, error) { sw, err := sp.allocator() if err != nil { return payload.Payload{}, err } + // redirect call to the workers exec method (without ttl) r, err := sw.Exec(p) + if stopErr := sw.Stop(); stopErr != nil { + sp.events.Push(events.WorkerEvent{Event: events.EventWorkerError, Worker: sw, Payload: err}) + } + + return r, err +} + +// execDebugWithTTL used when user set debug mode and exec_ttl +func (sp *StaticPool) execDebugWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error) { + sw, err := sp.allocator() + if err != nil { + return payload.Payload{}, err + } + // redirect call to the worker with TTL + r, err := sw.ExecWithTTL(ctx, p) if stopErr := sw.Stop(); stopErr != nil { sp.events.Push(events.WorkerEvent{Event: events.EventWorkerError, Worker: sw, Payload: err}) } diff --git a/pkg/pool/static_pool_test.go b/pkg/pool/static_pool_test.go index bf7f10e0..6667bfea 100755 --- a/pkg/pool/static_pool_test.go +++ b/pkg/pool/static_pool_test.go @@ -647,7 +647,7 @@ func Benchmark_Pool_Echo_Replaced(b *testing.B) { } // BenchmarkToStringUnsafe-12 566317729 1.91 ns/op 0 B/op 0 allocs/op -// inline BenchmarkToStringUnsafe-12 1000000000 0.295 ns/op 0 B/op 0 allocs/op +// BenchmarkToStringUnsafe-32 1000000000 0.4434 ns/op 0 B/op 0 allocs/op func BenchmarkToStringUnsafe(b *testing.B) { testPayload := []byte("falsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtoj") b.ResetTimer() @@ -659,7 +659,7 @@ func BenchmarkToStringUnsafe(b *testing.B) { } } -// BenchmarkToStringSafe-12 28584489 39.1 ns/op 112 B/op 1 allocs/op +// BenchmarkToStringSafe-32 8017846 182.5 ns/op 896 B/op 1 allocs/op // inline BenchmarkToStringSafe-12 28926276 46.6 ns/op 128 B/op 1 allocs/op func BenchmarkToStringSafe(b *testing.B) { testPayload := []byte("falsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtojfalsflasjlifjwpoihejfoiwejow{}{}{}{}jelfjasjfhwaopiehjtopwhtgohrgouahsgkljasdlfjasl;fjals;jdflkndgouwhetopwqhjtoj") diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go index d7e97fdd..dc307c33 100644 --- a/pkg/pool/supervisor_test.go +++ b/pkg/pool/supervisor_test.go @@ -53,6 +53,34 @@ func TestSupervisedPool_Exec(t *testing.T) { p.Destroy(context.Background()) } +// This test should finish without freezes +func TestSupervisedPool_ExecWithDebugMode(t *testing.T) { + var cfgSupervised = cfgSupervised + cfgSupervised.Debug = true + + ctx := context.Background() + p, err := Initialize( + ctx, + func() *exec.Cmd { return exec.Command("php", "../../tests/memleak.php", "pipes") }, + pipe.NewPipeFactory(), + cfgSupervised, + ) + + assert.NoError(t, err) + assert.NotNil(t, p) + + for i := 0; i < 100; i++ { + time.Sleep(time.Millisecond * 100) + _, err = p.Exec(payload.Payload{ + Context: []byte(""), + Body: []byte("foo"), + }) + assert.NoError(t, err) + } + + p.Destroy(context.Background()) +} + func TestSupervisedPool_ExecTTL_TimedOut(t *testing.T) { var cfgExecTTL = Config{ NumWorkers: uint64(1), |