ChrisR has asked for the wisdom of the Perl Monks concerning the following question:
The code works. I know that it's not pretty and my error checking could use some work but that's not the problem. The script process many files per second up to a point and then it begins to take about 5-6 seconds per file. The problem starts at file number 31657 and is OK again after file number 34093. There are over 35000 files to process. What I have found is that it has nothing to do with the number of files processed. I have run this script many times on a few different machines and have found that the problem only occurs in one directory. I have also found that the extra time is consumed when I'm creating the Win32::Perms object ( $file_obj = new Win32::Perms($dirtree[$x])). The directory in question is a shared directory. The administrator, which is running the script, has full controll over the directory. Considering that there are more than 2400 files in this directory, the time it takes to process this directory is well over 3 hours while it takes less than 8 minutes to process the rest of the 350000 files. System resources are not an issue as processor and memory usage are very low while the script processes the directory in question. I just can't figure out why Win32::Perms is so slow on that one directory. Any ideas??#!c:\perl\bin\perl.exe -w use strict; use warnings; use diagnostics; use File::List; use Win32::Perms; my $search2 = new File::List("c:\\"); my @tree2 = @{$search2->find(".*")}; my %ownerhash = GetFilesByUser(@tree2); for my $key(sort keys %ownerhash) { print "$key $ownerhash{$key}{numbytes} bytes in $ownerhash{$key}{n +umfiles} files\n"; } exit; sub GetFilesByUser { my @dirtree = @_; my $file_obj; my $fileowner; my %temphash; for my $x (0..$#dirtree) { $dirtree[$x] =~ s/\//\\/g; $dirtree[$x] =~ s/\\\\/\\/g; $file_obj = new Win32::Perms($dirtree[$x]) || print "ERROR1: $ +!\nFILE: $dirtree[$x]\n"; if(not $file_obj) { $temphash{FILESTHATGOTERRORS}{numfiles} ++; $temphash{FILESTHATGOTERRORS}{numbytes} += -s $dirtree[$x] +; } elsif($file_obj ne "1") { $fileowner = $file_obj->Owner() || print "ERROR2: $!\nFILE +: $dirtree[$x] \n"; $file_obj->Close(); $temphash{$fileowner}{numfiles} ++; if(! -z $dirtree[$x]) #check to see if file is zero bytes { $temphash{$fileowner}{numbytes} += -s $dirtree[$x] || + print "ERROR3: $!\nFILE: $dirtree[$x]\n"; } } } return %temphash; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Another Strange Win32::Perms Issue
by BrowserUk (Patriarch) on Oct 28, 2003 at 21:15 UTC | |
by ChrisR (Hermit) on Oct 28, 2003 at 21:47 UTC | |
by BrowserUk (Patriarch) on Oct 28, 2003 at 21:56 UTC | |
by ChrisR (Hermit) on Oct 28, 2003 at 22:19 UTC | |
|
Re: Another Strange Win32::Perms Issue
by Beechbone (Friar) on Oct 28, 2003 at 21:04 UTC | |
by ChrisR (Hermit) on Oct 28, 2003 at 21:30 UTC |