add p2c peak ewma load balancer

This commit is contained in:
kevin
2020-08-06 20:55:38 +08:00
parent c7544d0e60
commit 63583d4744
24 changed files with 304 additions and 282 deletions

View File

@@ -18,20 +18,13 @@ import (
func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
logger := executors.NewLessExecutor(time.Second)
return func(w http.ResponseWriter, r *http.Request) {
var resp types.Response
conn, ok := ctx.Client.Next()
if !ok {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
host, err := os.Hostname()
if err != nil {
http.Error(w, http.StatusText(http.StatusNotImplemented), http.StatusNotImplemented)
return
}
conn := ctx.Client.Conn()
client := graceful.NewGraceServiceClient(conn)
rp, err := client.Grace(context.Background(), &graceful.Request{From: host})
if err != nil {
@@ -40,6 +33,7 @@ func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return
}
var resp types.Response
resp.Host = rp.Host
logger.DoOrDiscard(func() {
fmt.Printf("%s from host: %s\n", time.Now().Format("15:04:05"), rp.Host)