BASH Execution Delay / Speedup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH Execution Delay / Speedup
# 8  
Old 01-26-2015
There are thousands of things that could cause this. SHOW US YOUR CODE!
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 01-26-2015
4
Code:
 INPUT_POINTER=0
  5 while [ true ]
  6 do
  7     if [ ${INPUT_POINTER} -ge ${SIZE} ]
  8     then 
  9         cp ${REMOTE_FILE} ${LOCAL_FILE}
 10         > ${REMOTE_FILE}
 11         SIZE=`wc -l ${LOCAL_FILE} | sed "s;  *;;" | sed "s; .*;;"`
 12         INPUT_POINTER=1
 13     fi  
 14     
 15     while [ ${INPUT_POINTER} -le ${SIZE} ]
 16     do
 17         INPUT_POINTER=$((INPUT_POINTER + 1));
 18         INPUT=`cat ${LOCAL_FILE} | head -${INPUT_POINTER} | tail -1`
 19         my_job "${INPUT}" &
 20     done # Reading File Lines
 21 done # while TRUE

I've tried inputing the file into the "done" statement and executing a "while READ", which worked about the same.
# 10  
Old 01-27-2015
So, from this code it seems that your intention is to simultaneously run an infinite number of jobs for every line in some file on your system. You do not care if any of these jobs start successfully. You do not care if any of these jobs complete successfully (or at all). You believe that you should be able to start an infinite number of jobs and all of those jobs should run as though they are the only job running on your system.

Unfortunately, I do not know of any system that will act anything at all like that. Nor, do I understand why you need an infinite loop to read lines in a file forever. Presumably your script terminates when the system kills it because it realizes you have exhausted system resources.

You say that a while read loop performs about the same way. You are correct in noting that an infinite loop is an infinite loop, but a while read loop would only have needed one process per line processed while your current nested loops use four processes per line processed plus 3 processes each time the file is processed. And, and a while read loop would read your file once each time you process the file while your current code reads the entire file n+1 times if your file contains n lines.

If, instead of processing a single file an infinite number of times, you want to process each line in a file once; and if instead of ignoring the success or failure of all of the jobs you start, you'd like to actually log any failures that might occur during processing and not terminate your script until all lines have been processed, tell us more about your system:
  1. Given the expected load on your system and the number of processors available to run your script, how many simultaneous processes should your script expect to be able to run?
  2. What does my_job do? (If it doesn't exit with a zero exit status if it completes successfully and exit with a non-zero exit status if it does not complete successfully, rewrite it so it does! If it exits before all children it has started have completed, rewrite it so it doesn't return until all of its children have finished!)
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 01-27-2015
I apologize, Don. I don't provide all the code because I thought it would obfuscate things, but it seems I've made things more complicated. I really appreciate your patience, here.

First, I run "ps" and look for instances of "my_job" and have a maximum number that's checked before spawning another. I've run as many as 400 to stress things, and it worked (with the exception being the problem I'm talking about here, which doesn't seem to be affected at all by that number). I currently run a maximum of 20, but at this instant, for debugging purposes, I've set the limit at one. There is some proprietary stuff inside "my_job" that I'm hesitant to show (yes, I understand how difficult that makes this!)

As for reading the files continuously, the source of data is always on, populating the source text file. I copy the file over, erase the source copy, and then read each line until a counter exceeds the line size of the file, OR if the last line I read has a timestamp that is too old.

As for your suggestion to read the file a single time, yes, I used that successfully and just switched back with the suspicion that that method (the method you recommend here) was causing my current problem.

Exit status: It executes an "exit 0" on success or failure, but results are all echoed to a log file. Failures I check are all for functions that read or write data to and from hardware, but I still exit 0, and simply report the results of those functions.

Would you suggest waiting until the process count (of running "my_job" instances) dropped to some lower number or perhaps zero before fetching a new file full of records?

Thanks again!!
Mark
# 12  
Old 01-27-2015
Quote:
Originally Posted by gmark99
I apologize, Don. I don't provide all the code because I thought it would obfuscate things, but it seems I've made things more complicated. I really appreciate your patience, here.
If you don't understand what's wrong, you also don't know what's relevant.

If you think the program is too big/complicated to post, whittle it down into a smaller, still-complete program which still shows the same problem. Sometimes just doing this can find the problem, too.
These 2 Users Gave Thanks to Corona688 For This Post:
# 13  
Old 01-27-2015
There are ways to limit the number of parallel processes for stable, robust system use; been there before, wrote bctl (birth control): Keep up constant number of parallel processes
This User Gave Thanks to DGPickett For This Post:
# 14  
Old 01-27-2015
Hi gmark99...
Quote:
Exit status: It executes an "exit 0" on success or failure, but results are all echoed to a log file. Failures I check are all for functions that read or write data to and from hardware, but I still exit 0, and simply report the results of those functions.
<Cough> It would be wiser to make your my_job have an error code in real time, detect it in the main script yet still log it as before...
How about commenting out the line, or placing echo in its place, in the script that points to my_job .
Also try a sleep <secs> just before your spawned child. In other words deliberately slow things down and see what the results are compared to what you expect them to be.
LBNL, although you are launching your child in the background try strategically placing wait in the loop and observe what happens or launch it without the & and let the shell temporarily hang until it is finished...
Just a few ideas to play with.
These 2 Users Gave Thanks to wisecracker For This Post:
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