Add firebase subscriber to topics from cache upon initialization; stricter rate limits

This commit is contained in:
Philipp Heckel 2021-11-03 21:16:07 -04:00
parent eef85c0955
commit 5948f39a53
2 changed files with 8 additions and 3 deletions

View file

@ -15,12 +15,12 @@ const (
) )
// Defines all the limits // 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 // - global topic limit: max number of topics overall
// - subscription limit: max number of subscriptions (active HTTP connections) per per-visitor/IP // - subscription limit: max number of subscriptions (active HTTP connections) per per-visitor/IP
var ( var (
defaultGlobalTopicLimit = 5000 defaultGlobalTopicLimit = 5000
defaultVisitorRequestLimit = rate.Every(time.Second) defaultVisitorRequestLimit = rate.Every(10 * time.Second)
defaultVisitorRequestLimitBurst = 50 defaultVisitorRequestLimitBurst = 50
defaultVisitorSubscriptionLimit = 30 defaultVisitorSubscriptionLimit = 30
) )

View file

@ -47,7 +47,7 @@ func (e errHTTP) Error() string {
} }
const ( const (
messageLimit = 1024 messageLimit = 512
) )
var ( var (
@ -86,6 +86,11 @@ func New(conf *config.Config) (*Server, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, t := range topics {
if firebaseSubscriber != nil {
t.Subscribe(firebaseSubscriber)
}
}
return &Server{ return &Server{
config: conf, config: conf,
cache: cache, cache: cache,