Make the proxy to report the number of clients to the broker

So the assignment of proxies is based on the load. The number of clients
is ronded down to 8. Existing proxies that doesn't report the number
of clients will be distributed equaly to new proxies until they get 8
clients, that is okish as the existing proxies do have a maximum
capacity of 10.

Fixes #40048
This commit is contained in:
meskio 2021-06-25 13:47:47 +02:00
parent 74bdb85b30
commit 7a1857c42f
No known key found for this signature in database
GPG key ID: 52B8F5AC97A2DA86
9 changed files with 165 additions and 77 deletions

28
proxy/tokens_test.go Normal file
View file

@ -0,0 +1,28 @@
package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestTokens(t *testing.T) {
Convey("Tokens", t, func() {
tokens := newTokens(2)
So(tokens.count(), ShouldEqual, 0)
tokens.get()
So(tokens.count(), ShouldEqual, 1)
tokens.ret()
So(tokens.count(), ShouldEqual, 0)
})
Convey("Tokens capacity 0", t, func() {
tokens := newTokens(0)
So(tokens.count(), ShouldEqual, 0)
for i := 0; i < 20; i++ {
tokens.get()
}
So(tokens.count(), ShouldEqual, 20)
tokens.ret()
So(tokens.count(), ShouldEqual, 19)
})
}