Monday, May 9, 2011

File Compression

Why you need to compress file, simple and single requirement is reduce file size. Save disk space.
When to compress, No need to be genius simply every day we compress files. It will reduce bandwidth usage during file transfer. And importantly it will save space on backup storage devices on production systems. So that makes backup stay for long period of time, before it overwrites by recent backup files.
Which method to use, simply on windows I use Winrar or Winzip. In Linux it is Tar or Gunzip. It is something to think about?
Well, I thought it is not be serious problem.
Then sometime back I compare the different methods.
Server I used is 6GB Ram with 4 Dual-Core AMD Opteron processors running rhel4.7.

Bzip2

Compressed file is a text file.
Average CPU usage is 90-99% during compression. But sometimes CPU usage exceed 100% also
Memory usage is around 1%
Original text file size 1135782806
Bunzip2 file size 30722634
Size reduction 1105060172(bytes). Reduction percentage 97.29%
Time elapsed - 528 sec

Gzip

It’s the same text file.
Average CPU usage is less than 1%.
Memory usage is very low. Less than 1%
Original text file size 1135782806
Gzip file size 51512452.
Size reduction is 1084270354. As a percentage 95.46%
Time elapsed 23 seconds.

Tar.gz

This is what I commonly used for archive and compress. So I want to know how efficient it is.
Average CPU usage is less than 1%.
Memory usage is very low. Less than 1%
Original text file size 1135782806
File size reduction 1135782806 --> 51512524. Ratio is 95.46%
Time taken is 23 seconds.

Zip

CPU usage is 90-100%. Memory usage is very low. Around 0.1%
File reduction was 1135782806 --> 51512601. Ratio is 95.46
Time taken was 27 seconds

Compression type you need is really depending with the requirement. If you have separate backup server, only have few script to run and if you don’t mind the CPU usage during file compression bzip2 is your choice. It will reduce file size to minimum. But remember it will eat up your CPU. Also need much more time.

For me gzip full fill my requirements. Compression ratio is less than bzip2 but not harm on CPU usage. So I can use it with production servers. And I do have lot of scripts on my crontab so the time need for compression is also important for me. Tar.gz also which I was currently using do the same. So basically I don’t need to change my backup scripts.

But whenever I need to do a file transfer I will prefer bzip, cause it is reduce the file size significantly when you compare with gzip.


So end of the day it always gonna be you to decide.

No comments:

Post a Comment