This report was written in order to compare the performance of hard drives and RAM disks. I wrote a Bash script for test basic file operations implemented in our package building system. The work illustrates of the possibility to use RAM in order to accelerate the build process.

Hardware and Software specification

  • OS: Red Hat Enterprise Linux Server release 6.0 (Santiago), Linux version 2.6.32-71.el6.x86_64
  • CPU: Intel® Xeon® Processor X5680 (12M Cache, 3.33 GHz, 6.40 GT/s Intel® QPI) x 2
  • Hard drive: Seagate Constellation ES ST3500514NS 500GB 7200 RPM 32MB Cache SATA 3.0Gb/s 3.5" Enterprise Internal Hard Drive -Bare Drive
  • RAM: 4GB DDR3 SDRAM PC3-10600 1333MHz CL9 x72 ECC Registered DIMM Memory - HYNIX HMT151R7TFR4C-H9 x 8

Bash Script Listing

            #!/bin/bash

            function remove_files() {
            local path=$1
            cd $path
            rm -f file*
            }

            function create_files() {
            local path=$1
            local num=$2
            local size=$3

            for ((i = 0; i < $num; ++i)) do
            ( dd bs=$size count=1 if=/dev/zero of=$path/file-$i ) > /dev/null 2>&1
            done
            }

            function verify_files() {
            local path=$1

            ls $path/file-* | xargs md5sum > /dev/null
            }

            function compress_files() {
            local path=$1
            local num=$2
            local speed=$3 # 1 - fastest, 9 - slowest

            for ((i = 0; i < $num; ++i)) do
            gzip -$speed -c $path/file-$i > $path/file-$i-$speed.gz
            done
            }

            path='/work/ram'
            num=40000
            size=$[1024]

            echo "Number of files: "$num
            echo "Size: "$size
            echo "Path: "$path
            echo ""

            start=$(date +%s)
            remove_files $path
            end=$(date +%s)
            diff=$(($end - $start))
            echo "Removing: $diff seconds"

            start=$(date +%s)
            create_files $path $num $size
            end=$(date +%s)
            diff=$(($end - $start))
            echo "Creating: $diff seconds"
            
            start=$(date +%s)
            verify_files $path
            end=$(date +%s)
            diff=$(($end - $start))
            echo "Verifying: $diff seconds"

            start=$(date +%s)
            compress_files $path $num 1
            end=$(date +%s)
            diff=$(($end - $start))
            echo "Compressing (fast): $diff seconds"
            
            start=$(date +%s)
            compress_files $path $num 9
            end=$(date +%s)
            diff=$(($end - $start))
            echo "Compressing (slow): $diff seconds"
          

ResultsThe results are present in seconds

The results of the overall test

RAM Test for 2000 files
Size 1K 10K 100K 1M 10M
Removing 0 0 0 0 0
Creating 4 3 4 8 8
Verifying 0 0 1 4 4
Compressing (fast) 2 3 4 14 14
Compressing (slow) 2 2 5 24 24
Hard Drive Test for 2000 files
Size 1K 10K 100K 1M 10M
Removing 0 0 0 1 6
Creating 3 3 3 20 285
Verifying 0 0 0 25 233
Compressing (fast) 2 2 3 18 215
Compressing (slow) 1 2 4 27 211

Discrete file operations test

RAM Test for files - size 1024 bytes
Number of files 2000 20 000 40 000
Removing 0 0 4
Creating 4 35 100
Verifying 0 0 2
Compressing (fast) 2 32 132
Compressing (slow) 2 39 225
Hard Drive Test for files - size 1024 bytes
Number of files 2000 20 000 40 000
Removing 33 0 1
Creating 2 30 65
Verifying 0 1 2
Compressing (fast) 2 20 54
Compressing (slow) 2 20 55

Conclusion

RAM disk usage is beneficial for files larger than 100 kilobytes. In another case, the speed of hard drive operations is not inferior to speed of operations in memory.