Performance degradation with KSH93


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Performance degradation with KSH93
# 1  
Old 04-02-2009
Performance degradation with KSH93

Hi,

I have a script that calls an external program to perform some calculations and then I read with "grep" and "sed" values from the output files. I've noticed that performance of KSH93 degrades with every iteration. The output files are all the same size, so I don't understand why after the first calculation it takes 5 seconds to read the values but after the 50th calculation it takes ~1 minute. Besides that, everything is working correctly, no error messages.

I had the same problem a couple of months ago with a simpler script. Back then I just executed the script with KSH88 and the problem was gone (I wasn't using any special features of KSH93).

But this actual script has gotten very complex using lots of KSH93 specific stuff, so I cannot use KSH88 here.

I've searched the internet concerning performance degradation, but found only a hint to a bug with the "unset" command. Well, I was using the "unset" command for some array variables, but even after commenting these lines out, the problem was still there.

Has anyone heard anything about KSH93 getting slower and slower with time?

By the way, I'm on a AIX 5.2 machine.

Thanks, Ingo
# 2  
Old 04-02-2009

Post the script.
# 3  
Old 04-02-2009
I have two output files. First I get some values from the first file, then I calculate values from the second file that are based on the first one. If you're wondering why I have semicolons at the end of each line, it's because the code is being joined in one string and executed by the "eval" command.

This code takes a couple of seconds for the first calculation and after the 50th it takes more than 1 minute, even though the output files are similar to each other in length.

# Timestamp
u_start=`perl -e 'print time()'`;

# Read values from EnvOPT.dat:? file
if [[ -a EnvOPT.dat:$OFP ]]; then
for x in `grep -e "^Contrail_Length " -e "^Contrail_Climate_Impact " -e "^Contrail_ETS_Cost " -e "^CO2_Emissions " -e "^CO2_Climate_Impact " -e "^CO2_ETS_Cost " EnvOPT.dat:$OFP`; do
param=`echo $x | awk '{print $1}'`;
value=`echo $x | awk '{print $3}'`;

case $param in
Contrail_Length) contrail_length="$value"; ;;
Contrail_Climate_Impact) contrail_climate_impact="$value"; ;;
Contrail_ETS_Cost) contrail_ets_cost="$value"; ;;
CO2_Emissions) co2_emissions="$value"; ;;
CO2_Climate_Impact) co2_climate_impact="$value"; ;;
CO2_ETS_Cost) co2_ets_cost="$value"; ;;
esac;
done;

# Edit both files, keep only important lines
sed '/#OFP_DEP_DEST#/,/ROUTING_TEXT/!d' ProfOPT.dat:$OFP | sed -e '1,12d' -e '$d' > ProfOPT.dat:tmp;
sed '/#Section MetPhenomIndices#/,$!d' EnvOPT.dat:$OFP | sed '1,3d' > EnvOPT.dat:tmp;

# Save edited files in array
set -A u_prof $(< ProfOPT.dat:tmp);
set -A u_env $(< EnvOPT.dat:tmp);

v=0;
# Number of lines (equal in both files)
u=${#u_prof[@]};
fuel_night=0;
while (( $v < $((u-1)) )); do
# Get values from first file (column 3)
val1=`echo ${u_env[$v]} | awk '{print $3}'`;
val2=`echo ${u_env[$((v+1))]} | awk '{print $3}'`;
# If values at line "i" and "i+1" equals "0" then...
if (( $val1 == 0 && $val2 == 0 )); then
# Get values from second file
(column 13)
val1=`echo ${u_prof[$v]} | awk '{print $13}'`;
val2=`echo ${u_prof[$((v+1))]} | awk '{print $13}'`;
# Calculate delta fuel and add to total fuel
fuel_night=$((fuel_night+val2-val1));
fi;
((v+=1));
done;
fi;

u_end=`perl -e 'print time()'`;
echo " Elapsed time: $((u_end-u_start)) seconds";

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Ksh93/AIX compatibility

Hi everyone ! Im trying to know from wich version of AIX KSH93 is available ? Internet tell me 6.x and 7.x AIX are available, bue what about 5.x ? Is KSH93 available on AIX 5.x ? Is it the same way to manipulate variables as KSH93 on 7.x ? Thanks for your support and have a nice day ! (2 Replies)
Discussion started by: majinfrede
2 Replies

2. UNIX for Advanced & Expert Users

Ksh93 on Linux compatible with ksh93 on AIX

Hi Experts, I have several shell scripts that have been developed on a Linux box for korn ksh93. If we want to run this software on an AIX 6.1 box that runs ksh88 by default can we just change the she-bang line to reference /bin/ksh93 which ships with AIX as its "enhanced shell" to ensure... (6 Replies)
Discussion started by: Keith Turley
6 Replies

3. Shell Programming and Scripting

Solaris 11 ksh93 if condition issue

Solaris 11 ksh93 if condition issue Has anyone run into issues with Solaris 11 with ksh93 if condition where it intermittently return wrong return code? We did not see this issue in Solaris 10 with ksh88 Any thoughts? Thanks! Solaris version: SunOS t52-ccc-28 5.11 11.2... (4 Replies)
Discussion started by: nugent
4 Replies

4. UNIX for Advanced & Expert Users

Embed tcl in ksh93 script

Hello everyone, I am trying to embed some tcl code inside a ksh93 script but I am not having any success. I even tried the simplest of code, something like this: . . jk=$(echo $(tcl << | write_file junkme "test"' | )) just to see if a file gets written. When I run there are no errors, but ... (3 Replies)
Discussion started by: gio001
3 Replies

5. Shell Programming and Scripting

ksh93 different results using -x option

This problem seems to be specific to ksh93. If you run with set -x some scripts don't work properly. For example: $ cat ksh.test2 ] && print FUBAR! || print OK! $ $ /bin/ksh93 ksh.test2 OK! $ /bin/ksh93 -x ksh.test2 + ] + print FUBAR! FUBAR! $ Trying to find out why this is... (8 Replies)
Discussion started by: lthorson
8 Replies

6. UNIX for Advanced & Expert Users

Writing Custom Builtins for KSH93

I am looking to create some ksh93 extensions using the custom builtin feature. I can successfully create a builtin function, load it using the builtin -f command and get an output. However, I want to get/set values of KSH variables from within my built-in. For example, lets say I am creating... (2 Replies)
Discussion started by: a_programmer
2 Replies

7. UNIX for Advanced & Expert Users

Gurus needed to diagnose severe performance degradation

Hi everyone, newbie forum poster here. I'm an Oracle DBA and I require some guidance from the Unix gurus here about how to pinpoint where a problem is within a Solaris 9 system running on an 8 CPU Fujitsu server that acts as our Oracle database server. Our sysadmins are trying their best to... (13 Replies)
Discussion started by: DBA_guy
13 Replies

8. UNIX for Advanced & Expert Users

Install ksh93 for cygwin

Hi, Does anyone know where can I get ksh93 for installation on CYGWIN. Thanks? (1 Reply)
Discussion started by: devtakh
1 Replies

9. Shell Programming and Scripting

ksh88 or ksh93

Hi all! Does anybody know how can I check if any UNIX installation has implemented ksh88 or ksh93? Thanks in advance. Néstor. (3 Replies)
Discussion started by: Nestor
3 Replies

10. Shell Programming and Scripting

ksh93 deprecation...

Any means of running ksh93 in a ksh88-mode? Might sound odd, but I want/need to restrict U/Win-developed scripts to correspond to the ksh88 version on my Solaris environment(s). Thanks. (2 Replies)
Discussion started by: curleb
2 Replies
Login or Register to Ask a Question