From 1fd9dc00336e80c875081aac8d8b74dfaa65fd2b Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 16:48:48 +0300 Subject: Add pprof endpoint --- cmd/rr/cmd/pprof.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cmd/rr/cmd/pprof.go diff --git a/cmd/rr/cmd/pprof.go b/cmd/rr/cmd/pprof.go new file mode 100644 index 00000000..3e06155c --- /dev/null +++ b/cmd/rr/cmd/pprof.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "log" + "net/http" + "net/http/pprof" +) + +func init() { + CLI.AddCommand(&cobra.Command{ + Use: "pprof", + Short: "Profile RoadRunner service(s)", + Example: "rr serve -d -v pprof http://localhost:6061", + Run: runDebugServer, + }) +} + +func runDebugServer(cmd *cobra.Command, args []string) { + var address string = "http://localhost:6061" + // guess that user set the address + if len(args) > 0 { + address = args[0] + } + mux := http.NewServeMux() + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + srv := http.Server{ + Addr: address, + Handler: mux, + } + if err := srv.ListenAndServe(); err != nil { + log.Fatal(err) + } +} -- cgit v1.2.3 From bd6841122908dc8e37ca0f13ab1a95f0f1e923ae Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 16:57:38 +0300 Subject: From code-review --> remove .rr.yaml from ignote, add .rr-sample.yaml instead as user local configuration --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4d651033..7fb2cf09 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ composer.lock vendor builds/ tests/vendor/ -.rr.yaml +.rr-sample.yaml psr-worker.php \ No newline at end of file -- cgit v1.2.3 From 14c0d45e2317f39c41b6015381626a99de8e510b Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 16:58:52 +0300 Subject: Process error from stop.go cobra CLI --- cmd/rr/cmd/stop.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/rr/cmd/stop.go b/cmd/rr/cmd/stop.go index 8beee73e..7b4794e7 100644 --- a/cmd/rr/cmd/stop.go +++ b/cmd/rr/cmd/stop.go @@ -38,7 +38,6 @@ func stopHandler(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer client.Close() util.Printf("Stopping RoadRunner: ") @@ -48,5 +47,5 @@ func stopHandler(cmd *cobra.Command, args []string) error { } util.Printf("done\n") - return nil + return client.Close() } -- cgit v1.2.3 From c1a227d465e857bbf4ba2f5f686aadb9b6b8d348 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 19:01:20 +0300 Subject: Move pprof from pprof.go to root.go --- cmd/rr/cmd/pprof.go | 38 -------------------------------------- cmd/rr/cmd/root.go | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 cmd/rr/cmd/pprof.go diff --git a/cmd/rr/cmd/pprof.go b/cmd/rr/cmd/pprof.go deleted file mode 100644 index 3e06155c..00000000 --- a/cmd/rr/cmd/pprof.go +++ /dev/null @@ -1,38 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" - "log" - "net/http" - "net/http/pprof" -) - -func init() { - CLI.AddCommand(&cobra.Command{ - Use: "pprof", - Short: "Profile RoadRunner service(s)", - Example: "rr serve -d -v pprof http://localhost:6061", - Run: runDebugServer, - }) -} - -func runDebugServer(cmd *cobra.Command, args []string) { - var address string = "http://localhost:6061" - // guess that user set the address - if len(args) > 0 { - address = args[0] - } - mux := http.NewServeMux() - mux.HandleFunc("/debug/pprof/", pprof.Index) - mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) - mux.HandleFunc("/debug/pprof/profile", pprof.Profile) - mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) - mux.HandleFunc("/debug/pprof/trace", pprof.Trace) - srv := http.Server{ - Addr: address, - Handler: mux, - } - if err := srv.ListenAndServe(); err != nil { - log.Fatal(err) - } -} diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index 515e6419..456cfc6a 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -26,6 +26,9 @@ import ( "github.com/spiral/roadrunner/cmd/util" "github.com/spiral/roadrunner/service" "github.com/spiral/roadrunner/service/limit" + "log" + "net/http" + "net/http/pprof" "os" ) @@ -116,8 +119,29 @@ func init() { }) } } + + // if debug --> also run pprof service + if Debug { + go runDebugServer() + } }) } +func runDebugServer() { + mux := http.NewServeMux() + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + srv := http.Server{ + Addr: ":6061", + Handler: mux, + } + + if err := srv.ListenAndServe(); err != nil { + log.Fatal(err) + } +} func configureLogger(format string) { util.Colorize = false -- cgit v1.2.3 From 6245e18258eccc0fe53725492303669005eae64a Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 22:39:00 +0300 Subject: Fix linker coded values --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index a27da775..2ca858e2 100755 --- a/build.sh +++ b/build.sh @@ -45,4 +45,4 @@ if [ "$1" == "all" ]; then exit fi -go build -o "$OD/rr" cmd/rr/main.go +go build -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go -- cgit v1.2.3 From ed2df68318f0e2e82c95bc54699c5a9610f906f3 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 11 Feb 2020 22:42:46 +0300 Subject: Temporary turn off php get-binary due to instability --- .github/workflows/ci-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index cf63195c..578de0c0 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -62,8 +62,8 @@ jobs: - name: Install Go dependencies run: go mod download - - name: Download binary roadrunner - run: php ./bin/rr get-binary +# - name: Download binary roadrunner +# run: php ./bin/rr get-binary - name: Run golang tests run: | -- cgit v1.2.3 From a693018d213abbc5774c2a0fe60c1087c2da83da Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 12 Feb 2020 10:40:23 +0300 Subject: Stabilize CI Add -s flag to ldflags to remove DWARF, string and symbol tables from release binaries --- .github/workflows/ci-build.yml | 4 ++-- build.sh | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 578de0c0..cf63195c 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -62,8 +62,8 @@ jobs: - name: Install Go dependencies run: go mod download -# - name: Download binary roadrunner -# run: php ./bin/rr get-binary + - name: Download binary roadrunner + run: php ./bin/rr get-binary - name: Run golang tests run: | diff --git a/build.sh b/build.sh index 2ca858e2..8015a481 100755 --- a/build.sh +++ b/build.sh @@ -8,6 +8,8 @@ RR_VERSION=1.6.0 # Hardcode some values to the core package LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}" LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$(date +%FT%T%z)" +# remove debug info from binary as well as string and symbol tables +LDFLAGS="$LDFLAGS -s" build(){ echo Packaging $1 Build -- cgit v1.2.3 From c1669aadcd599e863970ec371e8b23ca669674d6 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 12 Feb 2020 11:07:18 +0300 Subject: Update pause time in Test_Serve_Client --- service/rpc/service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/rpc/service_test.go b/service/rpc/service_test.go index ee87509a..11e8fcb5 100644 --- a/service/rpc/service_test.go +++ b/service/rpc/service_test.go @@ -71,16 +71,16 @@ func Test_Serve_Client(t *testing.T) { assert.NoError(t, s.Register("test", &testService{})) go func() { assert.NoError(t, s.Serve()) }() - time.Sleep(time.Millisecond) + time.Sleep(time.Second) client, err := s.Client() assert.NotNil(t, client) assert.NoError(t, err) - defer client.Close() var resp string assert.NoError(t, client.Call("test.Echo", "hello world", &resp)) assert.Equal(t, "hello world", resp) + assert.NoError(t, client.Close()) } func TestSetEnv(t *testing.T) { -- cgit v1.2.3