python3 is available when
python is run.
sudo apt install python-is-python3 -y
The previous section explained how to build the Cloudflare
zlib which includes the use of
crc32 instructions to improve performance on data compression.
Use a Python example and measure the performance difference with
Copy and save the file below as
size = 16384
with open('largefile', 'rb') as f_in:
with gzip.open('largefile.gz', 'wb') as f_out:
while (data := f_in.read(size)):
The above Python code will read a file named
largefile and write a compressed version as
To create the input file, use the
dd if=/dev/zero of=largefile count=1M bs=1024
Run with the default
zlib and time the execution.
time python ./zip.py
Make a note of how many seconds the program took.
This time, use
LD_PRELOAD to change to
zlib-cloudflare instead and check the performance difference.
Adjust the path to
libz.so as needed.
time LD_PRELOAD=/usr/local/lib/libz.so python ./zip.py
Notice the time saved using
The next section introduces how to use Linux
perf to profile applications and look for