Hi Gabriel,<br><br>The source code for embedded mode it's the same, look this code :<br><br>_nrdigest = 0<br>_const_b = 20<br>_f = None<br>_signal = False<br><br><br>def handler_alrm(signum, frame):<br>    global _signal<br>
    global _nrdigest<br>    global _f<br><br><br>    _signal = True<br><br>def try_me():<br>    global _nrdigest<br>    global _f<br>    global _signal<br><br>    _f = open("/dev/urandom","r")<br>    while _signal is not True:<br>
        buff = _f.read(_const_b)<br>        md5.md5(buff).hexdigest()<br>        _nrdigest = _nrdigest + 1<br><br>    if _f is not None : <br>        _f.close()<br><br># Define entry point with one input variable<br># req is a instance of Request object, usefull members of this object are:<br>
# req.input is a dictionary with input.xml variables<br># req.constants is a dictionary with constants defined into signature.xml<br># req.output is void dictionary for full with output variables<br># req.config is a dictionary with config values take from namespace<br>
# req.apdn_pid is a pid of aplication<br><br><br>def main( req ):<br>    global _nrdigest<br><br><br>    signal.signal(signal.SIGALRM, handler_alrm)<br>    signal.alarm(req.input['time'])  <br><br>   <br>    try_me()<br>
<br>    req.output['count'] = _nrdigest<br><br>    return req.OK<br><br><br>if __name__ == "__main__":<br>    <br>    # test code<br>    class test_req:<br>        pass<br>    <br>    req = test_req()<br>
    req.input = { 'time' : 10 }<br>    req.output = { 'ret' : 0, 'count' : 0 }<br>    req.OK = 1<br><br>    main(req)<br><br>    print "Reached %d digests" % req.output['count']<br>
<br>When this code it's run into embeded mode the main function it's called automatically form  one  c code with PyObject_CallObject function, and Request object it's build into c code. When you run this code into "standalone" or tradicional method with bash, the main function it's called from "main(req)" call.<br>
<br>I know the cost of search for global variable it's more bigger than local variable, but this cost it's the same for emedded mode and standalone mode :), and the same for read urandom. And read urandom don't have a lock implicit - the const_b is 20 bytes.<br>
<br>My problem it's that don't understand because the same program run into embedded mode or in bash mode have a different results !!! what do you think about this ? may be a GIL ?<br><br><br>PD: no seguro que no llego :), a ver si alguien mas se apunta a la discusion !<br>
<br><div class="gmail_quote">On Wed, Jun 4, 2008 at 4:45 AM, Gabriel Genellina <<a href="mailto:gagsl-py2@yahoo.com.ar" target="_blank">gagsl-py2@yahoo.com.ar</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

En Tue, 03 Jun 2008 16:58:12 -0300, Pau Freixes <<a href="mailto:pfreixes@milnou.net" target="_blank">pfreixes@milnou.net</a>> escribió:<div><div></div><div><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi list,<br>
<br>
First Hello to all, this is my and hope not end message to the list :P<br>
<br>
This last months I have been writting a  program in c like to mod_python for<br>
embedding python language, it's a middleware for dispatch and execute python<br>
batch programs into several nodes. Now I'm writing some python program for<br>
test how scale this into several nodes and comparing with "standalone"<br>
performance.<br>
<br>
I found a very strange problem with one application named md5challenge, this<br>
aplication try to calculate the max number md5 digest in several seconds,<br>
md5challenge use a simple signal alarm for stop program when time has<br>
passed. This is the code of python script<br>
<br>
def handler_alrm(signum, frame):<br>
    global _signal<br>
    global _nrdigest<br>
    global _f<br>
<br>
<br>
    _signal = True<br>
<br>
def try_me():<br>
    global _nrdigest<br>
    global _f<br>
    global _signal<br>
<br>
    _f = open("/dev/urandom","r")<br>
    while _signal is not True:<br>
        buff = _f.read(_const_b)<br>
        md5.md5(buff).hexdigest()<br>
        _nrdigest = _nrdigest + 1<br>
<br>
    if _f is not None :<br>
        _f.close()<br>
<br>
def main( req ):<br>
    global _nrdigest<br>
<br>
<br>
    signal.signal(signal.SIGALRM, handler_alrm)<br>
    signal.alarm(req.input['time'])<br>
<br>
<br>
    try_me()<br>
<br>
    req.output['count'] = _nrdigest<br>
<br>
    return req.OK<br>
<br>
<br>
if __name__ == "__main__":<br>
<br>
    # test code<br>
    class test_req:<br>
        pass<br>
<br>
    req = test_req()<br>
    req.input = { 'time' : 10 }<br>
    req.output = { 'ret' : 0, 'count' : 0 }<br>
    req.OK = 1<br>
<br>
    main(req)<br>
<br>
    print "Reached %d digests" % req.output['count']<br>
<br>
<br>
When I try to run this program in standalone into my Pentium Dual Core<br>
md4challenge reached 1.000.000 milion keys in 10 seconds but when i try to<br>
run this in embedded mode md5challenge reached about 200.000 more keys !!! I<br>
repeat this test many times and  always  wins  embedded mode  !!!  What's<br>
happen ?<br>
<br>
Also I tested to erase read dependencies from /dev/random, and calculate all<br>
keys from same buffer. In this case embedded mode win always also, and the<br>
difference are more bigger !!!<br>
<br>
Thks to all, can anybody help to me ?<br>
</blockquote>
<br></div></div>
So the above code corresponds to the standalone version - what about the embedded version? Are you sure it is exactly the *same* code? All those global statements are suspicious, and you don't even need most of them. Note that looking up a name in the global namespace is much slower than using a local name.<br>


Also, you're including the time it takes the OS to *generate* several megabytes of random data from /dev/urandom (how big is _const_b?).<br>
Usually it's easier (and more accurate) to measure the time it takes to compute a long task (let's say, how much time it takes to compute 1000000 md5 values). You're doing it backwards instead.<br>
I'd rewrite the test as:<br>
<br>
def try_me():<br>
  from md5 import md5<br>
  buff = os.urandom(_const_b)<br>
  for i in xrange(1000000):<br>
    md5(buff).hexdigest()<br>
<br>
def main(req):<br>
  t0 = time.clock()<br>
  try_me()<br>
  t1 = time.clock()<br>
  # elapsed time = t1-t0<br>
<br>
<br>
PS: Recuerdo que respondí esto en la lista de Python en castellano, pero ahora veo que mi mensaje nunca llegó :(<br>
<br>
-- <br>
Gabriel Genellina<br><font color="#888888">
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Pau Freixes<br>Linux GNU/User