[Stackless] GIL issue? Re: Santa concurrency problem
Brian Zimmer
bzimmer at ziclix.com
Fri Mar 30 21:21:17 CEST 2007
The implementation of time.sleep for Linux in timemodule.c uses the
system call select to implement sleep. Before calling select the macro
Py_BEGIN_ALLOW_THREADS is used to allow other threads to run.
So without calling time.sleep in the tasklet thread the constant
running of the sleep tasklet starves all other threads. When you add
the very small sleep other threads get a chance to run. Your cpu is
still pinned because of another busy wait you mentioned.
It doesn't look like Python's thread module exposes a yield but I know
in Java I've had to do this in some very tight loops (especially with
NIO). So in essence, at least to my understanding, the
time.sleep(0.001) is the functional equivalent of thread.yield().
I'd appreciate someone more knowledgeable either confirming or denying
this information.
thanks, brian
On Mar 30, 2007, at 10:18 AM, Andrew Francis wrote:
> Hello Christian, Richard, Brian and Colleagues:
>
> On 28.03.2007, at 19:45, Brian Zimmer wrote:
>
>> I removed all the wxPython code but it still
> exhibits >the same behaviour as the original sleep in
> that it >pins a cpu in a busy wait. The best overall
> solution >appears to be (in my limited understanding
> of
>> Stackless) the tiny sleep 0.001 seconds because it
>> doesn't appear to significantly change the behaviour
>> of the application and keeps the stackless process
> out >of the top spot in top.
>
> Christian Tismer :
>
>> Ah, sure. In that code, I didn't try to save cycles,
>> but to provide rather exact timing. Of course the
> tiny >sleep makes sense.This application had always
> lots of >work, so this was not an issue.
>
> (File under Brainstorming)
>
> Once again, I ran into my long time problem of "losing
> deferreds." This was despite redesigning my
> application to run Twisted in a separate thread.
>
> I noticed that an earlier example using the
> Twisted-in-a-separate-thread approach that worked had
> a time.sleep(). So I placed a time.sleep(.001) into my
> code, and it worked. Since my code also implemented a
> tight loop with most of the tasklets blocked, I
> checked the CPU : it was at 100%.
>
>> From a previous thread involving Carlos, I commented
> that the time.sleep() has a significance besides
> sleeping. time.sleep() will also release the GIL. In
> my case, the Twisted component could do its stuff.
>
> I don't know if my problem and the time.sleep in the
> Santa concurrency are somehow related. Since it seems
> the GIL plays a role in my application, I am
> interested in optimizing its performance with
> Stackless. Can anyone provide some insights?
>
> Cheers,
> Andrew
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________________________________
> _____________
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> http://answers.yahoo.com/dir/?link=list&sid=396546091
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list