• 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
..
admission Loading commit data...
api Loading commit data...
apimachinery Loading commit data...
apis Loading commit data...
apiserver Loading commit data...
auth Loading commit data...
capabilities Loading commit data...
client Loading commit data...
cloudprovider Loading commit data...
controller Loading commit data...
conversion Loading commit data...
credentialprovider Loading commit data...
dns Loading commit data...
fieldpath Loading commit data...
fields Loading commit data...
generated Loading commit data...
genericapiserver Loading commit data...
healthz Loading commit data...
httplog Loading commit data...
hyperkube Loading commit data...
kubectl Loading commit data...
kubelet Loading commit data...
kubemark Loading commit data...
labels Loading commit data...
master Loading commit data...
metrics Loading commit data...
probe Loading commit data...
proxy Loading commit data...
quota Loading commit data...
registry Loading commit data...
routes Loading commit data...
runtime Loading commit data...
security Loading commit data...
securitycontext Loading commit data...
selection Loading commit data...
serviceaccount Loading commit data...
ssh Loading commit data...
storage Loading commit data...
types Loading commit data...
util Loading commit data...
version Loading commit data...
volume Loading commit data...
watch Loading commit data...
OWNERS Loading commit data...