mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add unworking speculative load shedding
This commit is contained in:
30
lb/lb.go
30
lb/lb.go
@@ -14,6 +14,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
@@ -201,11 +202,9 @@ func (ch *chProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.URL.Path == "/1/lb/nodes" {
|
if r.URL.Path == "/1/lb/nodes" {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "PUT":
|
case "PUT":
|
||||||
// XXX (reed): addNode
|
|
||||||
ch.addNode(w, r)
|
ch.addNode(w, r)
|
||||||
return
|
return
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
// XXX (reed): removeNode?
|
|
||||||
ch.removeNode(w, r)
|
ch.removeNode(w, r)
|
||||||
return
|
return
|
||||||
case "GET":
|
case "GET":
|
||||||
@@ -214,7 +213,6 @@ func (ch *chProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX (reed): stats?
|
// XXX (reed): stats?
|
||||||
|
|
||||||
// XXX (reed): probably do these on a separate port to avoid conflicts
|
// XXX (reed): probably do these on a separate port to avoid conflicts
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,3 +385,29 @@ func jumpConsistentHash(key uint64, num_buckets int32) int32 {
|
|||||||
}
|
}
|
||||||
return int32(b)
|
return int32(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func besti() string {
|
||||||
|
ch.RLock()
|
||||||
|
defer ch.RUnlock()
|
||||||
|
|
||||||
|
for _, n := range ch.nodes[i:] {
|
||||||
|
load := atomic.LoadInt64(&ch.load[n])
|
||||||
|
|
||||||
|
// TODO flesh out these values with some testing
|
||||||
|
// back off loaded nodes slightly to spread load
|
||||||
|
if load < .7 {
|
||||||
|
return n
|
||||||
|
} else if load > .9 {
|
||||||
|
if rand.Float64() < .6 {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
} else if load > .7 {
|
||||||
|
if rand.Float64() < .8 {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// otherwise loop until we find a sufficiently unloaded node or a lucky coin flip
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("XXX: (reed) need to 503 or try with higher tolerance")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user