diff options
-rw-r--r-- | cmd/rr/cmd/serve.go | 6 | ||||
-rw-r--r-- | cmd/rr/main.go | 25 | ||||
-rw-r--r-- | static_pool.go | 5 |
3 files changed, 28 insertions, 8 deletions
diff --git a/cmd/rr/cmd/serve.go b/cmd/rr/cmd/serve.go index 334771ae..c53f7ce9 100644 --- a/cmd/rr/cmd/serve.go +++ b/cmd/rr/cmd/serve.go @@ -37,13 +37,11 @@ func init() { }) signal.Notify(stopSignal, syscall.SIGTERM) + signal.Notify(stopSignal, syscall.SIGINT) } func serveHandler(cmd *cobra.Command, args []string) error { - if err := Container.Serve(); err != nil { - return err - } - + go Container.Serve() <-stopSignal Container.Stop() diff --git a/cmd/rr/main.go b/cmd/rr/main.go index db696904..07448feb 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -26,7 +26,7 @@ import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) - "github.com/spiral/roadrunner/service/http" + rrhtp "github.com/spiral/roadrunner/service/http" "github.com/spiral/roadrunner/service/rpc" "github.com/spiral/roadrunner/service/static" @@ -35,16 +35,33 @@ import ( "github.com/spiral/roadrunner/cmd/rr/debug" "github.com/spf13/cobra" + _ "net/http/pprof" + "os" + "log" + "runtime/pprof" + "net/http" ) var debugMode bool func main() { + f, err := os.Create("cpu.pprof") + if err != nil { + log.Fatal(err) + } + + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + + go func() { + log.Println(http.ListenAndServe("localhost:6060", nil)) + }() + // provides ability to make local connection to services rr.Container.Register(rpc.Name, &rpc.Service{}) // http serving - rr.Container.Register(http.Name, &http.Service{}) + rr.Container.Register(rrhtp.Name, &rrhtp.Service{}) // serving static files rr.Container.Register(static.Name, &static.Service{}) @@ -55,8 +72,8 @@ func main() { rr.CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode", ) cobra.OnInitialize(func() { if debugMode { - service, _ := rr.Container.Get(http.Name) - service.(*http.Service).AddListener(debug.NewListener(rr.Logger).Listener) + service, _ := rr.Container.Get(rrhtp.Name) + service.(*rrhtp.Service).AddListener(debug.NewListener(rr.Logger).Listener) } }) diff --git a/static_pool.go b/static_pool.go index bb418649..f82bc797 100644 --- a/static_pool.go +++ b/static_pool.go @@ -148,6 +148,8 @@ func (p *StaticPool) allocateWorker() (w *Worker, err error) { case w = <-p.free: if w.state.Value() == StateReady { return w, nil + } else { + continue } default: // enable timeout handler @@ -159,8 +161,11 @@ func (p *StaticPool) allocateWorker() (w *Worker, err error) { return nil, fmt.Errorf("worker timeout (%s)", p.cfg.AllocateTimeout) case w := <-p.free: timeout.Stop() + if w.state.Value() == StateReady { return w, nil + } else { + continue } } } |