Using zstd for Fast and Efficient Compression on OpenShift

When you need to archive files directly on an OpenShift node, zstd is a great choice because it is already available on the system and provides an excellent balance of compression ratio and performance.

Access the Target Node

Start by opening a remote shell to the node:

oc rsh node/<node-target>

Maximum Compression

To prioritize the smallest archive size, use the ultra compression level (-22) with all available CPU threads:

time tar -I 'zstd -T0 --ultra -22' -cf /tmp/archive.tar.zst /tmp/random_100m.dat

Example result:

real    0m30.007s
user    0m29.346s
sys     0m0.384s

Maximum Compression with a Single Thread

If you want to limit CPU usage, run the same compression level with a single thread:

time tar -I 'zstd -T1 --ultra -22' -cf /tmp/archive.tar.zst /tmp/random_100m.dat

Example result:

real    0m30.677s
user    0m30.322s
sys     0m0.275s

The runtime is similar, making this a viable option when CPU resources are constrained.

Fast Throughput Compression

For large files where speed is more important than archive size, use a lower compression level:

time tar -I 'zstd -T0 -1' -cf /tmp/archive.tar.zst /var/log/random_1000m.dat

Example result:

real    0m18.716s
user    0m14.327s
sys     0m16.420s

Fast Compression with One Thread

You can further reduce CPU consumption by limiting compression to a single thread:

time tar -I 'zstd -T1 -1' -cf /tmp/archive.tar.zst /var/log/random_1000m.dat

Example result:

real    0m19.121s
user    0m13.434s
sys     0m14.402s

Key Takeaways

  • Use --ultra -22 when achieving the highest compression ratio is the primary goal.
  • Use -1 for the fastest archive creation and best throughput.
  • -T0 allows zstd to use all available CPU threads.
  • -T1 limits compression to a single thread and can be useful on busy systems.
  • In these examples, single-threaded and multi-threaded runs showed only minor differences in elapsed time, making thread selection largely a resource-management decision.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *