mirror of https://github.com/milvus-io/milvus.git
Cherry-pick from master pr: #41211 The restful API default timeout was hard-coded. This PR make this timeout value configurable via paramtable. --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/41258/head
parent
89a1159ed5
commit
b073112e16
|
@ -17,8 +17,6 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/metric"
|
||||
)
|
||||
|
||||
|
@ -120,7 +118,6 @@ const (
|
|||
HTTPHeaderAllowInt64 = "Accept-Type-Allow-Int64"
|
||||
HTTPHeaderDBName = "DB-Name"
|
||||
HTTPHeaderRequestTimeout = "Request-Timeout"
|
||||
HTTPDefaultTimeout = 30 * time.Second
|
||||
HTTPReturnCode = "code"
|
||||
HTTPReturnMessage = "message"
|
||||
HTTPReturnData = "data"
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
mhttp "github.com/milvus-io/milvus/internal/http"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/merr"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
|
||||
)
|
||||
|
||||
func defaultResponse(c *gin.Context) {
|
||||
|
@ -58,7 +59,6 @@ func (p *BufferPool) Put(buf *bytes.Buffer) {
|
|||
|
||||
// Timeout struct
|
||||
type Timeout struct {
|
||||
timeout time.Duration
|
||||
handler gin.HandlerFunc
|
||||
response gin.HandlerFunc
|
||||
}
|
||||
|
@ -154,7 +154,6 @@ func checkWriteHeaderCode(code int) {
|
|||
|
||||
func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc {
|
||||
t := &Timeout{
|
||||
timeout: mhttp.HTTPDefaultTimeout,
|
||||
handler: handler,
|
||||
response: defaultResponse,
|
||||
}
|
||||
|
@ -164,9 +163,10 @@ func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc {
|
|||
defer cancel()
|
||||
gCtx.Request = gCtx.Request.WithContext(topCtx)
|
||||
|
||||
timeout := paramtable.Get().HTTPCfg.RequestTimeoutMs.GetAsDuration(time.Millisecond)
|
||||
timeoutSecond, err := strconv.ParseInt(gCtx.Request.Header.Get(mhttp.HTTPHeaderRequestTimeout), 10, 64)
|
||||
if err == nil {
|
||||
t.timeout = time.Duration(timeoutSecond) * time.Second
|
||||
timeout = time.Duration(timeoutSecond) * time.Second
|
||||
}
|
||||
finish := make(chan struct{}, 1)
|
||||
panicChan := make(chan interface{}, 1)
|
||||
|
@ -209,7 +209,7 @@ func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc {
|
|||
tw.FreeBuffer()
|
||||
bufPool.Put(buffer)
|
||||
|
||||
case <-time.After(t.timeout):
|
||||
case <-time.After(timeout):
|
||||
gCtx.Abort()
|
||||
tw.mu.Lock()
|
||||
defer tw.mu.Unlock()
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPHeaderAllowInt64 = "Accept-Type-Allow-Int64"
|
||||
HTTPHeaderRequestTimeout = "Request-Timeout"
|
||||
HTTPDefaultTimeout = 30 * time.Second
|
||||
HTTPReturnCode = "code"
|
||||
HTTPReturnMessage = "message"
|
||||
HTTPReturnData = "data"
|
||||
|
|
|
@ -22,7 +22,7 @@ type httpConfig struct {
|
|||
Port ParamItem `refreshable:"false"`
|
||||
AcceptTypeAllowInt64 ParamItem `refreshable:"true"`
|
||||
EnablePprof ParamItem `refreshable:"false"`
|
||||
RequestTimeoutMs ParamItem `refreshable:"false"`
|
||||
RequestTimeoutMs ParamItem `refreshable:"true"`
|
||||
}
|
||||
|
||||
func (p *httpConfig) init(base *BaseTable) {
|
||||
|
@ -71,4 +71,13 @@ func (p *httpConfig) init(base *BaseTable) {
|
|||
Export: true,
|
||||
}
|
||||
p.EnablePprof.Init(base.mgr)
|
||||
|
||||
p.RequestTimeoutMs = ParamItem{
|
||||
Key: "proxy.http.requestTimeoutMs",
|
||||
DefaultValue: "30000",
|
||||
Version: "2.5.10",
|
||||
Doc: "default restful request timeout duration in milliseconds",
|
||||
Export: false,
|
||||
}
|
||||
p.RequestTimeoutMs.Init(base.mgr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue