1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-07 23:32:55 +02:00

IMGPROXY_REQUESTS_QUEUE_SIZE config

This commit is contained in:
DarthSim
2022-07-20 19:46:21 +06:00
parent 526724105e
commit 9081fd5766
3 changed files with 30 additions and 9 deletions

View File

@@ -29,12 +29,17 @@ import (
)
var (
queueSem *semaphore.Semaphore
processingSem *semaphore.Semaphore
headerVaryValue string
)
func initProcessingHandler() {
if config.RequestsQueueSize > 0 {
queueSem = semaphore.New(config.RequestsQueueSize + config.Concurrency)
}
processingSem = semaphore.New(config.Concurrency)
vary := make([]string, 0)
@@ -176,6 +181,14 @@ func checkErr(ctx context.Context, errType string, err error) {
func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if queueSem != nil {
token, aquired := queueSem.TryAquire()
if !aquired {
panic(ierrors.New(429, "Too many requests", "Too many requests"))
}
defer token.Release()
}
path := r.RequestURI
if queryStart := strings.IndexByte(path, '?'); queryStart >= 0 {
path = path[:queryStart]