我要评分
获取效率
正确性
完整性
易理解

Configuring NUMA Core Binding for Processes

Purpose

Redis instances can be classified into active instances and standby instances based on the roles of Redis nodes in the cluster. The active nodes process requests, write, read, and update data, periodically synchronize data to the standby Redis nodes, and make data persistent. When an active Redis node is faulty, a standby Redis node takes over services from the active Redis node. In the actual services, the active instances require more CPU and network resources due to their role. Therefore, after the Redis cluster is deployed, perform NUMA core binding for the Redis instances based on the roles of the Redis nodes in the cluster. As the cluster scale varies, you need to adjust the core binding policy to maximize the performance of clusters of different scales.

Procedure

  1. Obtain the node (instance) information of the current cluster by running the following command to log on to the cluster through any node in the cluster:
    1
    redis-cli -h ip_server -p port_server
    

    Modify the following parameters as required:

    • ip_server: IP address of the Redis server
    • port_server: listening port number of the Redis server
  2. Query the information of each node in the current cluster. The following is an example (simplified version). You can obtain the role of each instance in the current cluster by using this method and save the information to a temporary file tmp_nodes_info.log.
    1
    cluster nodes
    

  3. Perform core binding based on the role of an instance. The Redis cluster is a distributed database deployed on multiple physical servers. Therefore, you need to obtain the role information of the Redis instance on each server. Run the following command to obtain the role information of instances that belong to a service IP address from the tmp_nodes_info.log file in batches:
    1
    2
    local_master_ports=(cat tmp_nodes_info.log |grep "master"|awk '{print $2}'|awk -F@ '{print $1}' | grep ip_server | awk -F: '{print $2}')
    local_slave_ports=(cat tmp_nodes_info.log |grep "slave"|awk '{print $2}'|awk -F@ '{print $1}'|grep ip_server | awk -F: '{print $2}')
    

    ip_server: IP address of the Redis server. Change it based on the actual IP address.

  4. Obtain the process IDs (PIDs) of the corresponding process based on the port information in local_master_ports and local_slave_ports, and perform core binding for the corresponding Redis instance based on the PIDs.
    1
    2
    pid=(ps -ef | grep "redis" | grep port | awk '{print $2}')
    taskset -cp destCores pid
    

    Modify the following parameters as required:

    • port: port number of the Redis instance to be bound to a core
    • pid: ID of the process to be bound to a CPU core
    • destCores: CPU cores to be bound