Enabling the LZ4 Compression Algorithm for Kafka
Purpose
You can enable the LZ4 compression algorithm of the KSAL for Kafka.
Procedure
Replace the native LZ4 code in the lz4-java repository with the LZ4 code of the KSAL. Kafka uses the KafkaLZ4BlockInputStream and KafkaLZ4BlockOutputStream classes to call lz4-java-1.7.1.jar to enable the LZ4 compression algorithm of the KSAL, thereby improving the Kafka performance when it is using the LZ4 compression format.
Software Requirements
Obtaining Software
Table 2 lists the software packages required for enabling the KSAL LZ4 for Kafka.
|
Name |
Software Package Name |
Release Type |
Description |
How to Obtain |
|---|---|---|---|---|
|
KSAL LZ4 |
master.zip |
Open source |
Improve the performance of the LZ4 algorithm through the KSAL. |
|
|
KZL |
BoostKit-kzl_1.0.0.zip |
Closed source |
Code repository that optimizes LZ4 based on the Kunpeng platform. Hijack compression functions using patches and call KZL to optimize code, thereby improving performance. |
|
|
lz4-java native package |
1.7.1.zip |
Open source |
lz4-Java source code. Pack the KSAL LZ4 into this native package during compilation. |
Configuring the Compilation Environment
- Install OpenJDK.
- Download the installation package.
1wget https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_aarch64_linux_hotspot_8u252b09.tar.gz --no-check-certificate
- 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/
- Configure environment variables.
- Open the profile file.
1vi /etc/profile - 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
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the profile file.
- Make the environment variables take effect.
1source /etc/profile
- Download the installation package.
- Install Ant.
- Download the Ant 1.9.14 installation package.
1wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.14-bin.zip --no-check-certificate
- Decompress the package to the /opt/tools/installed directory.
1 2
unzip apache-ant-1.9.14-bin.zip mv apache-ant-1.9.14 /opt/tools/installed/
- Configure the Ant environment variables.
- Open the profile file.
1vi /etc/profile - Press i to enter the insert mode and configure the following content in the file:
1 2
export ANT_HOME=/opt/tools/installed/apache-ant-1.9.14 export PATH=$ANT_HOME/bin:$PATH
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the profile file.
- Make the environment variables take effect.
1source /etc/profile
- Check whether Ant is installed successfully.
1ant -version
- Download the Ant 1.9.14 installation package.
Compiling the LZ4 Compression Algorithm of the KSAL
- Download the LZ4 compression algorithm of the KSAL and add a patch to LZ4.
- Create an installation directory.
1mkdir -p /opt/lz4
- Download the LZ4 compression algorithm of the KSAL and decompress it.
1 2 3
cd /opt/lz4 wget https://gitee.com/kunpeng_compute/lz4/repository/archive/master.zip --no-check-certificate unzip master.zip

- Delete the original BoostKit-kzl_1.0.0.zip package.
1 2
cd /opt/lz4/lz4-master rm -rf BoostKit-kzl_1.0.0.zip
- Download the new BoostKit-kzl_1.0.0.zip package from Table 2, upload it to the lz4-master directory, and decompress it.
1 2
cd /opt/lz4/lz4-master unzip BoostKit-kzl_1.0.0.zip
- Decompress the lz4-1.9.3.zip package and add the KZL patch to LZ4.
1 2 3 4 5 6
cd /opt/lz4/lz4-master unzip lz4-1.9.3.zip patch -p0 < ./lz4_kzl.patch cp ./kzl.a ./lz4_accelerater.h ./lz4-1.9.3/lib cd lz4-1.9.3/lib ar -x kzl.a

- Create an installation directory.
- Download lz4-java and perform compilation.
- Download and decompress lz4-java.
1 2 3
cd /opt/lz4/ wget https://github.com/lz4/lz4-java/archive/refs/tags/1.7.1.zip --no-check-certificate unzip 1.7.1.zip
- Replace the native lz4 directory with the lz4 directory of KZL.
1 2 3 4
cd /opt/lz4/lz4-java-1.7.1/src rm -rf lz4 cd /opt/lz4/lz4-master cp -r lz4-1.9.3 /opt/lz4/lz4-java-1.7.1/src/lz4
- Modify the build.xml file to compile the .a and .o files into the JAR package.
- Go to the /opt/lz4/lz4-java-1.7.1 directory and open the build.xml file.
1 2
cd /opt/lz4/lz4-java-1.7.1 vim build.xml
- Press i to enter the insert mode and change <fileset dir="${src}/lz4/lib" includes="lz4.c, lz4hc.c, xxhash.c" /> in line 214 to the following content:
1<fileset dir="${src}/lz4/lib" includes="*.c,*.h, *.a,*.o" />
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Go to the /opt/lz4/lz4-java-1.7.1 directory and open the build.xml file.
- Perform compilation.
1 2 3
cd /opt/lz4/lz4-java-1.7.1 ant ivy-bootstrap ant

- Rename the package as lz4-java-1.7.1.jar.
1 2
cd dist mv lz4-java-1.6-SNAPSHOT.jar lz4-java-1.7.1.jar

- Download and decompress lz4-java.
Enabling the LZ4 Compression Algorithm of the KSAL
Replace the native package in the libs directory of Kafka with the previously obtained lz4-java-1.7.1.jar package. Restart Kafka.