emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Concurrency, again


From: Daniel Colascione
Subject: Re: Concurrency, again
Date: Thu, 27 Oct 2016 14:50:06 -0700
User-agent: K-9 Mail for Android


On October 27, 2016 1:55:02 PM PDT, Christopher Allan Webber <address@hidden> 
wrote:
>Daniel Colascione writes:
>
>> On 10/27/2016 10:27 AM, Eli Zaretskii wrote:
>>>> From: Philipp Stephani <address@hidden>
>>>> Date: Tue, 25 Oct 2016 23:28:51 +0000
>>>>
>>>> I've pushed the experimental branch to 'concurrency-libtask'. It's
>essentially a simple wrapper around libtask,
>>>> which implements CSP based on setcontext. I've also implemented a
>Windows equivalent based on
>>>> Windows native fibers, but haven't tried that yet.
>>>
>>> Thanks.
>>>
>>> Could you perhaps summarize the relative advantages and
>disadvantages
>>> of the two concurrency branches?  Your branch doesn't have any
>>> documentation besides doc strings of the new primitives, so it's not
>>> easy to grasp the high-level picture by looking at the details.
>>>
>>> One issue that bothers me is whether it's wise to use libtask here,
>>> because the changes you did there seem to imply that we will have to
>>> maintain the library (which is pretty low-level stuff) as part of
>>> Emacs.  Isn't using system threads better?
>>
>> Agreed on system threads vs libtask. Fibers of the sort libtask
>provides 
>> (similar to GNU Pth) have some claimed advantages in efficiency in
>large 
>> programs with lots of concurrent tasks, but for us, I vote for 
>> Python-style use of OS threads with a Python-style GIL that we can 
>> release to do long-running computations and recover from parallelism.
>
>Python's GIL + threading is probably not the best model to work off
>of... while the GIL is largely misunderstood, there have been a lot of
>challenges with getting this model to work nice.  At one point, it
>turned out that the GIL + threads would result in constant CPU
>thrashing.  This isn't the case any more, but it was once, and was a
>challenging thing to fix:
>
>  http://dabeaz.com/python/UnderstandingGIL.pdf
>
>Even now, my understanding is that Python does a ton of context
>switching, and while it's better than it was, you don't really get a
>lot
>of the performance you would over threads being used in other systems,
>because it's hard for Python to really run things concurrently.  Thus
>the rise of things like asyncio, where instead of parallelizing, you
>break things into a lot of coroutines which don't block on any IO.

Of course they block on IO, in their own terms. On a different level of 
abstraction, they're non blocking. They are exactly as blocking as OS's 
threads, except you're doing the work the OS already does, and probably better, 
at least at Emacs scale.

I favor maintainability and developer familiarity over raw performance. If 
we're merely as successful as Python, I don't think I'll be terribly unhappy 

>
>Other mechanisms like green threading + coroutines for most IO bound
>async stuff and, in the case that you need CPU bound stuff to be
>optimized, something that spawns independent processes (or okay, maybe
>threads) that communicate with message passing is probably much better
>than a GIL + system threads route, I'd think

The numpy approach helps for the odd truly compute bound task. You can 
implement message passing on top of a GIL system.

I understand you as claiming that a green thread system is more powerful than a 
real thread system. Can you see how? From where I'm standing, it has the same 
limitations *and* it's harder to release the GIL and do something heavy like 
JPEG decoding.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]