some rate limiting
This commit is contained in:
parent
cc8b8cf7a4
commit
8b131ba347
1
README
1
README
@ -42,7 +42,6 @@ gobyexample.com signups
|
||||
* web app
|
||||
* serve static files
|
||||
* mongo
|
||||
* rate limiting
|
||||
* time formatting
|
||||
* typed json parse/unparse
|
||||
* gzip
|
||||
|
25
src/xx-burstable-rate-limiting.go
Normal file
25
src/xx-burstable-rate-limiting.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import ("time"; "fmt")
|
||||
|
||||
func main() {
|
||||
tick := time.Tick(time.Millisecond * 200)
|
||||
throttle := make(chan bool, 10)
|
||||
go func() {
|
||||
for {
|
||||
<- tick
|
||||
select {
|
||||
case throttle <- true:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Millisecond * 1000)
|
||||
for {
|
||||
<- throttle
|
||||
go fmt.Println("acting")
|
||||
}
|
||||
}
|
||||
|
||||
// == todo
|
||||
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting
|
15
src/xx-rate-limiting.go
Normal file
15
src/xx-rate-limiting.go
Normal file
@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import ("time"; "fmt")
|
||||
|
||||
func main() {
|
||||
throttle := time.Tick(time.Millisecond * 200)
|
||||
for {
|
||||
<- throttle
|
||||
go fmt.Println("rate-limited action")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// == todo
|
||||
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting
|
Loading…
x
Reference in New Issue
Block a user