Project

General

Profile

tvheadend keeps nas awake (raspberry pi with autofs)

Added by stefan 327 about 5 years ago

Hello,
since i installed tvheadend on my raspberry pi (latest raspbian buster, HTS Tvheadend 4.3-1854~gfda89e85e)
my nas won't sleep anymore. The pi runs 24/7, the dvb-c adapter ist connected to it, and it has a ssd for storing, but the recordings are stored to a different nas, that also serves mpd with music. the mpd setup works fine with letting the nas sleep as soon as the mpd playlist is empty.
on the pi, autofs is installed.

here https://tvheadend.org/boards/5/topics/37117?r=39701#message-39701 is mentioned, that tvheadend checks disk space every 15s, and that forcing the drive to go to standby solves the problem - but I think thats no solution with my setup, because the nas would wake up immediately after 15 seconds?

https://tvheadend.org/issues/892 is another thread with a similar topic, and 3 years ago a last user mentions that tvheadend 4.1 is not working for him because of that.

Do I have any possibility to alter tvheadend behaviour? It's ok that tvheadend uses the local disk for everything (epg etc.) but the storing of the recordings.

Or is it a general question and only the developers can fix that?

Stefan


Replies (9)

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Em Smith about 5 years ago

It's not something that is user-configurable. It is hard-coded in dvr/dvr_vfsmgr.c in the dvr_get_disk_space_cb as sec2mono(15).

Unfortunately, I can't think of what a good value would be for you. If you set it to "10 minutes", your disk will probably keep powering down then powering back up again, which many people say will wear out your disk quickly. If you set it much larger, then when you are recording it will not keep adequate free space. I find the noise of a disk powering down and then re-powering up at a random interval more annoying than a constantly running disk.

Many NAS servers cache data so they do not need to access the disk, thus allowing the disk to power down. Is it on a USB disk on your WHS2011? There may be a setting on the USB configuration to say, "I promise I won't remove the disk without clicking the eject button". That may then cause the server to cache the disk usage, which will allow the disk to power-down naturally.

If you're only powering down because you are concerned about power, then many disks use very little power when idle, typically a few watts which normally equates to a few $/£/€ per year. If you're worried about the disk spinning and wearing out, then I wouldn't worry too much since many people say disks fail more when they are power cycled.

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by stefan 327 about 5 years ago

Thank you for the answer!

It is hard-coded in dvr/dvr_vfsmgr.c in the dvr_get_disk_space_cb as sec2mono(15).

If i would like to change that, i had to alter it in the source and compile it myself?

I would be very nice if there was an easier way to adapt tvheadend for nas-needs.
Perhaps a feature request is already existing?

The WHS2011 is actually a normal PC, and I'm planning to move to linux with it. Perhaps it works better then?
It has a small ssd and 5 big hard disks, 8gb ram. When it is running, with all disks spinning, it takes about 70-80 watts.

In standby, only 2 watts.

Like it is at the moment, on and 1 disk spinning (the one tvheadend is keeping on), it takes about 35-40 watts.

Assuming it's normally in standby (I don't look at the about 10% time on and recording or doing other tasks) that makes a difference of about 40 watts, and that is in germany with our high prices for electric energy about 0,04 kw * 24 hours * 365 days * 0,3 €/kWh = 105,12 Euro a year, a sum that I definitely want to save (not thinking about energy consumption in general and effects on climate and so on..)

I think the best way at the moment is probably to connect a second ssd to the pi, and use that for the recording? The Pi is on 24/7 anyway.

kind regards,
Stefan

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Em Smith about 5 years ago

Sorry, I thought you only needed the disks to sleep and cpu idle, not the whole machine go to standby.

How does the WHS go from standby to on? I can find information about "wake on lan", but I don't think it is supported by Tvheadend to wake up your NAS. Unfortunately, the Tvheadend pre-processor command also checks that storage directory exists before calling the pre-processor script, so I don't think that could be used to send a "wake on lan packet" either (and I'd expect that your NAS couldn't wake up fast enough anyway for the recording).

So, I don't think you can make your NAS go to standby and still use it with Tvheadend.

The Amazon Black Friday sale is on next week in Germany, so perhaps a local disk on the pi? I'd probably look at the filesizes you have for existing recordings and then work out if an SSD + enclosure is big enough, otherwise go for a normal usb disk.

I don't know the sizes of disks on your WHS or what else other than music you use the machine for, but I'd consider whether you could move your music to the Pi to allow the WHS to be idle more often.

I think on your Pi the Ethernet shares the USB throughput, but it should be more than fast enough for streaming.

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by stefan 327 about 5 years ago

Hello,

How does the WHS go from standby to on? I can find information about "wake on lan", but I don't think it is supported by Tvheadend to wake up your NAS

It goes on via wake on lan. I never set up wake on lan on the pi, i think it works simply via autofs / autofs smb/cifs.
That is working well with mpd. Ok, you have to wait until the disk is there, sometime it's 30 seconds, some time more. in tvheadend you can specify an additional amount of time for recordings - i think when I would choose a high enough value, it should work that the disk is ready for recording soon enough. but of course I'm not a developer, and i don't understand the underlying design of tvheadend... Altogether, i'm really happy that i found tvheadend, you can do so many things with it! the only sad thing is that the nas won't sleep.

you can never have enough space on a nvr :-)

On our old topfield receiver (defective, that's why I'm trying the pi/tvheadend solution) we had 1 TB, that was quite ok, but there could be more. On the Nas free ds is more than 1 TB at the moment.
What was really annoying with the topfield, if I wanted to save the files / cut them and recode them for longer storage on the pc, there was only the possibility to use the ftp server of the topfield (100mbit). Big recordings over several hours in hd took over 10 GB, it took quite a long time to transfer the files. Now, with the solution where the pi stores the recordings directly on the nas, I can work with a 1gbit connection (pc to nas), what makes it much more convenient.
Until now, I didn't recognize any problems with saving 1 simultaneous hd stream to the nas (it's a pi3b+). I'll test it with 2 streams (it's a usb dual tuner).
I'll have to test if my power supply is strong enough for the pi, 2 usb ssds and the usb dual tv tuner.. Good Idea with the Black Friday!

I don't know the sizes of disks on your WHS or what else other than music you use the machine for, but I'd consider whether you could move your music to the Pi to allow the WHS to be idle more often.

True.. I have to look for a bigger hd for the pi.

Thank you,
Stefan

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Em Smith about 5 years ago

One of my drives is a USB "Seagate Backup Plus". It has two USB ports on the front of the drive, so you get a free "usb powered hub". Might be useful on the Pi to avoid buying a separate hub? (Though USB bandwidth will be shared). It's slower than other disks, but is more than fast enough for Tvheadend.

I see some people have an autofs "wake on lan" script. I think what would happen is Tvheadend would check the path exists, that would cause autofs to send the wake on lan, but Tvheadend would then be blocked waiting the 30 seconds for the NAS to wake-up and autofs to finish mounting the remote path. As you say, setting a pre-record time might work, but it may cause a few problems since Tvheadend isn't intended to block for that long. But, since you're not watching recordings or recording anything else at that moment, you may just be fine, and clients would reconnect.

10GB/hour is good quality. That's roughly 3MB/s, or say 30Mbps (assuming some overheads). Some people have scripts to record locally then move file to a separate NAS server later: search the forums if that interests you.

Assume, you have tuner->pi->disk/Ethernet NAS. So, for one stream that would be a total of 60Mbps.
Assume you also watch something that's disk->pi->network? So another 60Mbps.

So, I'd say you could have six HD (6*60=360Mbps) + 1*watching HD (60Mbps) to give 420Mbps, and a bit of spare USB capacity.

Assuming your NAS is RAID, I'd be tempted to keep the master copies on the NAS for safety, and use "rsync -av --delete /nas/music /local/music" to keep a cached copy locally on the pi for mpd, etc. and then avoid powering the NAS...

Good luck!

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Joe User about 5 years ago

You can write a "feature request" for an option to disable disk space checking.
It is a bit absurd that tvheadend checks every 15sec when in fact it does nothing about it unless a recording is in progress.

The downside of setting the interval to a very high value is that it would even disable it when a recording is in progress.

I use the following patch:

diff --git a/src/dvr/dvr_vfsmgr.c b/src/dvr/dvr_vfsmgr.c
index 59eeb9a5b..dd294d2f5 100644
--- a/src/dvr/dvr_vfsmgr.c
+++ b/src/dvr/dvr_vfsmgr.c
@@ -327,6 +327,8 @@ dvr_disk_space_check()
       continue;
     if (cleanupDone)
       continue;
+    if (cfg->dvr_cleanup_threshold_free <=50 && !cfg->dvr_cleanup_threshold_used)
+      continue;
     if (idx < dvr_disk_space_config_idx)
       continue;
     if (tvh_vfs_fsid_build(cfg->dvr_storage, &diskdata, &fsid))

The smallest value for "Maintain free storage space in MiB:" is 50 (thus the <=50 comparison).

So with this patch, FOR EACH recording profile which uses the NAS, you would have to set:

Maintain free storage space in MiB:  50
Maintain used storage space in MiB (0=disabled):  0

Ideally there should be an option either globally and/or for each recording profile individually to disable disk space checking. Either by allowing a "0" value for "Maintain free storage space in MiB" which can be used to disable or an explicit "Disable disk space checking for the profile" option, which would be better because a value 0>n<50 would not be very useful when actually used.

BTW - it is especially absurd since I have ALL my "Recorded file(s) retention period:" set to forever, so nothing would be deleted anyway.)

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Dave H about 5 years ago

Joe User wrote:

It is a bit absurd that tvheadend checks every 15sec when in fact it does nothing about it unless a recording is in progress.

Is that true? Doesn't it need to access the recordings if it is playing something out as well? (Not that it makes much difference, I agree)

And @stefan_327, I used to love my Topfield. It was pretty much perfect until it eventually failed. Worked out of the box and allowed third-party open-source contributions to improve it as well :)

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by Joe User almost 5 years ago

Dave H wrote:

Is that true? Doesn't it need to access the recordings if it is playing something out as well? (Not that it makes much difference, I agree)

And @stefan_327, I used to love my Topfield. It was pretty much perfect until it eventually failed. Worked out of the box and allowed third-party open-source contributions to improve it as well :)

https://github.com/tvheadend/tvheadend/blob/d453f5bef392981c8b14025e2446e4012f72f422/src/dvr/dvr_vfsmgr.c#L345

Stefan A, obviously it is too late now, but ideally one would mount the NAS on the STB and directly record on it any recordings you plan to keep. I actually go further than that and also boot from, and mount the whole root filesystem from my NFS server (using nfsroot) on my Amiko Alien2 which also only has a 100Mb nic. I never tried to find the limits, but have no problems recording 2-3 channels while also playing back another recording. It seems a bit of a waste to have to buy extra disks when you already have a NAS (and kind of defeats the purpose of even having a NAS...)

RE: tvheadend keeps nas awake (raspberry pi with autofs) - Added by stefan 327 almost 5 years ago

Hello,
thanks for the answers.
I'm not that fast with everything, I didn't make any changes until now (and no new disk until now. I think i'll update the one in my pc, and use the old one for the recordings then). I'm not that experienced with altering sources and self-compiling, when I have enough time, I'll try. Using the nas for recordings stays the final goal for me, with working standby / spin down of the disks.
But I would prefer user configurable options ;-)

Best regards,
Stefan

    (1-9/9)