Why doesn't my RAMDisk performance match my HDD's performance?
I've been thinking about using temporary GIT repositories on RAMDisks (using DataRAM's ramdisk) as a kind of object store. I was interested to see whether it was worthwhile, so I ran a simple benchmark of writing 1000 x 30K files to the drive, and then compared the average write times. I was surprised when the performance came out consistently in favour of the HDD.
For the HDD I got:
average: 0.47ms/write
For the RAM disk I got:
average: 0.76ms/write
Can anyone explain why this is the opposite of what's expected?
Solution 1:
When using DMA, the CPU copies the data into memory and tells the harddrive to get it and write it to disk. While the harddrive does this, the CPU can do something else. With 30K files, the harddrive can keep up with reading and writing. Those files fit in the cache and do not have to be written to disk for writing to be completed. The spinning of the disk and seeking with the arm is the really limiting factor.
I don't know how the ramdisk is implemented, but it may have the CPU do the copying twice.
Solution 2:
Maybe the HDD operations have been cached in memory by your friendly OS and the RAMDisk was (partially) on virtual RAM / swap space?
Solution 3:
This is a hard question to answer, but in general you should understand that artificial benchmarks are rarely reliable. You should try testing actual git repositories.
My guess is that writing files to disk is "fast" because the CPU just issues a command to the drive "take this block of memory and write it to this section of the drive" and the drive processes it asynchronously (i.e. once the command is issued, the operation is "complete"). But copying to a RAM disk, you actually wait until the data is physically copied and since you're basically doing a RAM-to-RAM copy, you've got contention.
Again, I would suggest you try actual operations on actual Git repositories, if that's what you're planning to use it for.
Solution 4:
i think the problem here not in kernel<>mem speed but realisation of dataram software. for unixes there is tmpfs for ages suited for such purposes (and there is no need in additional second filesystem layer), however dataram product rather old unmodified software with (possible) bugs or using old non-optimized program architecture.
Im also got performance hit when try to run game client from dataram ramdisk actually speed was worse than running from IDE drive... it even BSOD on some moments (12gb RAM total 2.5gb ramdisk). with 4gb ramdisk performace worse (???).
With same system FreeBSD without problems handling 4gb+ filled tmpfs
however also has been noted by ImDisk author on forums that windows doing something weird in memory management regarding all ramdisks so possibly there also windows subsystems drawbacks