View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 6 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Thu Aug 02, 2007 5:28 pm 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location: SC
On my 3 GHz P4 when I am playing back an HD (either 720p or 1080i) program and commflagging I will get some studdering. I have tried the babysitting script to renice commflagging to 19 and it helps some but didn't completely solve my problem. I found that I had to either schedule commflagging for later or manually pause it while I was watching HD. I found many times that I would forget to restart commflagging after watching a program. To solve this I wrote a script that will check the cpu usage and if it is above a certain threshold it will pause the commflagging process. If the cpu usage is below the threshold it will continue commflagging. I run this script every minute from crontab and it seems to work well. I have played with the threshold value and 65 has worked well for me but that may need to be tweaked for different systems.

Here is the script. If you do put this in your crontab with logging I would suggest adding the following code to /etc/logrotate.d/pause_commflag
Code:
/var/log/mythtv/pause_commflag.log {
        daily
        rotate 7
        notifempty
        copytruncate
        compress
}

I am new to Linux and shell scripting in general so if there are any glaring issues, please speak up.

Thanks,
Britney


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 6:09 pm 
Offline
Joined: Sun Jan 22, 2006 12:37 am
Posts: 30
Location: Cleveland, OH
I remembered reading about this script earlier, and was interested in it because, like you, the "renice" technique worked a little but not all the way for me. So I searched for "pause mythcommflag" but couldn't find it. Reason why? Because this post doesn't actually contain the word "mythcommflag!" So now it does. :)

Incidentally, has anyone else used this pause script with success?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 6:46 pm 
Offline
Site Admin
Joined: Fri Sep 19, 2003 6:37 pm
Posts: 2659
Location: Whittier, Ca
Thanks, both the script and log rotate will be in the next release for those that choose to use it.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 2:10 am 
Offline
Joined: Sun Jan 22, 2006 12:37 am
Posts: 30
Location: Cleveland, OH
Thank you for this pause commflag script. I like this script, and I made these changes:

1.
Code:
FRONTENDCPU=`top -b -n 1 -u mythtv | grep mythfrontend | cut -c 43-45`

I had to change "43-45" to "42-45" to get the entire %CPU usage (##.#), e.g. 48.5%. Otherwise it only picked up the end digits (#.#), e.g. 8.5%.

2.
Code:
if [ "$FRONTENDCPU" -ge "$CPUTHRESHOLD" ]

I think this expression to check "greater than or equal" was working okay at first, but after I was tweaking the code, it began to give me error "integer argument expected." So instead, after asking the Internet, I changed it by adding a second set of brackets and using ">" sign, which converted this test command into an extended test command. (http://www.museum.state.il.us/ismdepts/ ... ructs.html ) I think the problem is that the original conditional statement couldn't handle decimal values, though I don't know why.
Code:
if [[ "$FRONTENDCPU" > "$CPUTHRESHOLD" ]]


3. I added some hyphens and spaces in front of the "echo" lines to make the /var/log/mythtv/pause_commflag.log more readable (to me).

4. The original script decides to pause mythcommflag by looking at mythfrontend %CPU usage instead of total CPU usage. I preferred to look at total CPU usage because I don't need to pause mythcommflag every time I watch something, only when the total exceeds my CPU limits. But every time I grabbed that number programmatically, it said "10.4%" even though "top" visually showed me 80-90%. So instead I grabbed LOAD AVERAGE OVER ONE MINUTE and set a threshold of 3.00.
Code:
#!/bin/bash
# pause_commflag.sh   v0.1.1
# Utility to automatically pause & unpause mythcommflag if CPU usage is above a certain level
# Free for any use.
# Installation:
#  cp pause_commflag.sh /usr/local/bin
#  chmod +x /usr/local/bin/pause_commflag.sh
# Usage: Add to crontab (crontab -e) with logging:
# * * * * * /usr/local/bin/pause_commflag.sh >>/var/log/mythtv/pause_commflag.log 2>&1
# Usage: Add to crontab (crontab -e) without logging:
# * * * * * /usr/local/bin/pause_commflag.sh


NOWDATE=$(date)
LOADAVERAGETHRESHOLD=3.00
PROCCOMMFLAG=`pidof mythcommflag`
if [ -n "${PROCCOMMFLAG}" ]
then

        echo "-$NOWDATE   COMMFLAG Process FOUND. Checking Load Average over 1 minute."
        LOADAVERAGE=`top -b -n 1 -u mythtv | grep load\ average | cut -c 59-62`
        if [[ "$LOADAVERAGE" > "$LOADAVERAGETHRESHOLD" ]]
        then
                echo "  LOAD AVERAGE over 1 minute ($LOADAVERAGE) is greater than the threshold \
($LOADAVERAGETHRESHOLD). PAUSE Commflagging"
                kill -s STOP $PROCCOMMFLAG
        else
                echo "  LOAD AVERAGE over 1 minute ($LOADAVERAGE) is less than the threshold \
($LOADAVERAGETHRESHOLD). CONTINUE Commflagging"
                kill -s CONT $PROCCOMMFLAG

        fi
#else
#       echo "No COMMFLAG Process Active"
fi



My computer setup is 1.6 GHz with 1 GB RAM with ext3 LVM with PVR-150 and WinTV-GO (bttv) and so I have to be careful when simultaneously recording to MPEG-4 via software encoding plus watching an MPEG-4 recording plus mythcommflagging. It "works" but with some recording or playback glitches especially "on the half-hour or hour" when another recording is finishing and mythcommflag is starting up. I am going to post a new topic asking for your suggestions on how best to manage all these. Thanks.

P.S. there is another method given by eweaver that adjusts io priority of mythcommflag. Is anyone familiar about this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 8:50 am 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location: SC
I am glad that you were able to modify this to work for you. I am running R5F1 and am using the version top that came with it. Are you using a different version of KnoppMyth? I am curious as to why you are getting a different output.

One of the reasons I looked at the mythfrontend CPU usage instead of overall CPU is that I thought that commflagging itself would contribute to high CPU load and might trigger a pause when only commflagging was consuming CPU. Have you experienced this or does the Load Average for 1 minute not rise too high with just commflagging?

The other method you linked is similar to the babysitting script I linked above but it appears to change the priority of IO. I have not tried it.

Britney


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 6:40 pm 
Offline
Joined: Sun Jan 22, 2006 12:37 am
Posts: 30
Location: Cleveland, OH
brfransen wrote:
I am running R5F1 and am using the version top that came with it. Are you using a different version of KnoppMyth? I am curious as to why you are getting a different output.

I am using R5F1 also, with the default "top" version.

Quote:
One of the reasons I looked at the mythfrontend CPU usage instead of overall CPU is that I thought that commflagging itself would contribute to high CPU load and might trigger a pause when only commflagging was consuming CPU. Have you experienced this or does the Load Average for 1 minute not rise too high with just commflagging?

For me, commflagging by itself is not too much of a load, and even having some combination of commflagging and recording or commflagging and playback might push the load average to around 2.8, which is why I set my threshold at 3.0. But only when recording on bt878 software encoding plus playback plus mythcommflag, I will see load averages around 4 to 5 which will pretty much screw up the recording plus give glitchy playback.

I think this "overall" threshold is better than only looking at mythfrontend usage. Although note that I play standard-def TV, not high-def TV, so I have a little more headroom.

Quote:
The other method you linked is similar to the babysitting script I linked above but it appears to change the priority of IO. I have not tried it.

I haven't tried it either, but I am intrigued by it. I found a post on the MythTV mailing list that suggests putting the "ionice" function directly into the mythcommflag command in mythtv-setup. This would eliminate using crontab, and seems like it would be more immediate.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu