Simone Margaritelli
Simone Margaritelli

Reputation: 4733

Any way to lower Python memory footprint?

i'm developing a python 2.6 (tested both on 2.6.5 and 2.6.6) application which is going to run as a daemon on my VPS. During some tests, i've found out that the app itself it's consuming (during its sleep time, so no activities or allocations whatsoever) about 37.53MB of memory. I i've spent the last few hours optimizing the code to reduce the app memory footprint but i miserably failed XD

I'm using this line of bash code to get the memory used by my app:

ps u -p $(pidof python) | awk 'NR > 1 {nm += $5} END {print nm * 1024}'

*(Yes, im sure i have only that one python instance running ;))*

So, just to be sure i was not goin to waste my time, i ran just a python interpreter session (no script, no args, no modules loaded) and with the same script i use to get the memory consumed by it ... you know what?

It's almost the same as my entire app!

So, there's any way to reduce the python interpreter memory footprint? I even tried to set the gc threshold to 3 for the first generation and then call gc.collect() in safe places of my app ... but nothing changed :(

Upvotes: 1

Views: 1629

Answers (1)

Yann Ramin
Yann Ramin

Reputation: 33177

Are you sure you are not reading the Python virtual memory?

Python here consumes 3.4MB of private memory.

Upvotes: 1

Related Questions