Why the speed of reading data from ramdisk is the same as harddisk?

S

sonet

/dev/sda2 49594228 1373972 45660300 3% /usr/local
/dev/ram0 96828 11976 84852 13%
/usr/local/Portal/cache

/usr/local/Portal/tesing (real filesystem)
/usr/local/Portal/cache/testing (ramdisk)

The file size is about 6M.

#--------------------------result-------------------------------
open file on ramdisk:6.60419464111328e-05
write file on ramdisk:0.0180449485778809
close file on ramdisk:4.10079956054688e-05
read data on ramdisk:0.179691076278687
=====================================
open file on disk:0.000105142593383789
write file on disk:0.0202229022979736
close file on disk:4.41074371337891e-05
read data on disk:0.0468909740447998

#---------------------------code--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes();

my $t1=Time::HiRes::gettimeofday;
open(my $HH,">/usr/local/Portal/cache/testing");
print "open file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";

my $str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/cache/testing");
my $a=join('',<$HH>);
close($HH);
print "read data on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
$t1=Time::HiRes::gettimeofday;

print "=====================================\n";

open($HH,">/usr/local/Portal/testing");
print "open file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/testing");
$a=join('',<$HH>);
close($HH);
print "read data on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
 
S

sonet

/dev/sda2 49594228 1373972 45660300 3% /usr/local
/dev/ram0 96828 11976 84852 13%
/usr/local/Portal/cache

/usr/local/Portal/tesing (real filesystem)
/usr/local/Portal/cache/testing (ramdisk)

The file size is about 6M.

#--------------------------result-------------------------------
open file on ramdisk:6.38961791992188e-05
write file on ramdisk:0.0180280208587646
close file on ramdisk:3.91006469726562e-05
read data on ramdisk:0.178893089294434
=====================================
open file on disk:0.000104904174804688
write file on disk:0.0201010704040527
close file on disk:4.50611114501953e-05
read data on disk:0.0465281009674072

#---------------------------code--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes();

my $t1=Time::HiRes::gettimeofday;
open(my $HH,">/usr/local/Portal/cache/testing");
print "open file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";

my $str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/cache/testing");
my $a=join('',<$HH>);
close($HH);
print "read data on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
print "=====================================\n";
$t1=Time::HiRes::gettimeofday;
open($HH,">/usr/local/Portal/testing");
print "open file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/testing");
$a=join('',<$HH>);
close($HH);
print "read data on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
 
D

Dr.Ruud

sonet schreef:
Subject: Why the speed of reading data from ramdisk is the same as
harddisk?

Why not? There is easily more than 1 RAM-buffer involved: many harddisks
have 8 MB RAM aboard, and the OS reads large chunks from the harddisk at
a time, even if you ask only for a single byte.

About writing: many harddisks report 'OK' when the data is available, so
long before the data is physically written to 'the platters'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top