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

Usage Description

The following uses openEuler 24.03 LTS SP3 and 6.6.0-132.0.0.111.oe2403sp3.aarch64 as an example to describe how to enable the HiSock feature to accelerate MySQL. Before installing and using this feature, ensure that MySQL has been deployed. To enable HiSock to accelerate Redis applications, ensure that Redis has been deployed.

  1. Move the commands compiled in step 7 in the "Installation Description" section to a custom path.
    1
    2
    cp samples/bpf/hisock/hisock_cmd <Custom_path>
    cp samples/bpf/hisock/bpf.o <Custom_path>
    
  2. Create an independent HiSock cgroup.
    mkdir -p /sys/fs/cgroup/systemd/hisock

    You are advised to use an independent cgroup to accurately control the effective scope of HiSock and prevent irrelevant processes in the same service or container cgroup from being affected.

  3. Go to the custom path where the commands are stored and load HiSock BPF programs. If "Load HiSock successfully" is displayed, a HiSock BPF program is successfully loaded.
    1
    ./hisock_cmd [-f BPF_FILE] [-c CGRP_PATH] [-p PORT] [-C PROCESS_NAME] [-i INTERFACE]
    

    If a BPF program fails to be loaded and the following error message is displayed, rectify the fault by referring to Troubleshooting.

    Table 1 Parameters

    Parameter

    Description

    Example

    -f BPF_FILE

    Specifies the path to the BPF object file. The default value is bpf.o.

    -f samples/bpf/hisock/bpf.o

    -c CGRP_PATH

    Specifies the cgroup path to which the SockOps and HiSock Egress programs are attached.

    -c /sys/fs/cgroup/systemd/hisock

    -p PORT

    Specifies the port to be accelerated. The value can be a single port, ports separated by commas (,), or a port range.

    -p 3306 or -p 3306-3310

    -C PROCESS_NAME

    Specifies the name of the target listening process. After the process name is matched, the SockOps program automatically learns the local listening port in the listening phase and writes the port to speed_port.

    -C mysqld

    -i INTERFACE

    Specifies the network interface to which the HiSock Ingress program is attached. A maximum of eight interfaces are supported.

    -i enp25s0

    -u

    Uninstalls the HiSock BPF program.

    -u

    -h

    Views the help information.

    -h

    Example 1: Enable HiSock for local port 3306.

    ./hisock_cmd  -f ./bpf.o -c /sys/fs/cgroup/systemd/hisock -p 3306 -i enp25s0

    Example 2: Enable HiSock for multiple local ports.

    ./hisock_cmd  -f ./bpf.o -c /sys/fs/cgroup/systemd/hisock -p 3306,3307 -i enp25s0

    Example 3: Enable HiSock for a range of local ports.

    ./hisock_cmd  -f ./bpf.o -c /sys/fs/cgroup/systemd/hisock -p 3306-3310 -i enp25s0

    Example 4: Set the program to automatically learn the listening port based on the process name and enable HiSock.

    ./hisock_cmd  -f ./bpf.o -c /sys/fs/cgroup/systemd/hisock -C mysqld -i enp25s0

    Example 5: Specify both a fixed port and the target process name.

    ./hisock_cmd  -f ./bpf.o -c /sys/fs/cgroup/systemd/hisock -p 3306 -C mysqld -i enp25s0
    • -p or -C must be configured. If both are specified, both take effect.
    • -c and -C function differently: -c is used to specify the cgroup path, while -C is used to specify the service process name. -C does not automatically add the process to the cgroup. In this case, you need to manually add the process to the cgroup. The common methods for determining the cgroup to which the target process belongs are as follows:
      pidof mysqld
      cat /proc/<pid>/cgroup
    • -C uses the kernel process name (comm) for exact matching. It does not support prefix match, substring match, wildcards, or regular expressions, and is case-sensitive.
      • The matching length of -C is limited by TASK_COMM_LEN, which is currently 16 bytes, including the null terminator \0. Therefore, the maximum length of a process name that can be effectively matched is 15 characters. If the value specified by -C exceeds 15 characters, the tool truncates the value to the first 15 characters and writes the truncated value to the target_comm map. The BPF program also performs exact matching based on the truncated comm value.
      • Before configuring -C, you are advised to confirm the actual comm value by running pgrep -a <name> or ps -eo pid,comm,args | grep <name> or by checking /proc/<pid>/comm.
    • The port number ranges from 1 to 65535. In the example tool, the maximum capacity of the speed_port map is 128. Therefore, the port range should not be too large.
  4. Start the MySQL service process.
    /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf &

    To enable HiSock to accelerate Redis applications, start the Redis service process.

  5. Migrate the target process to the cgroup.
    echo <pid> > /sys/fs/cgroup/systemd/hisock/cgroup.procs
  6. Verify the HiSock status.
    1. View the loaded BPF programs. The command output shows that the following BPF programs have been successfully loaded: hisock_sockops_prog, hisock_skmsg_prog, hisock_ingress_prog, and hisock_egress_prog.
      bpftool prog show | grep -E "hisock|sock_ops|sk_msg" 

    2. View the BPF maps. A correct command output shows the following information: connmap, local_connmap, speed_port, and target_comm.
      bpftool map show | grep -E "connmap|local_connmap|speed_port|target_comm"

    3. Check the acceleration port configuration. If the following information is displayed, the configurations for ports 33060 and 3306 have taken effect.
      bpftool map dump name speed_port

    4. Use the sysbench stress test tool or MySQL to initiate a remote or local service connection and view the connection context. The following uses a local service connection as an example. Related entries are properly displayed in local_connmap.
      bpftool map dump name connmap
      bpftool map dump name local_connmap

      value is a kernel socket reference. The message "No space left on device" is a display restriction/compatibility issue, which is normal.

  7. (Optional) Uninstall the HiSock feature. If "Unload HiSock successfully" is displayed, the HiSock feature is successfully uninstalled.
    1
    ./hisock_cmd -u -c /sys/fs/cgroup/systemd/hisock -i enp25s0