adlio / trello

Trello API wrapper for Go
MIT License
219 stars 71 forks source link

Use rate.Limiter for throttling #73

Closed Rukenshia closed 3 years ago

Rukenshia commented 3 years ago

from my manual testing, this will no longer cause high CPU usage (as reported in #72).

I wasn't sure how to properly test the throttling, but looking at the documentation of the rate package this should do.

I used this for testing:

package main

import (
    "log"
    "time"

    "github.com/Rukenshia/trello"
)

func main() {
    for {
        log.Printf("Creating 100 new clients")
        for i := 0; i < 100; i++ {
            client := trello.NewClient("foo", "bar")

            log.Printf("client: %v", client)
        }
        time.Sleep(5 * time.Second)
    }
}

before this change, CPU usage went up with every 5 second iteration. After the change, the CPU usage is consistently at 0%.