Closed bac7d3ea-3f1b-4826-8464-f0b53d5e12d2 closed 14 years ago
Description changed:
---
+++
@@ -3,16 +3,19 @@
* top() - Display the output of the 'top' command for the current process.
* get_memory_usage() - Display the memory usage in MB.
-The implementation on Solaris is particularly poor for many reasons.
-* The Sage function 'top()' calls the external command 'top' on Solaris, despite the fact that 'top' has never been part of the Solaris operating system. (The command has to be installed, but is not standard.)
-* The Sage function get_memory_usage() calls the function top(), so obviously breaks get_memory_usage() fails if the command 'top' is not installed.
-* 'top' is not very accurate on modern Solaris versions - is was OK 10+ years ago, but not now.
+The Sage implementation of top() and get_memory_usage() on Solaris are particularly poor for many reasons.
+
+* The Sage function 'top()' calls the external command 'top' on Solaris, despite the fact that 'top' has never been part of the Solaris operating system. ('top' can be installed, but it is not standard.)
+* The Sage function get_memory_usage() calls the function top(), so obviously get_memory_usage() fails if the command 'top' is not installed.
+* 'top' is not very accurate on modern Solaris versions - it was OK 10+ years ago, but not now.
* You need root access to install 'top'.
* The ticket #6028 created by Micheal Abshoff with the title "get_memory_usage() sucks performance wise on Solaris" gives a gentle hint at one more problem.
-* Running the Sage doctests brings a system to an almost standstill if top is not installed. The non-existent 'top' is run multiple times in a loop in an attempt to overcome some race condition.
-* I believe not having 'top' is causing doctest failures, which brings the system to an almost standstill as documented at #7153.
+* I believe not having 'top' is causing doctest failures, which brings the system to an almost standstill as documented at #7153.
+Even having it causes failures, as noted above.
-**Overall, the usage of 'top' in Solaris is a disaster.** The proper way to get the memory usage is to use a system call, but it is going to take some effort to sort out how to do so and is not high on the list of priorities.
+**Overall, the usage of 'top' in Solaris is a disaster.**
+
+The proper way to get the memory usage is to use a system call, but it is going to take some effort to sort out how to do so and is not high on the list of priorities.
A command with similar functionality to 'top', but greater accuracy is '/usr/bin/prstat' which comes as part of all recent versions of Solaris. The output looks similar to that of 'top'
Here is the output of an modified version of Sage 4.4.3, where top is not installed. The modifications were only to get Sage to build at this point. The hardware is a Sun Blade 1000 with 2 GB RAM.
top() reports that 'top' is not found, and get_memory_usage() goes into an infinite loop. If you look at the source code, you can see why the infinite loop exists.
-bash-3.00$ ./sage
----------------------------------------------------------------------
| Sage Version 4.3.3, Release Date: 2010-02-21 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: top()
sh: top: not found
''
sage: get_memory_usage()
sh: top: not found
sh: top: not found
sh: top: not found
sh: top: not found
Here is the output of the same two commands with the changes I will soon attach.
drkirkby@redstart:~/fresh/sage-4.3.3$ ./sage
----------------------------------------------------------------------
| Sage Version 4.3.3, Release Date: 2010-02-21 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: top()
'25519 drkirkby 164M 91M sleep 59 0 0:00:07 9.2% python/1'
sage: get_memory_usage()
91.0
The program 'top' is not installed - instead prstat is used to get the information. I also expanded the information someone gets when using help(top) or help(get_usage_message) - see below.
sage: help(top)
Help on function top in module sage.misc.getusage:
top()
Return the 'top' or 'prstat' line that contains this running
Sage process.
EXAMPLES:
sage: top() # random output
'72373 python 0.0% 0:01.36 1 14+ 1197 39M+ 34M+ 55M+ 130M+'
NOTES:
The external command 'top' (http://www.unixtop.org/) is called on Linux,
and most other operating systems. The output format of 'top' is not
consistent across all platforms and all versions of 'top'. If the
top() function does not work in Sage, you may need to install 'top'.
The external command 'prstat' is called on the Solaris and OpenSolaris
systems. That is part of Solaris, and will not need to be installed. The
columns used in the 'prstat' output are:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
sage: help(get_memory_usage)
Help on function get_memory_usage in module sage.misc.getusage:
get_memory_usage(t=None)
Return memory usage.
INPUT:
- ``t`` - None or output of previous call; (only used
on Linux)
OUTPUT:
- ``Linux`` - Returns float number (in megabytes)
- ``OS X`` - Returns float number (in megabytes) that matches VSIZE column of 'top'
- ``Solaris or OpenSolaris`` - Returns float number (in megabytes) that matches RSS
column of 'prstat'. Depending on the memory usage, 'prstat' will output the
data in KB, MB or GB. In each case, the value returned by this function will
always be in MB.
- ``other`` - not implemented for any other operating systems
EXAMPLES:
We test that memory usage doesn't change instantly::
sage: t = get_memory_usage()
sage: get_memory_usage(t) # amount of memory more than when we defined t.
0.0
NOTES:
Currently get_memory_usage() calls ''prstat' (Solaris and
OpenSolaris) to get the data it requires. In the long term,
a better solution would be to use Solaris system calls.
In some instances, 'top' may be used on OS X. This may break
if the memory usage is greater than 9999 MB. However, normally
'top' is not used on OS X.
sage:
Mercurial patch
Attachment: top-to-prstat.patch.gz
I'm removing the 'temporary and ugly fix' from the title, as this actually works quite well now.
Author: David Kirkby
Attachment: trac_8391-prstat_solaris.patch.gz
Use prstat
instead of top
on (Open)Solaris. Docstring tweaks.
I've attached an updated patch with minor (mostly docstring) tweaks. Please see the developer's guide for useful tips and recommendations.
Just to double check: Is the multiplier / divisor definitely not 1024?
Attachment: trac_8391-prstat_solaris-multiply-divide=1024.patch.gz
Updated with multipy/divide=1024. I could not overwrite the original
Thank you for the tip. You are correct of course, the conversion from KB -> MB ->GB should use multipliers of 1024, not 1000. I don't know what I was thinking then.
I was unable to overwrite the ticket, but instead got the message
"ATTACHMENT_DELETE privileges are required to perform this operation on Attachments of Ticket #8391'
So I created this with a new file name.
Reviewer: Jaap Spies
Looks good to me. This effects (Open) Solaris only.
I'll give a positive review.
Jaap
Merged: sage-4.3.4.alpha1
The file 'getusage.py' has two main functions.
The Sage implementation of top() and get_memory_usage() on Solaris are particularly poor for many reasons.
Overall, the usage of 'top' in Solaris is a disaster.
The proper way to get the memory usage is to use a system call, but it is going to take some effort to sort out how to do so and is not high on the list of priorities.
A command with similar functionality to 'top', but greater accuracy is '/usr/bin/prstat' which comes as part of all recent versions of Solaris. The output looks similar to that of 'top'
Hence I propose to replace the call to 'top' with one to 'prstat'. Despite I know this is not the correct way to determine memory usage, using 'prstat' is at least better than the current implementation using 'top'
Component: porting: Solaris
Author: David Kirkby
Reviewer: Jaap Spies
Merged: sage-4.3.4.alpha1
Issue created by migration from https://trac.sagemath.org/ticket/8391