Help Center/ Cloud Container Engine/ Best Practices/ Networking/ Increasing the Listening Queue Length by Configuring Container Kernel Parameters
Updated on 2024-07-04 GMT+08:00

Increasing the Listening Queue Length by Configuring Container Kernel Parameters

Application Scenarios

By default, the listening queue (backlog) length of net.core.somaxconn is set to 128. If the number of connection requests surpasses this limit during busy services, new requests will be declined. To avoid this issue, you can adjust the kernel parameter net.core.somaxconn to increase the length of the listening queue.

Procedure

  1. Modify kubelet configuration in the target node pool (only for clusters of v1.15 or later).

    1. Log in to the CCE console and click the cluster name to access the cluster console.
    2. Locate the row containing the target node pool and choose More > Manage.
      Figure 1 Managing node pool configuration
    3. Modify kubelet configuration parameters and add [net.core.somaxconn] to Allowed unsafe sysctls.
      Figure 2 Modifying kubelet parameters

  2. Create a workload, set kernel parameters, and configure the affinity with the node in 1.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        description: ''
      labels:
        appgroup: ''
      name: test1
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: test1
      template:
        metadata:
          annotations:
            metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"","path":"","port":"","names":""}]'
          labels:
            app: test1
        spec:
          containers:
            - image: 'nginx:1.14-alpine-perl'
              name: container-0
              resources:
                requests:
                  cpu: 250m
                  memory: 512Mi
                limits:
                  cpu: 250m
                  memory: 512Mi
          imagePullSecrets:
            - name: default-secret
          securityContext:
            sysctls:
              - name: net.core.somaxconn
                value: '3000'
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: kubernetes.io/hostname
                        operator: In
                        values:
                          - 192.168.x.x       # Node name.

  3. Go to the container and check whether the parameter settings take effect.

    kubectl exec -it <pod name> -- /bin/sh

    Run the following command in the container to check whether the configuration takes effect:

    sysctl -a |grep somax
    Figure 3 Viewing the parameter configuration