Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Why the speed of reading data from ramdisk is the same as harddisk? (http://www.velocityreviews.com/forums/t898435-why-the-speed-of-reading-data-from-ramdisk-is-the-same-as-harddisk.html)

sonet 06-09-2006 07:43 AM

Why the speed of reading data from ramdisk is the same as harddisk?
 
/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='';




sonet 06-09-2006 07:54 AM

Why the speed of reading data from ramdisk is slower than harddisk?
 
/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='';






Dr.Ruud 06-09-2006 10:20 AM

Re: [OT] Why the speed of reading data from ramdisk is the same as harddisk?
 
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'.

--
Affijn, Ruud

"Gewoon is een tijger."




All times are GMT. The time now is 07:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.