Download speed and CPU

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
bbaraniec
Full Member
Full Member
Posts: 110
Joined: July 29th, 2011, 5:43 am

Download speed and CPU

Post by bbaraniec »

Hello,

First of all welcome everyone and thanks for SAB :)
I have a question according download speed and CPU usage.
I'm running SAB 0.6.5 on ReadyNas Pro with Intel 1,86 Dual Core and 2GB ram.
I have 35Mbit/s connection giving me stable 4.0 to 4.2MB/s download speed. While downloading (without setting any limitation) I've sshed to my box and check CPU usage, it's around 60-70% all the time.
What I have notice that when I limit download speed to 4096kbit/s, so exact 4MB/s CPU usage drops to 20-30%. So you see there isn't much a difference in download speed but there is huge difference in CPU usage.
Any reason why this is happening? Can anyone confirm that behavior?
Thank you in advance

Regards
Bartek
-
Kind regards
Bartek
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Download speed and CPU

Post by shypike »

CPU usage is an issue with SABnzbd.
We have been planning to look at this, but the to-do list is so long.
It is an interesting observation that you make and it may very well
point to some inefficiency in the way the socket handling is scheduled.
I have a Windows Home Server box with a similar CPU/memory spec,
so I'll try to reproduce this.
I assume the ReadyNas runs some Linux derivative?
bbaraniec
Full Member
Full Member
Posts: 110
Joined: July 29th, 2011, 5:43 am

Re: Download speed and CPU

Post by bbaraniec »

Hi shypike,

Thank you for your reply.

Code: Select all

Nas:~# uname -a
Linux Nas 2.6.37.6.RNx86_64.2.1 #1 SMP Fri Jun 24 18:53:39 PDT 2011 x86_64 GNU/Linux
Nas:~# cat /proc/version
Linux version 2.6.37.6.RNx86_64.2.1 (jmaggard@calzone) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Fri Jun 24 18:53:39 PDT 2011
Running on Python 2.6.6.
Once I get some time I will check that behavior on my NB running Windows 7.
-
Kind regards
Bartek
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

@bbaraniec

Bartek, does your NAS support the 'top' command? I think so as it's Linux.

For my (Ubuntu) Linux, I've patched SABnzbd (a few lines in the file sabnzbd/misc.py) so that it shows the CPU-load and SABnzbd's relative part therein in the SAB webinterface. See screendump (upper right corner):

Image

So with this patch you don't have to ssh into your NAS to see the CPU-load.

If you find this useful for your NAS, let me know and I'll post the code.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Download speed and CPU

Post by shypike »

sander wrote: For my (Ubuntu) Linux, I've patched SABnzbd (a few lines in the file sabnzbd/misc.py) so that it shows the CPU-load and SABnzbd's relative part therein in the SAB webinterface. See screendump
Interesting, can you share this? :)
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

Sure! Below is the first version (with a lot of ugly debug and useful comment stuff). I'm now writing a version that calls an external custom script in which you can put things you want to report: handy for ad-hoc debugging stuff like CPU-usage, SAB-cpu-usage, unrar-cpu-usage, ...

Output of

Code: Select all

~/SABnzbd-0.6.6/sabnzbd$ diff -u misc.py.org misc.py
is

Code: Select all

--- misc.py.org	2011-07-31 12:02:54.667851903 +0200
+++ misc.py	2011-07-31 10:47:41.777851056 +0200
@@ -913,7 +913,36 @@
     if sabnzbd.WIN32 or sabnzbd.DARWIN:
         return ""
     try:
-        return "%.2f | %.2f | %.2f" % os.getloadavg()
+
+	'''
+	$ top -bn1 | grep Cpu
+	Cpu(s):  6.5%us,  1.7%sy,  0.9%ni, 89.8%id,  0.8%wa,  0.0%hi,  0.3%si,  0.0%st
+	'''
+	command = " top -bn1 | grep Cpu | awk '{ print $2 }' | awk -F% '{ print $1 }' "
+	CPUusage = os.popen(command).readline().strip()
+	#print CPUusage
+
+	'''
+	$ top -bn1 | grep SABnzbd.py
+	12665 sander    20   0  485m  74m 4568 S    0  2.0   0:28.02 SABnzbd.py      
+
+
+	with:
+	  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND      
+
+	'''
+	command = " top -bn1 | grep SABnzbd.py | awk '{ print $9 }' "
+	SABpercentage = os.popen(command).readline().strip()
+	#print SABpercentage
+
+	loadavg = "%.2f | %.2f | %.2f " % os.getloadavg()
+	#print loadavg
+
+	returnstring = loadavg + " --- CPUusage: " + CPUusage + "% --- SABpercentage: " + SABpercentage + "%"
+	#print returnstring
+
+        #return "%.2f | %.2f | %.2f | %s | %s" % os.getloadavg()
+	return returnstring
     except:
         return ""
 
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

And here's the cleaner and more flexible version of misc.py calling an external script.

I need help with one thing, Shypike: the working directory of SABnzbd: what is it? I need to get rid of the hard coded SAB directory. Or is there a directory that is always defined, for example the pre/post processing directory?

Code: Select all

--- misc.py.org	2011-07-31 12:02:54.667851903 +0200
+++ misc.py	2011-07-31 12:20:36.957852103 +0200
@@ -912,10 +912,27 @@
     """
     if sabnzbd.WIN32 or sabnzbd.DARWIN:
         return ""
+
     try:
-        return "%.2f | %.2f | %.2f" % os.getloadavg()
+	dir = '/home/sander/SABnzbd-0.6.6'
+	#dir = '..'   #### Does not work :-( What is my working directory? Or: put the script in the pre/post-processing directory?
+	scriptname = 'sysload-custom-script.sh'
+	scriptfullname = dir + '/' + scriptname
+
+	if os.path.isfile(scriptfullname):
+		# print "Yes, file exists"
+		customoutput = ''
+		for thisline in os.popen(scriptfullname).readlines() :
+			customoutput += ' --- ' + thisline.strip()
+	else:
+		customoutput = '--- no script found ' + scriptfullname	# This is debug info
+
+	loadavg = "%.2f | %.2f | %.2f " % os.getloadavg()
+	returnstring = loadavg + customoutput
+	return returnstring
+
     except:
-        return ""
+        return "<something went wrong>"		# This is debug info too
 
 
 def format_time_string(seconds, days=0):

Example output of my sysload-custom-script.sh:

Code: Select all

sander@R540:~/SABnzbd-0.6.6$ ./sysload-custom-script.sh
CPUload: 6.1%
SABpercentage: 8%
sander@R540:~/SABnzbd-0.6.6$
generated by this script:

Code: Select all

#!/bin/sh
top -bn1 | grep Cpu | awk '{ print $2 }' | awk -F% '{ print "CPUload: " $1 "%" }' 
top -bn1 | grep SABnzbd.py | awk '{ print "SABpercentage: " $9 "%" }'


User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Download speed and CPU

Post by shypike »

The current directory is whatever SABnzbd is started from, so not usable.
If you put the script in the same directory as SABnzbd.py, you can use the global sabnzbd.DIR_PROG.
BTW: I don't think running a script every few seconds is a good idea.
Isn't there some way to get this info from the /proc pseudo files?
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

OK, that directory works. Thanks.

I personally don't worry too much about calling a script each x (in my case: 30) seconds: that software is 20 year old technlogy, which used to run on machines with 1 MB RAM and a 10 Mhz CPU. So I don't think it will eat too much CPU or RAM.

And the 'time' command shows the real time used on the CPU: 0,04 sec:

Code: Select all

sander@R540:~/SABnzbd-0.6.6$ time ./sysload-custom-script.sh 
CPUload: 5.9%
SABpercentage: 4%

real	0m1.069s
user	0m0.020s
sys	0m0.040s
sander@R540:~/SABnzbd-0.6.6$
I can have a look at /proc/, but it would mean more parsing.
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

I had a look the /proc/ (procfs), and so far it's interessing:

You can only look at your own /proc/<pid>/... which you can easily access this via /proc/self/...

Example of (virtual?) memory usage:

sander@R540:~/kul$ cat /proc/self/status | grep -i -e VmPeak -e VmRss
VmPeak: 9236 kB
VmRSS: 588 kB
sander@R540:~/kul$

So that can easily be put into the sysload info line with a fopen().

The CPU usage seems to more difficult:
CPU used by your process is available in /proc/self/stat. This is an odd-looking file consisting of a single line; for example:

19340 (whatever) S 19115 19115 3084 34816 19115 4202752 118200 607 0 0 770 384 2
7 20 0 77 0 266764385 692477952 105074 4294967295 134512640 146462952 321468364
8 3214683328 4294960144 0 2147221247 268439552 1276 4294967295 0 0 17 0 0 0 0
The important data here are the 13th and 14th tokens (0 and 770 here). The 13th token is the number of jiffies that the process has executed in user mode, and the 14th is the number of jiffies that the process has executed in kernel mode. Add the two together, and you have its total CPU utilization.
So you have to count, and measure the difference ... See http://stackoverflow.com/questions/6316 ... -a-process

I expect /proc/self/ to also give info on open pipes ... which could be interesting too.
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

Here's a code snippet I wrote that prints the VmPeak (Virtual Memory Peak usage?) after reading it from /proc/self/status.

So this could be handy on the sysload line. As with sysload, it only works on *ix system. I don't know if it work on Mac.

Code: Select all

'''
sander@R540:~/kul$ cat /proc/self/status | grep -i -e VmPeak -e VmRss
VmPeak:	    9236 kB
VmRSS:	     588 kB
sander@R540:~/kul$ 
'''

f = open('/proc/self/status', "r")
for myline in f.readlines():
	if(myline.strip().lower().find('vmpeak')>-1):
		print myline.split()[1]
f.close()
User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

And here's the 'diff -u' for sabnzbd/misc.py showing the VmPeak in the sysload bar (without using an external script)


Image

Code: Select all

--- misc.py.org	2011-07-31 12:02:54.667851903 +0200
+++ misc.py	2011-07-31 22:40:53.843213037 +0200
@@ -913,9 +913,15 @@
     if sabnzbd.WIN32 or sabnzbd.DARWIN:
         return ""
     try:
-        return "%.2f | %.2f | %.2f" % os.getloadavg()
+	f = open('/proc/self/status', "r")
+	for myline in f.readlines():
+		if(myline.strip().lower().find('vmpeak')>-1):
+			vmpeak = myline.split()[1]
+	f.close()
+	returnstring = "%.2f | %.2f | %.2f" % os.getloadavg() + ' --- ' + vmpeak + ' kB'
+	return returnstring
     except:
-        return ""
+        return "nope not good"
 
 
 def format_time_string(seconds, days=0):

User avatar
sander
Release Testers
Release Testers
Posts: 8829
Joined: January 22nd, 2008, 2:22 pm

Re: Download speed and CPU

Post by sander »

I've played further with extending the sysload info, with interesting results: even with a slow external script (including a ping) and SAB on a refresh of 2 seconds, there is ... no delay in the screen. Fascinating.

Image

And here's the "diff -u" for sabnzbd/misc.py which calls an external script. The nice thing of the external script method is that you can put in extra scripting output without changing the SAB code. So you can also use it ad-hoc debug monitoring purposes.

Code: Select all


--- misc.py.org	2011-08-04 18:32:46.643345168 +0200
+++ misc.py	2011-08-04 18:44:06.043345297 +0200
@@ -912,10 +912,25 @@
     """
     if sabnzbd.WIN32 or sabnzbd.DARWIN:
         return ""
+
     try:
-        return "%.2f | %.2f | %.2f" % os.getloadavg()
+	scriptfullname = sabnzbd.DIR_PROG + '/' + 'sysload-custom-script.sh'	#### Or: put the script in the pre/post-processing directory?
+
+	if os.path.isfile(scriptfullname):
+		# print "Yes, file exists", scriptfullname
+		customoutput = ''
+		for thisline in os.popen(scriptfullname).readlines() :
+			customoutput += ' --- ' + thisline.strip()
+	else:
+		customoutput = '--- no script found '	# This is debug info
+
+	loadavg = "%.2f | %.2f | %.2f " % os.getloadavg()
+
+	returnstring = loadavg + customoutput + " --- END"
+	return returnstring
+
     except:
-        return ""
+        return "<something went wrong>"		# This is debug info too
 
 
 def format_time_string(seconds, days=0):

and here's the external script and it's output

Code: Select all

sander@R540:~/SABnzbd-0.6.7RC1$ cat sysload-custom-script.sh 
#!/bin/sh
top -bn1 | grep Cpu | awk '{ print $2 }' | awk -F% '{ print "CPUload: " $1 "%" }' 
top -bn1 | grep SABnzbd.py | awk '{ print "SAB-CPU-percentage: " $9 "%" }'
echo -n "connections to port 8080 and 9090: "; netstat -na | grep -e :8080 -e :9090 | wc -l
echo -n "ping: "; ping -c5 -i0.2 ping.xs4all.nl | grep "packet loss"  | awk -F, '{ print $3 }'


sander@R540:~/SABnzbd-0.6.7RC1$ ./sysload-custom-script.sh 
CPUload: 4.4%
SAB-CPU-percentage: 2%
connections to port 8080 and 9090: 20
ping:  0% packet loss
sander@R540:~/SABnzbd-0.6.7RC1$ 
pmow
Release Testers
Release Testers
Posts: 57
Joined: May 15th, 2009, 6:09 pm
Location: Florida

Re: Download speed and CPU

Post by pmow »

I've also noticed a correlation between download speed and CPU - In my case, one of my sab machines is a dedicated 100mbit server with an AMD 2600+ with 1GB ram.

Sab used to download at roughtly 8-10MB/s, but lately (in the last few months) I'm getting 5-6.5MB/s speeds, with the cpus of python hitting a max of 80% and hovering around 75% (according to top). I'm running Ubuntu and Sab 0.6.6 from packages.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Download speed and CPU

Post by shypike »

Do you see significant differences between releases or is it
that performance degrades over time?
Did you upgrade Python in the course of time?
Post Reply