sys.setcheckinterval query

A

Anand Pillai

Quoting from documentation on sys module in python
standard documentation.

"""
setcheckinterval(interval)
Set the interpreter's ``check interval''. This integer value
determines how often the interpreter checks for periodic things such
as thread switches and signal handlers. The default is 10, meaning the
check is performed every 10 Python virtual instructions. Setting it to
a larger value may increase performance for programs using threads.
Setting it to a value <= 0 checks every virtual instruction,
maximizing responsiveness as well as overhead.
"""
I have a program that uses multiple threads. Is there any direct
correlation
between the number of threads my program might spawn and the value of
ther
'interval' variable.

I am interested in the last but one statement which says, "Setting it
to a larger value may increase performance for programs using
threads.". So my question is what would that value be? How can I find
out the number of
python 'virtual instructions' for every function I have?

Thanks

~Anand
 
P

Peter Hansen

Anand said:
"""
setcheckinterval(interval)
Set the interpreter's ``check interval''. This integer value
[...]
"""
I am interested in the last but one statement which says, "Setting it
to a larger value may increase performance for programs using
threads.". So my question is what would that value be? How can I find
out the number of python 'virtual instructions' for every function I have?

Do you really want to waste time optimizing at such a level? I suspect
it's very unlikely you will notice any difference other than with
order-of-magnitude changes. In other words, it's normally every 10
instructions, but if you change it to 100 or 1000 you could notice a
difference. (Zope sets the checkinterval to 120 (in the version I checked),
but I think I'd be surprised if 100 or 140 turned out much different.
Trying to "tune" it to, say 27, or 73, or something would be sheer insanity.

If you need better performance than what you are getting, find your
bottlenecks by profiling and optimize there, or write a C extension,
or use Pyrex, or Psycho or something.

(To find the number of bytecode instructions, use module "dis", BTW.)

-Peter
 
A

Aahz

"""
setcheckinterval(interval)
Set the interpreter's ``check interval''. This integer value
determines how often the interpreter checks for periodic things such
as thread switches and signal handlers. The default is 10, meaning the
check is performed every 10 Python virtual instructions. Setting it to
a larger value may increase performance for programs using threads.
Setting it to a value <= 0 checks every virtual instruction,
maximizing responsiveness as well as overhead.
"""

Note that Python 2.3 changes the default to 100, so be careful about
hard-coding anything.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top