Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: questions regarding stack size use for multi-threaded pythonprograms

Reply
Thread Tools

Re: questions regarding stack size use for multi-threaded pythonprograms

 
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-13-2009
En Mon, 09 Nov 2009 16:05:31 -0300, Eyal Gordon <>
escribió:

> background:
> we are using python 2.4.3 on CentOS 5.3 with many threads - and our
> shell's
> default stack size limit is set to 10240KB (i.e. ~10MB).
>
> we noticed that python's Threading module appears to create threads with
> this value as their stack size (we ran a sample program that creates 10
> threads and measured its virtual memory size, then reduced the stack size
> limit of the shell to 5120KB - and saw that the program's virtual memory
> size was reduced by ~50MBs).
>
> the problem:
> our program uses numerous threads, and thus the virtual memory size gets
> to
> be very large. we would like to reduce the size of the stack to reduce
> this
> size. we were looking for information about recommendation for the stack
> size to use, but found none.


You can set the thread stack size (for threads that are going to be
created, not existing threads) using threading.stack_size(SIZE)
http://docs.python.org/library/threa...ing.stack_size

> questions:
> 1. is there some rule-of-thumb for the recommended stack size for python
> programs of various sorts?


No idea. I've been always happy with the default settings.

> 2. is there a way for us, at runtime (from inside the code or outside the
> process), to find how much of a thread's stack we are using (in KB or
> some
> other size units)?


see top(1)

> 3. when we define local objects - do the objects themselves get
> allocated on
> the stack - or are they allocated on the heap and only references to them
> are kept on the stack?


They're allocated on the heap, and most references to objects are on the
heap too. The Python stack of execution frames is allocated on the heap
too. Basically, the OS stack is used for local variables in C code only.

> 4. would the size of the stacks (which are probably not really allocated
> by
> the linux virtual memory sub-system, unless used) have a noticeable
> performance effect on a python program? same question regarding the use
> of a
> large number of threads?


I think it doesn't matter, unless you create so many threads as to exhaust
the available addressing space (in 32bits, 4GB address space and 10MB per
thread means 400 threads maximum).

--
Gabriel Genellina

 
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
Re: questions regarding stack size use for multi-threaded pythonprograms Andrew MacIntyre Python 0 11-14-2009 12:57 AM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
Can we determine stack size & Heap size at runtime ? sunny C Programming 5 08-17-2006 12:17 AM
question regarding stack size allocation ronjon C Programming 2 12-30-2004 05:39 AM



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