summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpool.go5
-rwxr-xr-xstatic_pool_test.go44
2 files changed, 49 insertions, 0 deletions
diff --git a/pool.go b/pool.go
index bc57bcbd..de7e837d 100755
--- a/pool.go
+++ b/pool.go
@@ -75,6 +75,11 @@ type Config struct {
// worker handle as many tasks as it can.
MaxJobs int64
+ // Deferred flag enables slower working mode which inits empty worker ahead of every request. Useful to debug
+ // applications with heavy bootload phase. Do not use at production. It is also keeps pool without any workers
+ // until first request.
+ Deferred bool
+
// AllocateTimeout defines for how long pool will be waiting for a worker to
// be freed to handle the task. Defaults to 60s.
AllocateTimeout time.Duration
diff --git a/static_pool_test.go b/static_pool_test.go
index ec80e92a..c9a43f69 100755
--- a/static_pool_test.go
+++ b/static_pool_test.go
@@ -301,6 +301,50 @@ func Test_StaticPool_Replace_Worker(t *testing.T) {
}
}
+func Test_StaticPool_Debug_Worker(t *testing.T) {
+ ctx := context.Background()
+ p, err := NewPool(
+ ctx,
+ func() *exec.Cmd { return exec.Command("php", "tests/client.php", "pid", "pipes") },
+ NewPipeFactory(),
+ Config{
+ Deferred: true,
+ NumWorkers: 1,
+ MaxJobs: 1,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ )
+ assert.NoError(t, err)
+ defer p.Destroy(ctx)
+
+ assert.NotNil(t, p)
+
+ assert.Len(t, p.Workers(), 0)
+
+ var lastPID string
+ res, _ := p.Exec(Payload{Body: []byte("hello")})
+
+ assert.Len(t, p.Workers(), 1)
+
+ lastPID = strconv.Itoa(int(p.Workers()[0].Pid()))
+ res, _ = p.Exec(Payload{Body: []byte("hello")})
+ assert.NotEqual(t, lastPID, string(res.Body))
+
+ for i := 0; i < 10; i++ {
+ lastPID = strconv.Itoa(int(p.Workers()[0].Pid()))
+ res, err := p.Exec(Payload{Body: []byte("hello")})
+
+ assert.NoError(t, err)
+ assert.NotNil(t, res)
+ assert.NotNil(t, res.Body)
+ assert.Nil(t, res.Context)
+
+ assert.NotEqual(t, lastPID, string(res.Body))
+ lastPID = string(res.Body)
+ }
+}
+
// identical to replace but controlled on worker side
func Test_StaticPool_Stop_Worker(t *testing.T) {
ctx := context.Background()