Recommendations

Give the external PostgreSQL server at least 8 CPU cores and set max_connections to at least 600 (see PostgreSQL).

Web service autoscaling

In the high availability variant, the HorizontalPodAutoscaler of the web service uses two metrics and follows the one that asks for more pods:

  • CPU usage per pod;
  • puma-queued, the average number of requests waiting in the Puma queue of a pod.

Requests start to queue once every Puma worker of a pod is busy. CPU usage of a pod stops growing at about one core per worker, so CPU alone reacts to an overload late.

puma-queued is a custom metric. Kubernetes does not provide it: the HorizontalPodAutoscaler reads it from the custom metrics API (custom.metrics.k8s.io), which a metrics adapter serves. In Deckhouse Kubernetes Platform the adapter is built in. In other clusters, install prometheus-adapter.

Warning. If the API does not serve puma-queued, the HorizontalPodAutoscaler still adds web service pods under CPU load but never removes them, and the web service stays at maxReplicas after the load drops. If the cluster has no metrics adapter, keep only the Resource item in gitlab.webservice.hpa.customMetrics.

To make the metric available:

  1. Make Prometheus scrape the web service metrics, for example with gitlab.webservice.metrics.serviceMonitor.enabled: true or with the objects from Monitoring. The following query must return one series per web service pod:

    count by (pod) (puma_queued_connections{namespace="<namespace>"})
  2. Declare the metric:

    • in Deckhouse Kubernetes Platform, create a PodMetric object in the release namespace:

      apiVersion: deckhouse.io/v1beta1
      kind: PodMetric
      metadata:
        name: puma-queued
        namespace: <namespace>
      spec:
        query: sum by (<<.GroupBy>>) (avg_over_time(puma_queued_connections{<<.LabelMatchers>>}[1m]))
    • in other clusters, install the prometheus-community/prometheus-adapter chart pointed at your Prometheus (prometheus.url, prometheus.port) and add a rule to its values:

      rules:
        custom:
          - seriesQuery: 'puma_queued_connections{namespace!="",pod!=""}'
            resources:
              overrides:
                namespace: {resource: namespace}
                pod: {resource: pod}
            name:
              matches: ^puma_queued_connections$
              as: puma-queued
            metricsQuery: sum by (<<.GroupBy>>) (avg_over_time(<<.Series>>{<<.LabelMatchers>>}[1m]))

      Only one provider can serve custom.metrics.k8s.io in a cluster. If another adapter already serves it, declare the metric in that adapter.

  3. Check that the API returns a value for each web service pod:

    kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/<namespace>/pods/*/puma-queued"

Ingress-nginx

The web service pods get equal shares of requests only when ingress-nginx sends requests straight to the pods. With the annotation nginx.ingress.kubernetes.io/service-upstream: "true" on the web service Ingress, ingress-nginx sends them to the ClusterIP of the Service instead. The cluster then picks a pod once per TCP connection, and ingress-nginx reuses each connection for up to 10000 requests, so the pods added by the HorizontalPodAutoscaler get almost no requests. The high availability values turn the annotation off with gitlab.webservice.ingress.serviceUpstream: false.

If the annotation has to stay on, make ingress-nginx close its connections to the web service sooner. Set the following keys in the ingress-nginx ConfigMap, or in spec.config of the IngressNginxController object in Deckhouse Kubernetes Platform:

upstream-keepalive-requests: "100"
upstream-keepalive-timeout: "10"

New pods then start to get requests within seconds, but the requests are spread less evenly than without the annotation.

Values

Save the chosen variant to a file and pass it to the install command as described in Applying the values.

  • Standalone
  • High availability
global:
  codeHelm:
    loadbalancer:
      resources:
        limits:
          cpu: 1000m
          memory: 512Mi
        requests:
          cpu: 500m
          memory: 256Mi

gitlab:
  webservice:
    workerProcesses: 8
    puma:
      threads:
        min: 8
        max: 8
    resources:
      limits:
        memory: 13G
      requests:
        cpu: 8
        memory: 13G
  sidekiq:
    resources:
      limits:
        memory: 3G
      requests:
        cpu: 1
        memory: 1500Mi
  gitlab-shell:
    resources:
      limits:
        cpu: 500m
        memory: 600Mi
      requests:
        cpu: 32m
        memory: 50Mi
  gitlab-pages:
    resources:
      limits:
        memory: 3G
      requests:
        cpu: 900m
        memory: 1G
  gitaly:
    resources:
      limits:
        cpu: 6000m
        memory: 16000Mi
      requests:
        cpu: 6000m
        memory: 16000Mi
    cgroups:
      memoryBytes: 16777216000
      cpuQuotaUs: 600000
      repositories:
        memoryBytes: 8388608000
        cpuQuotaUs: 300000
  praefect:
    resources:
      limits:
        cpu: 1200m
        memory: 1200Mi
      requests:
        cpu: 500m
global:
  codeHelm:
    loadbalancer:
      replicas: 2
      resources:
        limits:
          cpu: 1000m
          memory: 512Mi
        requests:
          cpu: 500m
          memory: 256Mi
      hpa:
        enabled: true
        minReplicas: 2
        maxReplicas: 3
        cpuUtilization: 80
        memoryUtilization: 80
      pdb:
        enabled: true
  praefect:
    virtualStorages:
      - name: default
        gitalyReplicas: 3
        maxUnavailable: 1

gitlab:
  webservice:
    workerProcesses: 6
    puma:
      threads:
        min: 8
        max: 8
    resources:
      limits:
        memory: 10G
      requests:
        cpu: 6
        memory: 10G
    ingress:
      serviceUpstream: false
    hpa:
      enabled: true
      customMetrics:
        - type: Resource
          resource:
            name: cpu
            target:
              type: AverageValue
              averageValue: 4500m
        - type: Pods
          pods:
            metric:
              name: puma-queued
            target:
              type: AverageValue
              averageValue: "1"
    minReplicas: 2
    maxReplicas: 4
    maxUnavailable: 2
    workhorse:
      resources:
        limits:
          memory: 2Gi
        requests:
          cpu: 500m
          memory: 500M
  sidekiq:
    resources:
      limits:
        memory: 3G
      requests:
        cpu: 1
        memory: 1500Mi
    hpa:
      enabled: true
      cpu:
        targetAverageValue: 700m
    minReplicas: 4
    maxReplicas: 8
    maxUnavailable: 1
  gitlab-shell:
    resources:
      limits:
        cpu: 500m
        memory: 600Mi
      requests:
        cpu: 32m
        memory: 50Mi
    hpa:
      enabled: true
      cpu:
        targetAverageValue: 1600m
    minReplicas: 3
    maxReplicas: 6
    maxUnavailable: 1
  gitlab-pages:
    resources:
      limits:
        memory: 3G
      requests:
        cpu: 900m
        memory: 1G
    hpa:
      enabled: true
      minReplicas: 2
      maxReplicas: 6
      cpu:
        targetAverageValue: 100m
    maxUnavailable: 1
  gitaly:
    resources:
      limits:
        cpu: 6000m
        memory: 16000Mi
      requests:
        cpu: 6000m
        memory: 16000Mi
    cgroups:
      memoryBytes: 16777216000
      cpuQuotaUs: 600000
      repositories:
        memoryBytes: 8388608000
        cpuQuotaUs: 300000
  praefect:
    replicas: 3
    resources:
      limits:
        cpu: 1200m
        memory: 1200Mi
      requests:
        cpu: 500m

registry:
  hpa:
    enabled: true
    minReplicas: 3
    maxReplicas: 5
    cpu:
      targetAverageUtilization: 75
  maxUnavailable: 3

Load test

The high availability variant of this size was tested under a synthetic load for 30 minutes on Deckhouse Code installed as the Deckhouse Platform module. The load followed the request mix of the GitLab reference architecture for up to 3000 users: REST API calls, web interface pages, and Git clone, pull and push over HTTPS and SSH. Git over SSH is left out of the results: the test clients had no SSH access to the instance.

Throughput:

TrafficTarget, RPSMeasured, RPS
REST API6042.5
Web interface64.0
Git clone and pull over HTTPS60.24
Git push over HTTPS1.20.12

Response times and failed requests; a range runs from the fastest to the slowest request of the group:

RequestsMedian95th percentileFailed
REST API0.4–2.5 s1.1–4.7 s1.5%
Web interface pages1.0–3.7 s2.3–6.7 s0.1%
Git clone over HTTPS131 s696 s3.6%
Git pull over HTTPS3.0 s6.1 s0%
Git push over HTTPS5.8 s12 s0%

Failed Git pulls caused by the Git configuration of the test client are not counted. Of the failed REST API requests, 1112 of 1137 were rejected by the rate limit with HTTP 429.

Additional resources