[Python-Dev] Different cpu python code usage between embedded mode and standalone mode

Guido van Rossum guido at python.org
Sat Jun 7 19:27:07 CEST 2008


This is not an issue for python-dev, but I have to ask: what do you
mean by "embedded mode"?

On Sat, Jun 7, 2008 at 10:14 AM, Pau Freixes <pfreixes at gmail.com> wrote:
> Hi list,
>
> First Hello to all, I have a serious problem for understand some results
> when I'm comparing cpu usages between same python code in embedded mode and
> standalone mode ( python name_script.py )
>
> This last months I have been writing a  program in c like to mod_python for
> embedding python language, it's a middleware for dispatch and execute python
> batch programs into several nodes. Now I'm writing some python program for
> test how scale this into several nodes and comparing with "standalone"
> performance.
>
> I found a very strange problem with one application named md5challenge, this
> aplication try to calculate the max number md5 digest in several seconds,
> md5challenge use a simple signal alarm for stop program when time has
> passed. This is the code of python script
>
> _nrdigest = 0
> _const_b = 20
> _f = None
> _signal = False
>
>
> def handler_alrm(signum, frame):
>     global _signal
>     global _nrdigest
>     global _f
>
>
>     _signal = True
>
> def try_me():
>     global _nrdigest
>     global _f
>     global _signal
>
>     _f = open("/dev/urandom","r")
>     while _signal is not True:
>         buff = _f.read(_const_b)
>         md5.md5(buff).hexdigest()
>         _nrdigest = _nrdigest + 1
>
>     if _f is not None :
>         _f.close()
>
> # Define entry point with one input variable
> # req is a instance of Request object, usefull members of this object are:
> # req.input is a dictionary with input.xml variables
> # req.constants is a dictionary with constants defined into signature.xml
> # req.output is void dictionary for full with output variables
> # req.config is a dictionary with config values take from namespace
> # req.apdn_pid is a pid of aplication
>
>
> def main( req ):
>     global _nrdigest
>
>
>     signal.signal(signal.SIGALRM, handler_alrm)
>     signal.alarm(req.input['time'])
>
>     try_me()
>
>     req.output['count'] = _nrdigest
>
>     return req.OK
>
>
> if __name__ == "__main__":
>
>     # test code
>     class test_req:
>         pass
>
>     req = test_req()
>     req.input = { 'time' : 10 }
>     req.output = { 'ret' : 0, 'count' : 0 }
>     req.OK = 1
>
>     main(req)
>
>     print "Reached %d digests" % req.output['count']
>
>
> When I try to run this program in standalone into my Pentium Dual Core
> md5challenge reached 1.000.000 milion keys in 10 seconds but when i try to
> run this code in embedded mode md5challenge reached about 200.000 more keys
> !!! I repeat this test many times and  always  wins  embedded mode  !!!
> What's happen ?
>
> Also I tested to erase read dependencies from /dev/random, and calculate all
> keys from same buffer. In this case embedded mode win always also, and the
> difference are more bigger !!!
>
> The alarm time expires in both case in 10 seconds.
>
> Thks to all, can anybody help to me for understand this results ?
>
> --
> Pau Freixes
> Linux GNU/User
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list