The ratelimit package provides an efficient token bucket implementation. See http://en.wikipedia.org/wiki/Token_bucket.