[hotfix] Add batch size and interval to broadcast messages
Context:
- based on inspection of source code signal server imposes rate limit of roughly 50 messages with attachments per minute
- Attachment rate limit: https://github.com/signalapp/Signal-Server/blob/940bd55079037ca0116a37c8cb060f0578ceabf6/service/src/main/java/org/whispersystems/textsecuregcm/configuration/RateLimitsConfiguration.java#L48
- Messages rate limit: https://github.com/signalapp/Signal-Server/blob/940bd55079037ca0116a37c8cb060f0578ceabf6/service/src/main/java/org/whispersystems/textsecuregcm/configuration/RateLimitsConfiguration.java#L57
- we were not observing that rate limit and thus getting dropped messages (and sometimes crashes when attempting to resend
Changes
- this batches messages to send in bursts of 50 every minute to avoid rate limiting
Out of Scope
- we might want to provide users with a footer notifying them that their message was sent earlier than they are receiving it but that is left to a separate card. (if we do it at all!)
Technical Details
Leaky Bucket Rate Limiting
- Signal uses the leaky bucket rate limiting algorithm
- It works by having two things: a bucket size and a leak rate
- Every request that comes in is added to the bucket
- Every x amount of time (for signal it is per minute), the bucket will leak out certain # of requests (the leak rate)
- Success example: attachments for signal have a bucket size of 50 and a leak rate of 50/minute. if we send 35 requests at a time, the bucket will go up to 35 and then after a minute, they will leak out, which means that all requests we sent were valid
- Failure example: if we send 60 requests in a minute, the bucket will go up to 50 as that is the bucket size, those 50 requests will be processed and then the remaining 10 will all be dropped. after 1 minute, the bucket will go back down to 0
Edited by feed back