add p2c peak ewma load balancer
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user