# Maximum number of concurrent requests to accept in a single
# service process, or 0 for no limit.
- MaxConcurrentRequests: 0
+ MaxConcurrentRequests: 64
+
+ # Fraction of MaxConcurrentRequests that can be "log create"
+ # messages at any given time. This is to prevent logging
+ # updates from crowding out more important requests.
+ LogCreateRequestFraction: 0.50
# Maximum number of 64MiB memory buffers per Keepstore server process, or
# 0 for no limit. When this limit is reached, up to
"API.LockBeforeUpdate": false,
"API.KeepServiceRequestTimeout": false,
"API.MaxConcurrentRequests": false,
+ "API.LogCreateRequestFraction": false,
"API.MaxIndexDatabaseRead": false,
"API.MaxItemsPerResponse": true,
"API.MaxKeepBlobBuffers": false,
secureClient *http.Client
insecureClient *http.Client
dbConnector ctrlctx.DBConnector
+ limitLogCreate chan struct{}
}
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
ic.CheckRedirect = neverRedirect
h.insecureClient = &ic
+ logCreateLimit := int(float64(h.Cluster.API.MaxConcurrentRequests) * h.Cluster.API.LogCreateRequestFraction)
+ if logCreateLimit == 0 && h.Cluster.API.LogCreateRequestFraction > 0 {
+ logCreateLimit = 1
+ }
+ if logCreateLimit == 0 {
+ // can't have unlimited size channels, so just make
+ // the buffer size really big.
+ logCreateLimit = 4096
+ }
+ h.limitLogCreate = make(chan struct{}, logCreateLimit)
+
h.proxy = &proxy{
Name: "arvados-controller",
}
return h.proxy.Do(req, urlOut, client)
}
+func (h *Handler) limitLogCreateRequests(w http.ResponseWriter, req *http.Request, next http.Handler) {
+ if req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/logs") {
+ select {
+ case h.limitLogCreate <- struct{}{}:
+ next.ServeHTTP(w, req)
+ <-h.limitLogCreate
+ default:
+ http.Error(w, "Excess log messages", http.StatusServiceUnavailable)
+ }
+ return
+ }
+ next.ServeHTTP(w, req)
+}
+
func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next http.Handler) {
resp, err := h.localClusterRequest(req)
n, err := h.proxy.ForwardResponse(w, resp, err)