Skip to content
/ gcra Public

Package gcra implements the generic cell rate algorithm

License

Notifications You must be signed in to change notification settings

256dpi/gcra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcra

Test GoDoc Release

Package gcra implements the generic cell rate algorithm (GCRA).

Example

opts := Options{
    Burst:  50,
    Rate:   10,
    Period: time.Second,
}

now := time.Now()

bucket := MustGenerate(now, 25, opts)

bucket, result := MustCompute(now, bucket, 10, opts)
fmt.Printf("%+v\n", result)

bucket, result = MustCompute(now, bucket, 30, opts)
fmt.Printf("%+v\n", result)

bucket, result = MustCompute(now, bucket, 15, opts)
fmt.Printf("%+v\n", result)

now = now.Add(2 * time.Second)

bucket, result = MustCompute(now, bucket, 0, opts)
fmt.Printf("%+v\n", result)

fmt.Printf("Bucket Offset: %s", time.Time(bucket).Sub(now).String())

// Output:
// {Limited:false Remaining:15 RetryIn:0s ResetIn:3.5s}
// {Limited:true Remaining:15 RetryIn:1.5s ResetIn:3.5s}
// {Limited:false Remaining:0 RetryIn:0s ResetIn:5s}
// {Limited:false Remaining:20 RetryIn:0s ResetIn:3s}
// Bucket Offset: 3s

About

Package gcra implements the generic cell rate algorithm

Resources

License

Stars

Watchers

Forks

Packages

No packages published