Need tune my command occupying 90% CPU


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need tune my command occupying 90% CPU
# 1  
Old 09-03-2009
Lightbulb Need tune my command occupying 90% CPU

Can some body tune the below command, its occupyinh more than 90% of CPU some times.

Code:
tail -n 1000 /logs/trace.log | awk 'BEGIN{OOM = 0; ScE = 0; NaE = 0; Jms = 0}
/OutOfMemoryException/{OOM = 1}
/StaleConnectionException/{ScE = 1}
/NamingException/{NaE = 1}
/JmsTimeOutException/{Jms = 1}
END{printf " %-7s%-7s%-7s%-7s",OOM,ScE,NaE,Jms;}'

Advance Thanks for your valuable feedbacks.

Thanks
Senthil.

Last edited by senthil.ak; 09-03-2009 at 08:33 AM..
# 2  
Old 09-03-2009
one thing striked while seeing this, once if you have a certain text then why you need to continue checking...

that is if OOM is enabled at 1st line itself why you are continuing the check for the remaining 999 lines !

So have a if condition, if the OOM is not enabled then do out a pattern match else dont.

This is just a simple thing striked. Expecting better solution from others here...
# 3  
Old 09-03-2009
Do you mean to say like this

Code:
tail -n 1000 /logs/trace.log | awk 'BEGIN{OOM = 0; ScE = 0;NaE = 0; Jms = 0}
{if ($0 ~ /OutOfMemoryException/)OOM = 1;}
{if ($0 ~ /StaleConnectionException/)ScE = 1;}
{if ($0 ~ /NamingException/)NaE = 1;}
{if ($0 ~ /JmsTimeOutException/)Jms = 1;}
END{printf " %-7s%-7s%-7s%-7s",OOM,ScE,NaE,Jms;}'

thanks
Senthil
# 4  
Old 09-04-2009
I think he means that you should check that a condition does not exist and then, only in that case, try to match the regex. If not OOM then try to match OOM, etc. But that's probably because you seem to be using your variables as flags (value = 0 or 1) instead of counters. Do you really only want to set the variables equal to 1 on a match or did you really mean to increment (+= 1 or ++) them so that they are counters and not just flags? Plus, if you use an if-then-else construct, you won't end up trying to match all 4 cases for every line (like you do now). If you have any historical data that indicates the frequency of occurrences of those errors, then you could order them in your if-then-else by highest frequency first and that would help too.

But does it really matters how much CPU it's using?
# 5  
Old 09-04-2009
Based on the command that is written,
if its to check for the existence of OOM and others, once its 1 for all, then exit instead of continuing to process.
# 6  
Old 09-04-2009
Can some body help on this, i still cant understood the solution, I have provided the script snippet which i am using in the script and the suggested one

Code:
tail -n 1000 /logs/trace.log | awk 'BEGIN{OOM = 0; ScE = 0;NaE = 0; Jms = 0}
{if ($0 ~ /OutOfMemoryException/)OOM = 1;}
{if ($0 ~ /StaleConnectionException/)ScE = 1;}
{if ($0 ~ /NamingException/)NaE = 1;}
{if ($0 ~ /JmsTimeOutException/)Jms = 1;}
END{printf " %-7s%-7s%-7s%-7s",OOM,ScE,NaE,Jms;}'

Do the above code is correct or i need to change this one too.... My purpose is to check the error in the last 1000 line in logs and then set the counter to 1 if not then 0. Awaiting for better solution from experts.

Last edited by senthil.ak; 01-06-2010 at 07:28 AM.. Reason: spelling mistake
# 7  
Old 01-06-2010
Can some body help on this, i still cant understood the solution, I have provided the script snippet which i am using in the script and the suggested one

Code:
tail -n 1000 /logs/trace.log | awk 'BEGIN{OOM = 0; ScE = 0;NaE = 0; Jms = 0}
{if ($0 ~ /OutOfMemoryException/)OOM = 1;}
{if ($0 ~ /StaleConnectionException/)ScE = 1;}
{if ($0 ~ /NamingException/)NaE = 1;}
{if ($0 ~ /JmsTimeOutException/)Jms = 1;}
END{printf " %-7s%-7s%-7s%-7s",OOM,ScE,NaE,Jms;}'

Do the above code is correct or i need to change this one too.... My purpose is to check the error in the last 1000 line in logs and then set the counter to 1 if not then 0. Awaiting for better solution from experts.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

Files not getting deleted with rm & occupying space in filesystem

Hello, OS version is Red Hat Enterprise Linux Server release 6.5 (Santiago). In one of the filesystem some old files post clone are not getting removed even with 'rm' # ls -ltr | grep meagpd_62.dbf -rw-rw---- 1 oracle oinstall 34358697984 Sep 1 08:46 meagpd_62.dbf # rm... (7 Replies)
Discussion started by: saharookiedba
7 Replies

2. Shell Programming and Scripting

Tune my script

Hi ! My script read out data out of 144 files per day - every ten minutes a file with data. data-file WR030B 306.71 0 WR050B 315.13 0 WR120B 308.34 0 WV030B 3.52 0 WV050B 5.06 0 WV120B 6.65 0 TLUFT02B 8.60... (3 Replies)
Discussion started by: IMPe
3 Replies

3. Programming

SQL : Fine tune Insert by query

i would like to know how can i fine tune the following query since the cost of the query is too high .. insert into temp temp_1 select a,b,c,d from xxxx .. database used is IDS.. (1 Reply)
Discussion started by: expert
1 Replies

4. Shell Programming and Scripting

Command to find the Memory and CPU utilization using 'top' command

Hi all, I found like top command could be used to find the Memory and CPU utilization. But i want to know how to find the Memory and CPU utilization for a particular user using top command. Thanks in advance. Thanks, Ananthi.U (2 Replies)
Discussion started by: ananthi_ku
2 Replies

5. Solaris

Please tune my script for Solaris

I have very big log file around 2-3 GB in that it contians 24 hours log data. My work is extract only 5-5 data and count the patterns from them. I worte a script in linux and we're using that. sed -n "/2009 05:/,/2009 17:/p" trace.log | grep -f patterns.txt > temp.log while read string ;do... (5 Replies)
Discussion started by: senthil.ak
5 Replies

6. Shell Programming and Scripting

Tune my query

I have a requirement to separate only some numbers from the input file and produce it in a format. The input is ( i have took a sample, the actual file contains more than 50000 rows around 840 MB in size) $cat temp.txt 001 08 002 08 003 06 004 11 005 11 006 08 007 08 008 92* 009 92 010... (1 Reply)
Discussion started by: senthil.ak
1 Replies

7. UNIX for Dummies Questions & Answers

Tune my logic of script

I have big log file, which contains the netstat output from my application server to a particular DB server. I aim is to plot a daily graph for this. Please find the sample log file below. @ - ........................................................... @ - Total number of connection to the ... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

8. Programming

Application occupying CPU resources

Dear all, I have a pro c application running in the unix environement. This pro c program actually trigger by a java application from sun workstation. Recently, when we released a new proc c application and notice that the application occupying the CPU resources even through we check that the... (1 Reply)
Discussion started by: ghho
1 Replies
Login or Register to Ask a Question