BASH Execution Delay / Speedup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH Execution Delay / Speedup
# 1  
Old 01-26-2015
BASH Execution Delay / Speedup

I have a BASH script that runs a continuous loop, reading a line from a file, and then spawning a background process to use it. I've placed "date" commands inside it to see where it's slowing down, and everything inside -- including reading the line from the file -- is fast, but the loop bogs down AROUND THE "DONE" STATEMENT. Before the end of the loop and getting back to the top often takes 30 to 200 seconds!!

I've tried many things to no avail. I've also limited the number of background processes from 400 all the way down to ZERO (runs the single command in foreground), but the end of the loop is a KILLER.

HELP ME UNDERSTAND THIS (and fix it!!)
# 2  
Old 01-26-2015
As we have nothing or no code to view and test then we cannot possibly hazard a guess.

Please give us the script or something similar so that we can emulate your problem.

OS, machine, bash version and any other details would be of help to us too...

TIA...
# 3  
Old 01-26-2015
Code:
while [ true ] do

(copy a text file over if out of lines)

while [ pointer is less than end of file ] do

  (spawn a job) < ------ background (&) or foreground both take over 30-100 seconds to get past this

done
done

---------- Post updated at 05:13 PM ---------- Previous update was at 05:08 PM ----------

Okay -- I posted the code, and here are some details. I'm running BASH on Redhat Linux 4.6 on an HP server, and I'm usually the only person running on the machine.

Thanks for the quick reply, BTW!! MUCH appreciated!
# 4  
Old 01-26-2015
We are going to need to know what (spawn a job) actually is before we can tell you why it's taking 300 seconds to complete.
# 5  
Old 01-26-2015
BASH Execution Delay / Speedup

What the job does is take that line of the file that it's given as an argument and uses that to make seven or eight data accesses. Right now they're stubs, but in the future, they'll be accessing some hardware that may take awhile. Hence, spawning the job to run in background.

At first, I thought that running over 200 of these jobs as bogging down the machine. So I reduced the number, and reduced and reduced until I had a single job that made some accesses and exited. Still a huge delay at the end of the loop. But there's no testing there -- it's just supposed to return and run the loop again. The test for the line number in the file is in the inner loop. The outer loop continues reading a new copy of the external file *inside* the loop, not where the slowdown is occurring. Not knowing exactly what BASH is doing internally, I don't know what's going on at the head and footer of the loop. But it occasionally slows down a LOT.
# 6  
Old 01-26-2015
And without seeing your actual bash script, we don't know what's going on at the head and footer of your loop.

I can imagine lots of things you could be doing that would cause the symptoms you're seeing. But instead of us guessing at what you're doing, why don't you actually show us your code so we can give you some input that might actually make a difference in the way your code runs???
# 7  
Old 01-26-2015
I am using BASH 4.1.2 on the Linux machine.

Since I've said I've "spawned" the job at that point in background, but folks are saying that it may still be responsible for the slowdown, is there some sort of delay in starting a job like that that may slow down the main loop regardless of it taking awhile to start running independently?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why execution is different from orginal bash registry$database?

Hi all, here's my script #!/bin/ksh if then export DB_CREATE_PATH=`pwd` fi echo echo "********************--Menu--*****************************" echo "*** " echo "*** 1. Pre-Upgrade Steps "... (3 Replies)
Discussion started by: jediwannabe
3 Replies

2. Shell Programming and Scripting

How to simulate an execution queue with bash?

I'm running cygwin bash on windows 7 and I'm have some bat files that perform large builds and take a long time and a lot of memory. Therefor, I don't want to builds executing simultaneously (too much memory). How can I implement a queue so I can queue up multiple builds and only execute one... (2 Replies)
Discussion started by: siegfried
2 Replies

3. Shell Programming and Scripting

execution of a string being echoed in bash

hi all, I am trying to do a loop on a series of plotting function shown below: colorlist=(blue red green); n=0; for k in $xy; do psbasemap $range -JM$scale -B10g5 -X1 -Y1 -P -K > $outfile pscoast $range -JM$scale -B10g5 -D$res -P -W$lwidth -G$fill -O -K >> $outfile echo... (1 Reply)
Discussion started by: ida1215
1 Replies

4. Shell Programming and Scripting

Execution problems with BASH Shell Script

Hi I need help with my coding , first time I'm working with bash . What i must do is check if there is 3 .txt files if there is not 3 of them i must give an error code , if al three is there i must first arrange them in alphabetical order and then take the last word in al 3 of the .txt files... (1 Reply)
Discussion started by: linux newb
1 Replies

5. Shell Programming and Scripting

Execution Problems with bash script

Hello, can someone please help me to fix this script, I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Shell Programming and Scripting

Splitting file needs speedup

I've got a large file (2-4 gigs), made up of 4 columns. I'd like to split the file into two, based on the 2nd column value being even or odd. The following script does the job, but runs incredibly slow--I'm not sure it will complete this week. There must be a clever way to do this with just... (2 Replies)
Discussion started by: I.P. Freeley
2 Replies

7. Shell Programming and Scripting

Optimize and Speedup the script

Hi All, There is a script (test.sh) which is taking more CPU usage. I am attaching the script in this thread. Could anybody please help me out to optimize the script in a better way. Thanks, Gobinath (6 Replies)
Discussion started by: ntgobinath
6 Replies

8. Shell Programming and Scripting

execution time / runtime -- bash script please help!

Hello, I'm running a bash script and I'd like to get more accurate a runtime information then now. So far I've been using this method: STARTM=`date -u "+%s"` ......... *script function.... ......... STOPM=`date -u "+%s"` RUNTIMEM=`expr $STOPM - $STARTM` if (($RUNTIMEM>59)); then... (6 Replies)
Discussion started by: TehOne
6 Replies

9. Shell Programming and Scripting

Calculating delay time - bash

Hi, I am having the following problem. test > hourOfDay=06 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime 180 test > hourOfDay=07 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime 120 test > hourOfDay=08 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime bash: (9-08: value... (5 Replies)
Discussion started by: jbsimon000
5 Replies

10. Shell Programming and Scripting

bash - delay expansion of variable

Hello - I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER: MYPID=$$ MYNAME=`basename $0` LOGGER="/usr/bin/logger -t $MYNAME($LINENO) -p daemon.error" ... echo 'this is an entry into the log file' | $LOGGER ... (3 Replies)
Discussion started by: scandora
3 Replies
Login or Register to Ask a Question