Reason: The original steps 1 and 3 in the redisRateLimitHandler method were not atomic, leading to poor precision under high concurrent requests. For example, with a rate limit set to 60, sending 200 concurrent requests would result in none being blocked, whereas theoretically around 140 should be intercepted. Solution: I chose not to merge steps 1 and 3 into a single Lua script because a single atomic operation involving read, write, and delete operations could suffer from performance issues under high concurrency. Instead, I implemented a token bucket algorithm to optimize this, reducing the atomic operation to just read and write steps while significantly decreasing the memory footprint.
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| limiter | Loading commit data... | |
| constants.go | Loading commit data... | |
| crypto.go | Loading commit data... | |
| custom-event.go | Loading commit data... | |
| database.go | Loading commit data... | |
| email-outlook-auth.go | Loading commit data... | |
| email.go | Loading commit data... | |
| embed-file-system.go | Loading commit data... | |
| env.go | Loading commit data... | |
| gin.go | Loading commit data... | |
| go-channel.go | Loading commit data... | |
| gopool.go | Loading commit data... | |
| init.go | Loading commit data... | |
| json.go | Loading commit data... | |
| logger.go | Loading commit data... | |
| pprof.go | Loading commit data... | |
| rate-limit.go | Loading commit data... | |
| redis.go | Loading commit data... | |
| str.go | Loading commit data... | |
| topup-ratio.go | Loading commit data... | |
| utils.go | Loading commit data... | |
| validate.go | Loading commit data... | |
| verification.go | Loading commit data... |