mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 12:36:40 +00:00
Add Concurrency Limiter
This enables limiting concurrency. It is a naive approach which will reject requests as soon as they exceed the maximum number of in-flight requests. It is a port of the following PR from the new watchdog code: https://github.com/openfaas-incubator/of-watchdog/pull/54 Signed-off-by: Sargun Dhillon <sargun@sargun.me> Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
45cf4db4cb
commit
b019f6ca54
@ -17,6 +17,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
limiter "github.com/openfaas/faas-middleware/concurrency-limiter"
|
||||
|
||||
"github.com/openfaas/faas/watchdog/types"
|
||||
)
|
||||
|
||||
@ -294,8 +296,8 @@ func makeHealthHandler() func(http.ResponseWriter, *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeRequestHandler(config *WatchdogConfig) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
func makeRequestHandler(config *WatchdogConfig) http.HandlerFunc {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case
|
||||
http.MethodPost,
|
||||
@ -309,5 +311,6 @@ func makeRequestHandler(config *WatchdogConfig) func(http.ResponseWriter, *http.
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
return limiter.NewConcurrencyLimiter(handler, config.maxInflight).ServeHTTP
|
||||
}
|
||||
|
Reference in New Issue
Block a user