Skip to content

Instantly share code, notes, and snippets.

@farhany
Last active April 26, 2019 20:28
Show Gist options
  • Save farhany/602a2ec9c9035b8f2bc6a23681f0b3c3 to your computer and use it in GitHub Desktop.
Save farhany/602a2ec9c9035b8f2bc6a23681f0b3c3 to your computer and use it in GitHub Desktop.
Rate Limiting for HTTP
// Source: https://stackoverflow.com/questions/17959732/why-is-go-https-client-not-reusing-connections
import "time"
requests_per_second := 5
throttle := time.Tick(1000000000 / requests_per_second)
for i := 0; i < 16; i += 1 {
<-throttle
go serveQueue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment