diff --git a/app/notification_push.go b/app/notification_push.go index 3dd056ce1a..fae062847d 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -333,7 +333,7 @@ func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session return err } - resp, err := a.HTTPService().MakeClient(true).Do(request) + resp, err := a.Srv().pushNotificationClient.Do(request) if err != nil { return err } diff --git a/app/notification_push_test.go b/app/notification_push_test.go index 83132cb118..3ccec8f118 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -1349,6 +1349,7 @@ func TestAllPushNotifications(t *testing.T) { assert.Equal(t, 6, numUpdateBadges) } +// Run it with | grep -v '{"level"' to prevent spamming the console. func BenchmarkPushNotification(b *testing.B) { th := SetupWithStoreMock(b) defer th.TearDown() @@ -1432,9 +1433,10 @@ func BenchmarkPushNotification(b *testing.B) { b.ResetTimer() // We have an inner loop which ranges the testdata slice // and we just repeat that. - // TODO: replace 10 by b.N then := time.Now() - for i := 0; i < 10; i++ { + cnt := 0 + for i := 0; i < b.N; i++ { + cnt++ var wg sync.WaitGroup for j, data := range testData { wg.Add(1) @@ -1473,7 +1475,7 @@ func BenchmarkPushNotification(b *testing.B) { } wg.Wait() } - b.Logf("time taken: %v", time.Since(then)) + b.Logf("throughput: %f reqs/s", float64(len(testData)*cnt)/time.Since(then).Seconds()) b.StopTimer() time.Sleep(2 * time.Second) } diff --git a/app/server.go b/app/server.go index 743e088d4f..8ffd881293 100644 --- a/app/server.go +++ b/app/server.go @@ -118,7 +118,8 @@ type Server struct { phase2PermissionsMigrationComplete bool - HTTPService httpservice.HTTPService + HTTPService httpservice.HTTPService + pushNotificationClient *http.Client // TODO: move this to it's own package ImageProxy *imageproxy.ImageProxy @@ -204,6 +205,7 @@ func NewServer(options ...Option) (*Server, error) { }) s.HTTPService = httpservice.MakeHTTPService(s) + s.pushNotificationClient = s.HTTPService.MakeClient(true) s.ImageProxy = imageproxy.MakeImageProxy(s, s.HTTPService, s.Log)