Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > limiting memory consumption of Python itself or a dict in a Python program

Reply
Thread Tools

limiting memory consumption of Python itself or a dict in a Python program

 
 
Jonas Maurus
Guest
Posts: n/a
 
      09-19-2007
Hello everybody,

I'm pondering the following problem:

I want to write a Python program that receives messages via SMTP and
stores them in a dict or an array. For my purposes it would be
important that all received mail would be kept in RAM and not cached
out to disk. If a new message comes in that can't fit in the allocated
memory, a number of old messages would be discarded.

As the server needs to have room for other tasks, I'd like to limit
the overall memory consumption to a certain amount.

Is this possible? How would I go about implementing it? By imposing
"ulimit"s and catching MemoryError?

Thanks for your help,
Jonas

 
Reply With Quote
 
 
 
 
Kay Schluehr
Guest
Posts: n/a
 
      09-20-2007
On 19 Sep., 22:48, Jonas Maurus <jonas.mau...@gmail.com> wrote:
> Hello everybody,
>
> I'm pondering the following problem:
>
> I want to write a Python program that receives messages via SMTP and
> stores them in a dict or an array. For my purposes it would be
> important that all received mail would be kept in RAM and not cached
> out to disk. If a new message comes in that can't fit in the allocated
> memory, a number of old messages would be discarded.
>
> As the server needs to have room for other tasks, I'd like to limit
> the overall memory consumption to a certain amount.
>
> Is this possible? How would I go about implementing it? By imposing
> "ulimit"s and catching MemoryError?
>
> Thanks for your help,
> Jonas


When your application pre-allocates a chunk of memory and use
datatypes like array and struct you might write your own memory
manager. You can't control the total memory consumption of Python
though, since Python implements an own malloc and it might allocate
memory in large chunks. But this is somewhat orthogonal to your
problem and applies also when Python reads/writes buffers from/to
disk.

 
Reply With Quote
 
 
 
 
Jeremy Sanders
Guest
Posts: n/a
 
      09-20-2007
Jonas Maurus wrote:

> I want to write a Python program that receives messages via SMTP and
> stores them in a dict or an array. For my purposes it would be
> important that all received mail would be kept in RAM and not cached
> out to disk. If a new message comes in that can't fit in the allocated
> memory, a number of old messages would be discarded.
>
> As the server needs to have room for other tasks, I'd like to limit
> the overall memory consumption to a certain amount.


Since your data is all in one place, why not write a dict or list wrapper
which keeps track of the total space of the items stored (using len on the
strings)?

It could automatically clean out old entries when the memory usage becomes
too much.

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
6500: User-Based Rate Limiting AND Total Rate Limiting Patrick Cervicek Cisco 0 08-07-2007 03:07 PM
Debugging Memory consumption for Perl Program janicehwang1325@yahoo.com Perl Misc 2 06-30-2006 01:07 AM
dict!ident as equivalent of dict["ident"] Alexander Kozlovsky Python 5 05-22-2006 08:06 AM
How to calculate the CPU time consumption and memory consuption of any python program in Linux Shahriar Shamil Uulu Python 5 12-24-2005 08:29 PM
Re: dict->XML->dict? Or, passing small hashes through text? Skip Montanaro Python 0 08-15-2003 03:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57