1 Star 0 Fork 0

openfaiss/faiss

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scaling.go 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
openfaiss 提交于 2023-10-25 22:06 +08:00 . first commit
// Copyright (c) OpenFaaS Author(s). All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package handlers
import (
"fmt"
"log"
"net/http"
"gitee.com/openfaiss/faiss/gateway/pkg/middleware"
"gitee.com/openfaiss/faiss/gateway/scaling"
)
// MakeScalingHandler creates handler which can scale a function from
// zero to N replica(s). After scaling the next http.HandlerFunc will
// be called. If the function is not ready after the configured
// amount of attempts / queries then next will not be invoked and a status
// will be returned to the client.
func MakeScalingHandler(next http.HandlerFunc, scaler scaling.FunctionScaler, config scaling.ScalingConfig, defaultNamespace string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
functionName, namespace := middleware.GetNamespace(defaultNamespace, middleware.GetServiceName(r.URL.String()))
res := scaler.Scale(functionName, namespace)
if !res.Found {
errStr := fmt.Sprintf("error finding function %s.%s: %s", functionName, namespace, res.Error.Error())
log.Printf("Scaling: %s\n", errStr)
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(errStr))
return
}
if res.Error != nil {
errStr := fmt.Sprintf("error finding function %s.%s: %s", functionName, namespace, res.Error.Error())
log.Printf("Scaling: %s\n", errStr)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errStr))
return
}
if res.Available {
next.ServeHTTP(w, r)
return
}
log.Printf("[Scale] function=%s.%s 0=>N timed-out after %.4fs\n",
functionName, namespace, res.Duration.Seconds())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openfaiss/faiss.git
git@gitee.com:openfaiss/faiss.git
openfaiss
faiss
faiss
741517bdd2c0

搜索帮助