File Compression in the Multi-Core Era

Original author: Jeff Atwood
  • Transfer
We did a daily big backup for Stack Overflow , so again I played around a bit with file compression.

Our server has the latest 64-bit version of 7zip (4.64) installed . I believe that a dual-core processor is enough for a desktop system. But with servers everything is simple: the more cores, the more fun! The server has two quad-core processors - only eight cores, so I was a little disappointed to find that neither RAR nor 7zip use more than two cores.

But, even using only two cores for compression, the 7zip algorithm is incredibly efficient, and recently it has become quite fast. I used to recommend using RAR instead of Zip. Given the free, unlike RAR, and the effectiveness of 7zip, now it will be logical to choose it.

Here are a couple of my tests for compressing a 4.76 GB database backup file (I used a server with two quad-core 2.5 GHz Xeon E5420 processors on board):
7zipfastest5 min14 MB / sec973 MB
7zipfast7 min11 MB / sec926 MB
7zipnormal34 min2.5 MB / sec752 MB
7zipmaximum41 min2.0 MB / sec714 MB
7zipultra48 min1.7 MB / sec698 MB
If you think that since 7zip shows good results with compression rates of maximum and ultra, then with ultra-plus the result will be completely unbelievable , I have to disappoint you. There are certain reasons why archiver manufacturers set the default compression ratio to normal. If the compression ratio is reduced, the size of the output archive increases sharply, while an increase in the compression ratio leads to a relatively small decrease in the size of the output archive in exchange for a large increase in the compression time.

Now let's see what happens if I switch 7zip to using bzip2 :
7zip with bzip2 selected

We will compress the same file (4.76 GB) on the same machine:
bzip2fastest2 min36 MB / sec1092 MB
bzip2fast2.5 min29 MB / sec1011 MB
bzip2normal3.5 min22 MB / sec989 MB
bzip2maximum7 min12 MB / sec987 MB
bzip2ultra21 min4 MB / sec986 MB
Why is bzip2 so much faster than 7zip? It's simple:
loading the processor when using 7zip
7zip multithreaded cpu usage
loading the processor when using bzip2
bzip2-multithreaded-cpu-usage.png

Bzip2 uses more than two cores for parallelization. I don’t know how many kernels he can use, but in the drop-down menu 7zip offers no more than sixteen kernels for bzip2. Our server has eight cores, so I chose so many during the test.

Unfortunately, increasing the speed of bzip2 is pointless with a high compression ratio - the difference between normal, maximum, and ultra is a miserable 0.06%. The algorithm perfectly scales in time, but practically does not scale in size of the output file. This is very strange because it is precisely to reduce the size that I would like to spend the time won by parallelization.

But even a minimal reduction in size can make sense, depending on the circumstances:

итоговое время = время сжатия + n * (размер архива / скорость сети + время распаковки)

For example, if you compress a file to send it over the network, n = 1, so the compression time significantly affects the total time. If you want to upload a file on the Internet, n is large, so a large compression time will have little effect on the total time.
After all, slow networks work well with slow but efficient algorithms, while fast networks need fast but possibly less efficient algorithms.

On the other hand, the ability to compress a five-gigabyte file five times in two minutes is impressive. Therefore, the thought of how quickly the 7zip algorithm would work if I rewrote it and parallelized it to work on more than two cores does not leave me.

Also popular now: