From ac4765f813e1831b6581dd50abbc86af96093b0a Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 15 Jul 2021 20:50:04 -0400 Subject: [PATCH] tweak client settings --- internal/cmd/root.go | 21 ++++++++++++++++++--- internal/reddit/client.go | 6 +++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/cmd/root.go b/internal/cmd/root.go index b2843c9..2af3d7e 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -3,6 +3,7 @@ package cmd import ( "context" "os" + "runtime" "runtime/pprof" "github.com/DataDog/datadog-go/statsd" @@ -36,17 +37,31 @@ func Execute(ctx context.Context) int { if !profile { return nil } + f, perr := os.Create("cpu.pprof") if perr != nil { return perr } + pprof.StartCPUProfile(f) return nil }, - PersistentPostRun: func(cmd *cobra.Command, args []string) { - if profile { - pprof.StopCPUProfile() + PersistentPostRunE: func(cmd *cobra.Command, args []string) error { + if !profile { + return nil } + + pprof.StopCPUProfile() + + f, perr := os.Create("mem.pprof") + if perr != nil { + return perr + } + defer f.Close() + + runtime.GC() + err := pprof.WriteHeapProfile(f) + return err }, } diff --git a/internal/reddit/client.go b/internal/reddit/client.go index 32c738f..b88b9ca 100644 --- a/internal/reddit/client.go +++ b/internal/reddit/client.go @@ -61,9 +61,9 @@ func NewClient(id, secret string, statsd *statsd.Client, connLimit int) *Client } t := http.DefaultTransport.(*http.Transport).Clone() - t.MaxIdleConns = connLimit / 4 - t.MaxConnsPerHost = connLimit - t.MaxIdleConnsPerHost = connLimit / 4 + t.MaxIdleConns = connLimit / 4 / 100 + t.MaxConnsPerHost = connLimit / 100 + t.MaxIdleConnsPerHost = connLimit / 4 / 100 t.IdleConnTimeout = 60 * time.Second t.ResponseHeaderTimeout = 5 * time.Second