• Kubernetes Submit Queue's avatar
    Merge pull request #38294 from liggitt/rate-limit · 440ed2cf
    Kubernetes Submit Queue authored
    Automatic merge from submit-queue (batch tested with PRs 38294, 37009, 36778, 38130, 37835)
    
    Re-use tested ratelimiter
    
    The ratelimiter introduced in #35583 is not working correctly when called from multiple threads
    This reverts to the tested ratelimiter we were previously using to unblock 1.5 (automated revert wasn't possible)
    Ref #38273
    
    reproducing test case:
    ```
    func TestMultiThreadedBlocking(t *testing.T) {
    	done := make(chan bool)
    
    	// 100 QPS, burst of 100
    	b := NewBucketWithRate(100, 100)
    
    	go func() {
    		defer close(done)
    		fmt.Println(time.Now(), "Waiting for 1000 (should block for ~9-10 seconds)")
    		b.Wait(1000)
    		fmt.Println(time.Now(), "Got 1000")
    	}()
    
    	// give the request for 1000 plenty of time to take the tokens
    	time.Sleep(2 * time.Second)
    	fmt.Println(time.Now(), "Waiting for 1 (should wait until 1000 block is refilled)")
    	b.Wait(1)
    	fmt.Println(time.Now(), "Got 1 (should happen right after the wait for 1000 completes)")
    
    	<-done
    }
    
    $ go test ./pkg/util/ratelimit/ -v -run TestMultiThreadedBlocking
    === RUN   TestMultiThreadedBlocking
    2016-12-07 12:15:36.222133049 -0500 EST Waiting for 1000 (should block for ~9-10 seconds)
    2016-12-07 12:15:38.222797752 -0500 EST Waiting for 1 (should wait until 1000 block is refilled)
    2016-12-07 12:15:38.222897951 -0500 EST Got 1 (should happen right after the wait for 1000 completes)
    2016-12-07 12:15:45.223125234 -0500 EST Got 1000
    ```
    
    in contrast, the same test run against juju/ratelimit:
    ```
    go test ./pkg/util/flowcontrol/ -v -run TestMultiThreadedBlocking
    === RUN   TestMultiThreadedBlocking
    2016-12-07 12:32:56.796077782 -0500 EST Waiting for 1000 (should block for ~9-10 seconds)
    2016-12-07 12:32:58.799159059 -0500 EST Waiting for 1 (should wait until 1000 block is refilled)
    2016-12-07 12:33:05.801076002 -0500 EST Got 1000
    2016-12-07 12:33:05.807510387 -0500 EST Got 1 (should happen right after the wait for 1000 completes)
    --- PASS: TestMultiThreadedBlocking (9.01s)
    ```
    440ed2cf
Name
Last commit
Last update
.github Loading commit data...
Godeps Loading commit data...
api Loading commit data...
build-tools Loading commit data...
cluster Loading commit data...
cmd Loading commit data...
docs Loading commit data...
examples Loading commit data...
federation Loading commit data...
hack Loading commit data...
hooks Loading commit data...
logo Loading commit data...
pkg Loading commit data...
plugin Loading commit data...
staging Loading commit data...
test Loading commit data...
third_party Loading commit data...
vendor Loading commit data...
.gazelcfg.json Loading commit data...
.generated_docs Loading commit data...
.generated_files Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
BUILD Loading commit data...
CHANGELOG.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
Makefile.generated_files Loading commit data...
OWNERS Loading commit data...
OWNERS_ALIASES Loading commit data...
README.md Loading commit data...
Vagrantfile Loading commit data...
WORKSPACE Loading commit data...
code-of-conduct.md Loading commit data...
labels.yaml Loading commit data...