Rate This Document
Findability
Accuracy
Completeness
Readability

Enabling the CRC32 Acceleration Algorithm for Kafka

Purpose

This section describes how to enable the Kunpeng BoostKit SDS KSAL CRC32 acceleration algorithm for Kafka 2.5.0. You can also refer to this section for other Kafka versions. The acceleration algorithm accelerates the CRC32 algorithm processing performance during Kafka network transmission and improves the end-to-end performance.

Procedure

Apply the function code patch to open source Kafka (deeply customize the Kafka check patch for closed-source version and perform modifications), and modify the Kafka compilation script. Kafka components use CRC32C to determine the factory class of CRC32C. In its static code block, a branch is added for Arm-based machines, and JNI is used to call the Kunpeng Storage Acceleration Library (KSAL) to enable CRC32C.

Software Requirements

Table 1 Software requirements

Item

Supported Version

Java

OpenJDK

OS

openEuler 22.03 LTS SP3

Kafka

1.0.0-3.8.0

Gradle

6.1.1

Obtaining Software

Table 2 lists the software packages required for enabling the Kunpeng BoostKit SDS KSAL CRC32 for Kafka.

Table 2 Software packages required for enabling the KSAL CRC32 for Kafka

Name

Software Package Name

Release Type

Description

How to Obtain

Kunpeng Storage Acceleration Library (KSAL)

BoostKit-KSAL_1.6.0.zip

Closed source

A Huawei-developed storage algorithm library that uses algorithms optimized based on Kunpeng instead of mainstream open source algorithms to improve storage performance. It contains the Erasure Code (EC), Cyclic Redundancy Check 16 T10 Data Integrity Field (CRC16 T10DIF), and Cyclic Redundancy Check 32 (CRC32C) algorithms.

Link

Kafka patch of KSAL

ksal-crc32-code.patch

Open source

Patch that integrates KSAL, to be used during Kafka compilation

Link

Configuring the Compilation Environment

  1. Install OpenJDK.
    1. Download the installation package.
      1
      wget https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_aarch64_linux_hotspot_8u252b09.tar.gz --no-check-certificate
      
    2. Decompress the package to the /opt/tools/installed directory.
      1
      2
      3
      tar -zxf OpenJDK8U-jdk_aarch64_linux_hotspot_8u252b09.tar.gz
      mkdir -p /opt/tools/installed/
      mv jdk8u252-b09 /opt/tools/installed/
      
    3. Configure environment variables.
      1. Open the profile file.
        1
        vi /etc/profile
        
      2. Press i to enter the insert mode and configure the following content in the file:
        1
        2
        export JAVA_HOME=/opt/tools/installed/jdk8u252-b09
        export PATH=$JAVA_HOME/bin:$PATH
        
      3. Press Esc, type :wq!, and press Enter to save the file and exit.
    4. Make the environment variables take effect.
      1
      source /etc/profile
      
    5. Check whether OpenJDK is installed successfully.
      If the JDK version is "1.8.0_252" as displayed, the installation is successful.
      1
      java -version
      

  2. Install Gradle.
    1. Download the Gradle installation package.
      1
      wget https://services.gradle.org/distributions/gradle-6.1.1-bin.zip --no-check-certificate
      
    2. Decompress the package to the /opt/tools/installed directory.
      1
      2
      unzip gradle-6.1.1-bin.zip
      mv gradle-6.1.1 /opt/tools/installed/
      
    3. Configure environment variables for Gradle.
      1. Open the profile file.
        1
        vi /etc/profile
        
      2. Press i to enter the insert mode and configure the following content in the file:
        1
        2
        export GRADLE_HOME=/opt/tools/installed/gradle-6.1.1
        export PATH=$GRADLE_HOME/bin:$PATH
        
      3. Press Esc, type :wq!, and press Enter to save the file and exit.
    4. Make the environment variables take effect.
      1
      source /etc/profile
      
    5. Check whether Gradle is installed successfully.
      1
      gradle -version
      

  3. Install KSAL.
    1. Download the KSAL binary package.
      1
      wget https://kunpeng-repo.obs.cn-north-4.myhuaweicloud.com/Kunpeng%20BoostKit/Kunpeng%20BoostKit%2024.0.RC2/BoostKit-KSAL_1.6.0.zip --no-check-certificate
      
    2. Install KSAL.
      1
      2
      unzip BoostKit-KSAL_1.6.0.zip
      rpm -ivh libksal-release-1.6.0.oe1.aarch64.rpm
      
    3. Check whether the installation is successful.
      If the KSAL SO packages exist in the directory, the installation is successful. See the following figure.
      1
      ll /lib64/*ksal*
      

Compiling Kafka

  1. Download the patch that is to enable the KSAL CRC32 for Kafka.
    1. Create an installation directory.
      1
      mkdir -p /opt/crc32
      
    2. Download the CRC32 acceleration algorithm of the KSAL and decompress it.
      1
      2
      3
      cd /opt/crc32 
      wget https://gitee.com/kunpengcompute/boostkit-bigdata/repository/archive/main.zip --no-check-certificate 
      unzip main.zip
      

  2. Download Kafka, use the patch, and compile Kafka.
    1. Download and decompress Kafka.
      1
      2
      3
      cd /opt/crc32 
      wget https://github.com/apache/kafka/archive/refs/tags/2.5.0.zip --no-check-certificate 
      unzip 2.5.0.zip
      
    2. Use the patch that integrates KSAL.
      1
      2
      cd kafka-2.5.0
      git apply /opt/crc32/boostkit-bigdata-main/kafka/ksal-crc32-code.patch
      
    3. Modify the Gradle compilation script.
      Use the patch to modify build.gradle for open source Kafka 2.5.0.
      1
      git apply /opt/crc32/boostkit-bigdata-main/kafka/ksal-crc32-build-code.patch
      
      • For other Kafka versions, modify the compilation script file as follows:
        1. Open build.gradle.
          1
          vi build.gradle
          
        2. Locate the corresponding lines to be modified using /project(':clients') {.
        3. Press i to enter the insert mode and add the following content to the project(':clients') module in the file:
          1
          2
          3
          4
          5
          6
          7
          task compileCrcJNI(type:Exec) {
              def javaHome = System.getenv('JAVA_HOME')
              commandLine 'gcc', '-fPIC', '-I', javaHome + '/include', '-I', javaHome + '/include/linux',
                      '-shared', '-o', 'src/main/resources/libNativeCrc32C.so',
                      'src/main/native/org/apache/kafka/common/utils/KsalCrc32C.c', '-lksal'
          } 
          compileJava.dependsOn 'compileCrcJNI'
          
        4. Press Esc, type :wq!, and press Enter to save the file and exit.
      • In Kafka 2.7.2, an error is reported indicating that the code is incompatible when the native Scala version is compiled. You need to modify the Scala in the gradle.properties file to an earlier version, for example, 2.12.10 (recommended).
    4. Perform compilation.
      1
      gradle -g /$USER_HOME/gradleRepository releaseTarGz -info
      

    5. Obtain the Kafka binary package kafka_2.12-2.5.0.tgz.
      1
      ll core/build/distributions/
      

Enabling the CRC32 Acceleration Algorithm

  1. Decompress the Kafka binary package.
    1
    tar -zxvf core/build/distributions/kafka_2.12-2.5.0.tgz -C /usr/local
    
  2. Start ZooKeeper and Kafka.
    1
    2
    3
    cd /usr/local/kafka_2.12-2.5.0
    bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
    bin/kafka-server-start.sh -daemon config/server.properties
    
  3. Create a topic.
    1
    bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 70 --topic test
    
  4. Send a message.
    1
    2
    bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
    randomtest
    

    This script is provided by Kafka and is used to send messages to a specified Kafka topic.

    • bootstrap-server indicates the IP address and port number of the Kafka broker.
    • topic indicates the topic to which data is written.

    After performing this operation, you can enter any message and press Enter to send the message. To abort, press Ctrl + C to exit.

  5. Stop sending the message and check Kafka logs. If KSAL-related logs are generated, the deployment takes effect.
    1
    cat logs/server.log | grep KSAL