serving icon indicating copy to clipboard operation
serving copied to clipboard

Requests are failing with 503s when scale from 0 to N

Open vvraskin opened this issue 7 years ago • 4 comments

Expected Behavior

When there are no running pods and a burst of say 1K requests comes in - all requests respond with 200.

Actual Behavior

A big portion of the requests responds with 503

Steps to Reproduce the Problem

  1. Deploy Knative with istio-sidecar proxy
  2. Deploy a hello-world service
  3. Wait until there are no pods running
  4. Start 1K concurrent requests against the service
  5. Observe 503 responses

Additional Info

The problem might sound similar to https://github.com/knative/serving/issues/1846 and https://github.com/knative/serving/issues/1409, but this time the 503s are not coming from the Activator. I see that istio-ingress gateway is failing after 3 retries received from the istio-sidecar proxy of the activator. According to the logs the sidecar is also returning a 503 with the UF: Upstream connection failure in addition to 503 response code.. Digging deeper into envoy proxy (backing the istio sidecar) I collected these metrics:

cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.external.upstream_rq_503: 8
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.external.upstream_rq_5xx: 8
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.external.upstream_rq_completed: 8
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.internal.upstream_rq_200: 197
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.internal.upstream_rq_2xx: 197
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.internal.upstream_rq_503: 435
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.internal.upstream_rq_5xx: 435
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.internal.upstream_rq_completed: 632
100  7cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.membership_change: 1
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.membership_healthy: 1
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.membership_total: 1
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_active: 357
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_connect_fail: 272
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_connect_timeout: 272
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_destroy_local_with_active_rq: 291
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_destroy_with_active_rq: 291
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_http1_total: 920
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_rx_bytes_buffered: 37012
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_rx_bytes_total: 37380
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_total: 920
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_cx_tx_bytes_total: 240840
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_200: 197
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_2xx: 197
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_503: 443
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_5xx: 443
1cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_completed: 640
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_pending_failure_eject: 435
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_pending_total: 920
cluster.inbound|80||activator-service.knative-serving.svc.cluster.local.upstream_rq_total: 931

The interesting ones could be these:

upstream_cx_total: 920
upstream_cx_connect_timeout: 272
upstream_rq_pending_failure_eject: 435

It looks like there is not enough connections that get opened (I would have expected 1K instead of 920) and envoy gets connect timeouts. The timeout is set 1s - so it seems like the it takes longer then that to establish that many connections. Need to verify this assumption.

vvraskin avatar Jan 24 '19 15:01 vvraskin

@vvraskin Does this happen if you send a lower number of requests (like 500)?

tcnghia avatar Jan 25 '19 00:01 tcnghia

I suspect we may be hitting the maximum connection setting here https://istio.io/docs/reference/config/istio.networking.v1alpha3/#ConnectionPoolSettings-HTTPSettings

For activator we may have to increase this value, or probably add a more aggressive HPA to activator so it scales up quickly to avoid hitting the max connections.

tcnghia avatar Jan 25 '19 00:01 tcnghia

I was testing with 400 connections - it was fine.

Had a similar idea that we might be hitting the connection limit. But the number of connections never reaches it (we are by default on 1K connections per envoy proxy), and also when the limit is hit - the metric upstream_cx_overflow should be emitted - which doesn't happen.

vvraskin avatar Jan 25 '19 08:01 vvraskin

Modulo the number of requests in the burst, this should be in scope for "Serving v1".

I think what's important for "v1" is knowing what our limit is, and documenting it.

We will continue to push this number up for the indefinite future :)

mattmoor avatar Jan 28 '19 19:01 mattmoor