J
Jeffrey Ellin
Hi, I am using the following code to get the directory sizes of users
outboxes on our appservers. This code snippet works but it is
dreadfully slow. I have also used File:Find, but it doesn't seem any
faster. Any ideas on how to speed it up? Everything is running on
Win2K.
#sql to get all active users and their last sync date, exclude users
who
#are enddated in the system
$sql = " select n.name,n.APP_SERVER_NAME, max(s.LAST_UPD) as
sync_date " .
" from siebel.s_node n, " .
" siebel.s_extdata_node e, " .
" siebel.s_dock_status s " .
" where n.ROW_ID = s.node_id and " .
" e.NODE_ID = n.ROW_ID and " .
" n.node_type_cd = 'REMOTE' and " .
" s.type = 'SESSION' and " .
" local_flg = 'N' and " .
" e.ACTIVE_FLG = 'Y' and " .
" (n.EFF_END_DT > sysdate or n.EFF_END_DT is null)" .
" group by n.name, n.APP_SERVER_NAME " .
" order by sync_date " ;
#execute sql
$sth = $dbh->prepare($sql);
$sth->execute;
#delete old report file
unlink 'outboxreport.csv';
#loop through each user in resultset.
while (($node,$server,$sync)=$sth->fetchrow_array()){
#get name of docking directory
my $dockloc = substr($server,6);
#assemble path statement
my $path = "//$server/docking$dockloc/$node/outbox";
#my $path = "//$server/docking/$node/outbox";
#get directory size
my $dirsize = -s $path;
opendir(my ($dh),$path);
#loop through each file in the directory skip over dat and uaf since
they are part of new database
while( defined( my $filename = readdir $dh ) ) {
next if $filename eq "." or $filename eq ".." or $filename
=~ /uaf/ or $filename =~ /dat/;
$dirsize += -s "$path/$filename";
}
#re-open file so it writes as we process
open REP, ">>outboxreport.csv";
#convert file size to megabytes
$dirsize = $dirsize/1000000;
#round file size
$dirsize = sprintf "%.2f", $dirsize;
#print out report in csv format
print REP "$node,$server,$sync,$dirsize\n";
}
outboxes on our appservers. This code snippet works but it is
dreadfully slow. I have also used File:Find, but it doesn't seem any
faster. Any ideas on how to speed it up? Everything is running on
Win2K.
#sql to get all active users and their last sync date, exclude users
who
#are enddated in the system
$sql = " select n.name,n.APP_SERVER_NAME, max(s.LAST_UPD) as
sync_date " .
" from siebel.s_node n, " .
" siebel.s_extdata_node e, " .
" siebel.s_dock_status s " .
" where n.ROW_ID = s.node_id and " .
" e.NODE_ID = n.ROW_ID and " .
" n.node_type_cd = 'REMOTE' and " .
" s.type = 'SESSION' and " .
" local_flg = 'N' and " .
" e.ACTIVE_FLG = 'Y' and " .
" (n.EFF_END_DT > sysdate or n.EFF_END_DT is null)" .
" group by n.name, n.APP_SERVER_NAME " .
" order by sync_date " ;
#execute sql
$sth = $dbh->prepare($sql);
$sth->execute;
#delete old report file
unlink 'outboxreport.csv';
#loop through each user in resultset.
while (($node,$server,$sync)=$sth->fetchrow_array()){
#get name of docking directory
my $dockloc = substr($server,6);
#assemble path statement
my $path = "//$server/docking$dockloc/$node/outbox";
#my $path = "//$server/docking/$node/outbox";
#get directory size
my $dirsize = -s $path;
opendir(my ($dh),$path);
#loop through each file in the directory skip over dat and uaf since
they are part of new database
while( defined( my $filename = readdir $dh ) ) {
next if $filename eq "." or $filename eq ".." or $filename
=~ /uaf/ or $filename =~ /dat/;
$dirsize += -s "$path/$filename";
}
#re-open file so it writes as we process
open REP, ">>outboxreport.csv";
#convert file size to megabytes
$dirsize = $dirsize/1000000;
#round file size
$dirsize = sprintf "%.2f", $dirsize;
#print out report in csv format
print REP "$node,$server,$sync,$dirsize\n";
}