HDD spin-up problem

Linux and UNIX specific discussions
Post Reply
User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia
HDD spin-up problem

Post by mackowiakp » Mon Apr 25, 2011 8:09 pm

I have TwonkyServer running on Mandriva Linux with 3x1,TB HDD for A/V content + 32GB SSD for OS only. The problem is that HDD`s goes spi-down after 20 min of inactivity. When I try to broadcast A/V content from HDD`s, HDD must spin-up. It takes several seconds and sometimes my Samasung TV says "Connection lost" or "Invalid format". Then I switch to "normal" TV function and again to play A/V via ethernet and everything works fine. I have no possibility to set-up any timeout in Samsun TV. So is it any possibility to set-up such timeout in this (some woraround)? Or is any other possibility to resolve the problem without keeping HDD`s spin-up all the time? Does Samsung TV sends any pulling to server (after switching to IP mode) which could be use for trigerring spin-up of attached disks to server?
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
DaemonBeetle
Posts:305
Joined:Mon Dec 28, 2009 11:05 am
AV Hardware:Plex Media Server, Samsung Smart TV (2009 and 2013)

Re: HDD spin-up problem

Post by DaemonBeetle » Wed Apr 27, 2011 6:44 pm

Disks aren't generally designed to spin up and down, so what you're saving in power consumption is being offset by the reduced lifespan of the disks. If you can afford the extra power cost of leaving them spinning all the time not only will you solve your Twonky problem, but your disks will last longer.
No longer running Twonky

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Wed Apr 27, 2011 8:24 pm

OK. But I mean about possibility to spin-up disk if I switch my Samsung TV to IP mode. Samsung DLNA client must send something to Twonky and I want this switching to trigger spin-up of disk. Of course I can write some script "looking" for new IP connection pulling coming to server and spin up disks in such case. But what I need to look for (on IP level)?
You have to look that more than 90% of time of usage, disks are spin-down. My home server is turn on all the time.
So what can be use as such trigger?
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
DaemonBeetle
Posts:305
Joined:Mon Dec 28, 2009 11:05 am
AV Hardware:Plex Media Server, Samsung Smart TV (2009 and 2013)

Re: HDD spin-up problem

Post by DaemonBeetle » Wed Apr 27, 2011 8:46 pm

The first thing Twonky will know is when it gets a connection from the TV - that will be the first time the TV becomes active on the network for anything other than DHCP. That's the soonest that Twonky would be in a position to do anything that would wake the disks.

If you're moderately skilled you could probably write an IPTables userspace module that causes the disk to spin up when any packets are sent to the Twonky port. You'd need to identify the port used (netstat will tell you that).

Alternatively, much simpler, using the likes of SWATCH you could watch Twonky's log for

Code: Select all

LOG_EVENTING: handleConnections : upnp_cp_resubscribe
If that causes it to spin up too often try looking instead for

Code: Select all

LOG_HTTP: upnp_soap_server_dispatcher : 
Though it may be too close to the actual request to buy enough time for the disks to spin up. I'm sure if you spend some time experimenting you'll find something, though you'll probably also have to play with the logging levels to get it right.
No longer running Twonky

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Wed Apr 27, 2011 8:57 pm

THX for reply. I will try. IP tables is good idea for me.
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: HDD spin-up problem

Post by parnott » Thu Apr 28, 2011 5:55 pm

mackowiakp wrote:THX for reply. I will try. IP tables is good idea for me.
If you want to try this approach then you need to look for SSDP NOTIFY messages. I am fairly sure they are UDP broadcast packets. The Samsung TV should be sending them about every 300 secs or so, even when not in 'network mode'. They just let other devices on the network know that the source is still there.

Now the problem will be your router is probably broadcasting these messages as well, as could other devices on your network. So, unless you filter by the Samsung TV's IP address, the only thing you have achieved is keeping your disks spinning all the time. And, there are much easier ways to do this.

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Thu Apr 28, 2011 6:37 pm

OK. But I want to spin-up disks only when TV is in "network mode". During normal operation of TV set disk should be sipn-down.
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: HDD spin-up problem

Post by parnott » Fri Apr 29, 2011 6:06 pm

mackowiakp wrote:OK. But I want to spin-up disks only when TV is in "network mode". During normal operation of TV set disk should be sipn-down.
Well you can try but I doubt it will work. Just think about it-
1) The Samsung TV is giving the error messages because Twonky is not giving a reply fast enough for the TV.
2) Twonky can't give the reply fast enough because it is waiting for the disks to spin up.
3) Twonky does not know what mode the TV is in, and there is nothing in the protocols to support this. The first Twonky knows that the TV wants data is when it receives a request from the TV. Typically this would be a browse request. At this level it works just the same as a Web Browser and Web Server (in fact the protocol IS HTTP).
4) Intercepting the request in IP Tables and trying to spin up the disks there will give you at most a few milliseconds head start in the disk spin up. But you have introduced an additional delay in responding to the TV's request. Twonky still has to wait for the few seconds it takes for the disks to spin up and the TV will still think the connection has been lost.

So I can't think of any practical way of doing what you want.

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Sat Apr 30, 2011 3:08 am

In my country people say that "If You cant have what You love, just love your mother-in-low". So I agree that there in no way to solve the problem because TV set can not "ask" Twonky "Are You ready" and Twonky answer "Wait, I have to spin-up my disks". But associating spin-up disks with the first pooling on IP level (diskover by IP Tables) gives servereal seconds for spin-up action because user browse the A/V content listing to find what he want to watch. Of course it is only workaround but not real solving the problem. But it solve the problem from the point of view of user. And it must be enouth at this time. Like mother-in-low ;-)
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
DaemonBeetle
Posts:305
Joined:Mon Dec 28, 2009 11:05 am
AV Hardware:Plex Media Server, Samsung Smart TV (2009 and 2013)

Re: HDD spin-up problem

Post by DaemonBeetle » Sat Apr 30, 2011 9:41 am

It won't give several seconds - it might give you one, more probably as parnott said quite a lot less.
No longer running Twonky

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: HDD spin-up problem

Post by parnott » Sat Apr 30, 2011 7:58 pm

But associating spin-up disks with the first pooling on IP level (diskover by IP Tables) gives servereal seconds for spin-up action because user browse the A/V content listing to find what he want to watch.
No it does not, because Twonky has to read its database to find out what content listings to serve to the client. If Twonky cannot respond quickly enough (because the disks are spinning up) then the TV will think the connection has been lost.

I really don't know what you mean by 'first pooling on IP level'. If you mean intercepting the initial connection to get content listings or play a media file, then the time it it takes to execute the interceptor just adds more delay. It is the TV that is having the problem. It is not getting a response within the timeframe parameters it was programmed with.

There is nothing on the server or with Twonky that you can do to fix it except keep you disks spun up all the time. It makes no sense that you are trying to work around a problem your TV is having because it expects responses within certain timeframes and then you want to add more delay on the server. Is not going to work.

And as a bit of cultural excahnge, in the country where I am from we have the phrase "Pissing into the wind". It basicly means, well at a polite level, something that is pointless or not likely to work.

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Sat Apr 30, 2011 9:03 pm

So the begining of listing a "discussion" between TV set and TwonkyServer after depresing <MEDIA.P> key (that is switching TV to "IP mode") and "clicking to VIDEO icon (on TV):

21:45:18.715831 IP TV-p.51797 > mediatomb.no-ip.org.9000: Flags [S], seq 1700701837, win 5840, options [mss 1460,sackOK,TS val 16184333 ecr 0,nop,wscale 1], length 0
21:45:18.715897 IP mediatomb.no-ip.org.9000 > TV-p.51797: Flags [S.], seq 2275513877, ack 1700701838, win 5792, options [mss 1460,sackOK,TS val 4494666 ecr 16184333,nop,wscale 6], length 0
21:45:18.716188 IP TV-p.51797 > mediatomb.no-ip.org.9000: Flags [.], ack 1, win 2920, options [nop,nop,TS val 16184334 ecr 4494666], length 0
21:45:18.716621 IP TV-p.51797 > mediatomb.no-ip.org.9000: Flags [P.], seq 1:493, ack 1, win 2920, options [nop,nop,TS val 16184334 ecr 4494666], length 492
21:45:18.716783 IP mediatomb.no-ip.org.9000 > TV-p.51797: Flags [.], ack 493, win 108, options [nop,nop,TS val 4494667 ecr 16184334], length 0
21:45:18.717674 IP mediatomb.no-ip.org.9000 > TV-p.51797: Flags [P.], seq 1:291, ack 493, win 108, options [nop,nop,TS val 4494667 ecr 16184334], length 290

TV-p - is my TV set and mediatomb.no-ip.org is TwonkyServer working on port 9000. This is listing captured by TCPDUMP.
So "clicking" on Video, Audio, Photo icons on TV screen couse such "conversation". Thats what I mean "IP pooling". This can trigger (via IP Tables) spin-up disks, especialy first line. It gives me several seconds to spin-up before I select file to play/listen/display. Of course IT IS ONLY workaround - not real solving the problem.
During normal operation of TV-set no such IP "discussion".
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

HDD spin-up problem - partialy SOLVED

Post by mackowiakp » Sun May 01, 2011 6:21 pm

This is my workaround of spin-up HDD. I want to spin-up 2 pcs USB connected HDD (named disk-1 and disk-2) each set-up to spin-down by itself after 20 min (1200 sec). The OS (Linux) is installed on SSD (64 GB) disk so this one does not has spin-down problem.
Just I run the script below (on Twonky running server) form cron as @reboot statement (in background).
192.168.0.12 and 13 - IP address of my TV sets
192.168.0.7 - IP adres of Twonky server
9000 - IP port of Twonky server
eth1 - physical port of Twonky server

#!/bin/bash
rm -f /root/XXX 2>/dev/null
sleep 160
while true
do
tcpdump -q -i eth1 -c 1 -n host 192.168.0.7 and \(192.168.0.12 or 192.168.0.13\) and port 9000 > /root/XXX 2>/dev/null
#mail -s "Spin-up" media < /root/XXX
ls /home/media/disk-1/Filmy > /dev/null 2>/dev/null
ls /home/media/disk-2/Muzyka > /dev/null 2>/dev/null
sleep 1100
done

Any improvements ?
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: HDD spin-up problem

Post by parnott » Sun May 01, 2011 8:10 pm

Any improvements ?
Probably not. But only you can tell us.

However look at your code.
1) You imply you are executing the code as a cron job. But I cannot see how the scipt will ever end, so it will just keep replicating itself. Probably eventually crash your server. See examples of a while loop here- http://tldp.org/LDP/Bash-Beginners-Guid ... 09_02.html If it is a start-up script then-
2) You are using tcpdump but not doing anything with the output of that command that can be used in the rest of the script.
3) You are using ls to spin up the disks. Fine but if each disk takes 2 seconds to spin up then you have got a delay of 4 seconds. TV is still going to time-out.

Keep trying, but it is not going to happen.

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Sun May 01, 2011 9:04 pm

AD 1) - The script will never ends - it is intended. The crashing is not possible because of long time of sleep command in the loop.
AD 2) - Yes, I am doing nothing with TCPDUMP results but such syntax "trigger" executing the rest part of the script (THE FIRST FRAME) so script stops at TCPDUMP command and wait for any transmission between TWONKYSERVER and TV sets. And ONLY for TV sets. All other uPnP clients (VLC, WMP, etc) does not couse spin-up disks (but can it can be done simply by adding additional IP adresses)
AD 3) - Yes, spin-up takes aprox 4 sec but it is enough latency in normal home operation. Notice that it takes more than 4 sec to switch TV to "network mode" and find interesting file for playback. And more, please notice that even turning on TV set (without switching to "network mode") cousing generating serveral IP frames to TwonkyServer.from TV set. Optionally each "ls" lines could be ended by "&" to put it in bacground so the time will be reuced to 2 sec.

I have to say once more. IT IS WORKAROUND. Not solving the problem!
Linux is like wigwam. No Windows, no Gates but Apache inside!

User avatar
mackowiakp
Posts:43
Joined:Mon Apr 11, 2011 8:00 am
AV Hardware:Samsung TV series 5 and 6, PCH A110, Mandirva Linux
Icecrypt S4000 Sat PVR, Ariva 200 Sat PVR-Ready
Location:Poland/Gdynia

Re: HDD spin-up problem

Post by mackowiakp » Mon May 02, 2011 6:36 pm

So final tested and improved version of my script:

#!/bin/bash
sleep 160
cat /dev/null > /root/XXX
while true
do
cat /dev/null > /root/XXX
tcpdump -q -i eth1 -c 10 -n host 192.168.0.7 and \(192.168.0.12 or 192.168.0.13\) and port 9000 > /root/XXX 2>/dev/null
if [ $(stat -c%s /root/XXX) -gt 1 ]
then
cat /root/XXX > /home/media/disk-1/spin-up
cat /root/XXX > /home/media/disk-2/spin-up
#mail -s "Spin-up" media < /root/XXX
fi
sleep 720
done
Linux is like wigwam. No Windows, no Gates but Apache inside!

Post Reply