20602: Prioritize interactive (browser) requests.
authorTom Clegg <tom@curii.com>
Wed, 7 Jun 2023 21:13:30 +0000 (17:13 -0400)
committerTom Clegg <tom@curii.com>
Thu, 8 Jun 2023 18:31:39 +0000 (14:31 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/service/cmd.go

index 1073f421dfa915e54dcb38ff9e3a02ecf7107413..026a01ecae8a38d1ab6369fdf654adc6c942eab3 100644 (file)
@@ -10,6 +10,7 @@ import (
        "flag"
        "fmt"
        "io"
+       "math"
        "net"
        "net/http"
        "net/http/httptest"
@@ -158,6 +159,7 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout
                                                                Handler:       handler,
                                                                MaxConcurrent: cluster.API.MaxConcurrentRequests,
                                                                MaxQueue:      cluster.API.MaxQueuedRequests,
+                                                               Priority:      c.requestPriority,
                                                                Registry:      reg}))))))
        srv := &httpserver.Server{
                Server: http.Server{
@@ -254,6 +256,25 @@ func (c *command) requestQueueDumpCheck(cluster *arvados.Cluster, prog string, r
        }
 }
 
+func (c *command) requestPriority(req *http.Request, queued time.Time) int64 {
+       switch {
+       case req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/containers/") && strings.HasSuffix(req.URL.Path, "/lock"):
+               // Return 503 immediately instead of queueing. We want
+               // to send feedback to dispatchcloud ASAP to stop
+               // bringing up new containers.
+               return math.MinInt64
+       case req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/logs"):
+               // "Create log entry" is the most harmless kind of
+               // request to drop.
+               return 0
+       case req.Header.Get("Origin") != "":
+               // Handle interactive requests first.
+               return 2
+       default:
+               return 1
+       }
+}
+
 // If an incoming request's target vhost has an embedded collection
 // UUID or PDH, handle it with hTrue, otherwise handle it with
 // hFalse.