python - Strange behavior of psutil -
i'm using library psutil python 2.7.
consider small program :
import os import psutil # return memory usage in mb process = psutil.process(os.getpid()) print process.memory_info().rss / float(2 ** 20)
the memory informations returned program different. can't understand how application, doing time same stuff (here, pretty nothing) cannot have same memory footprint @ each execution.
example (each line different execution) :
- 10.37109375
- 10.37109375
- 10.359375
- 10.41015625
- 10.4140625
- 10.30078125
am missing here ?
measuring memory occupation taking picture of in movement. ps utils not see same size of script+variables, of parts not visible. classes instantiated , destroyed. variables allocated, freed again.
as documentation says, 'garbage' collector common dynamically typed languages such python, runs @ times not synchronous measuring interval, see variations.
worrysome if memory footprint increasing continually - in case we'd have memory 'leakage' (eg. happen if there recursive call occupying ever-increasing resources).
the times program behaves predictably long on (unless write programs microcontrollers). programs run in multitasking environments, programs , operating system continually (and simultaneously) fighting computer's resources.
but modern programs, such python
, ruby
, perl
, others, don't act same each execution. influenced memory have available (which varies because of other programs running).
and mind, it's not 5-line program testing. take line process = psutil.process(os.getpid())
. calls os.getpid(), calls operating system's getpid()
. result goes psutil.process
calls few hundred lines of code. finally, innocent-looking process =
has call memory manager reserve memory process
, , transfer result there...
Comments
Post a Comment