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

Discussion in 'Perl Misc' started by sonet, Jun 9, 2006.

  1. sonet

    sonet Guest

    /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, Jun 9, 2006
    #1
    1. Advertising

  2. sonet

    sonet Guest

    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='';
    sonet, Jun 9, 2006
    #2
    1. Advertising

  3. sonet

    Dr.Ruud Guest

    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."
    Dr.Ruud, Jun 9, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver

    Some RAMdisk solution?

    Oliver, Oct 29, 2003, in forum: C++
    Replies:
    1
    Views:
    327
    Oliver
    Oct 30, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    7
    Views:
    194
  4. sonet
    Replies:
    0
    Views:
    107
    sonet
    Oct 27, 2005
  5. Bill H

    Perl and a Ramdisk

    Bill H, Nov 30, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    98
    Martijn Lievaart
    Dec 2, 2007
Loading...

Share This Page