From 5948f39a53268543d01ee6f31a7859f2f186664f Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 3 Nov 2021 21:16:07 -0400 Subject: [PATCH] Add firebase subscriber to topics from cache upon initialization; stricter rate limits --- config/config.go | 4 ++-- server/server.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 186c019..b244349 100644 --- a/config/config.go +++ b/config/config.go @@ -15,12 +15,12 @@ const ( ) // Defines all the limits -// - request limit: max number of PUT/GET/.. requests (here: 50 requests bucket, replenished at a rate of 1 per second) +// - request limit: max number of PUT/GET/.. requests (here: 50 requests bucket, replenished at a rate of one per 10 seconds) // - global topic limit: max number of topics overall // - subscription limit: max number of subscriptions (active HTTP connections) per per-visitor/IP var ( defaultGlobalTopicLimit = 5000 - defaultVisitorRequestLimit = rate.Every(time.Second) + defaultVisitorRequestLimit = rate.Every(10 * time.Second) defaultVisitorRequestLimitBurst = 50 defaultVisitorSubscriptionLimit = 30 ) diff --git a/server/server.go b/server/server.go index c7e5afc..64d26a0 100644 --- a/server/server.go +++ b/server/server.go @@ -47,7 +47,7 @@ func (e errHTTP) Error() string { } const ( - messageLimit = 1024 + messageLimit = 512 ) var ( @@ -86,6 +86,11 @@ func New(conf *config.Config) (*Server, error) { if err != nil { return nil, err } + for _, t := range topics { + if firebaseSubscriber != nil { + t.Subscribe(firebaseSubscriber) + } + } return &Server{ config: conf, cache: cache,