develooper Front page | perl.fwp | Postings from November 2001

perl to measure disk performance

Thread Previous | Thread Next
From:
Lev Selector
Date:
November 25, 2001 17:36
Subject:
perl to measure disk performance
Message ID:
004101c1761a$a26bb700$0300a8c0@levcomp
Hello.

Below I describe a perl script I used to measure disk performance.
My questions:
   1. Any pointers to better solutions ?
   2. What kind of results you are getting on your machines? 
       (Especially if somebody has fast SCSI hard drives).
=======================================

As vendors compete adding MHz-s to the CPUs, 
this alone actually doesn't improve the perceived performance very much. 

Inspired by the article by Eric S. Raymond 
"The Ultimate Linux Box 2001: How to Design Your Dream Machine" 

  - http://www.tuxedo.org/~esr/writings/ultimate-linux-box/ - 

For fun I decided to investigate (using Perl) how much upgrading 
to SCSI will boost the performance.
Searching Google and CPAN didn't give me any Perl scripts 
or modules to measure hard drive performance.
 (Benchmark module is not useful for this purpose).
So I wrote a primitive (and not accurate) script (see below). 
I tested it on my home Windows PC and on Linux Web Server.
Both are running Pentium III 500 MHz, 100MHz bus, 8GB IDE hard drives.
Results of the test below demonstrate that on 
Linux disk operations are ~ 3 times faster. ??

=============================================
On Linux webserver:
=============================================
root@first ~#  disktest.pl 
Start
/files/junk_mytest.txt - 16 sec, 468 MB
/home/junk_mytest.txt - 21 sec, 468 MB
Finished
root@first ~#  disktest.pl 
Start
/files/junk_mytest.txt - 16 sec, 468 MB
/home/junk_mytest.txt - 21 sec, 468 MB
Finished
root@first ~#  

=============================================
On similar computer with Windows 2000 Pro
(Antivirus turned off, 
C drive is low on free disk space, 
C& G are one physical disk, H,I,D - the other):
=============================================
H:\AAA_work\myperl>disktest.pl
Start
G:/junk_mytest.txt - 74 sec, 468 MB
H:/junk_mytest.txt - 32 sec, 468 MB
I:/junk_mytest.txt - 51 sec, 468 MB
C:/junk_mytest.txt - 122 sec, 468 MB
D:/junk_mytest.txt - 39 sec, 468 MB
Finished

H:\AAA_work\myperl>


Here is the script
# -------------------------------------------------------
#!/usr/local/bin/perl

use strict;

my $OS = 'dos'; # set to 'unix' or 'dos'

my @drives = qw(   /files    /home   );  # change to whatever you have
if ($OS ne 'unix') {
  @drives = qw(G: H: I: C: D:);   # change to whatever you have
}
  
my $count = 30000;
my $str = "0123456789ABCDEF" x 1024 . "\n";
my $bytes_in_mb = 1024*1024;

my $drive;
print "Start\n";
for $drive (@drives) { test_drive($drive, $count) }
print "Finished\n";
exit(0);

# ---------------------------------------------
# real work is done here    
# ---------------------------------------------
sub test_drive {
  my $drive = shift;
  my $count = shift;
  my $myfile = $drive . "/junk_mytest.txt";
  print "$myfile - ";
  unlink $myfile if -e $myfile;
  open (OUT, ">$myfile") or die "can't open file $myfile for writing: $!";
  my $t0 = time();
  my $ii=0;
  for $ii (1..$count) {
    print OUT $str;
  }
  my $t1 = time();
  close(OUT);
  printf "%d sec, %d MB\n", $t1-$t0, ${[stat($myfile)]}[7]/$bytes_in_mb;
  unlink $myfile if -e $myfile;
}

# -------------------------------------------------------


Warmest Regards
Lev Selector



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About