tag:blogger.com,1999:blog-8935780327334775165.post6408975310896982413..comments2023-08-07T22:48:57.800+08:00Comments on Entity Crisis: CPython Threading is Fundamentally Broken.Unknownnoreply@blogger.comBlogger14125tag:blogger.com,1999:blog-8935780327334775165.post-51759045765390221242009-06-20T17:12:47.503+08:002009-06-20T17:12:47.503+08:00Seun, you can see from my other posts that I'v...Seun, you can see from my other posts that I've noted the same results.<br /><br />I agree that a greater tick interval mitigates the problem.<br /><br />However, a greater tick interval simply pushes multithreading closer to sequential execution. This is the same thing as saying: "My multi-threaded program is slow, but my sequential program is fast. Therefore, I can make my multi-threaded program faster by making it more sequential."<br /><br />It sounds rather silly when you think about it like that.Simon Wittberhttps://www.blogger.com/profile/02730025645144151014noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-26183889801600353542009-06-20T05:14:37.116+08:002009-06-20T05:14:37.116+08:00Actually, it's not that bad. The 'slowdow...Actually, it's not that bad. The 'slowdown' disappears when you set sys.setcheckinterval(n) to a sane value. If you're not convinced, take a peek at my <a href="http://seun-python.blogspot.com/2009/06/gil.html" rel="nofollow">benchmark results</a>.Seun Osewahttps://www.blogger.com/profile/11257184260827538727noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-62682153000609116382009-06-17T21:32:02.453+08:002009-06-17T21:32:02.453+08:00I'm intrigued as to why the GIL is considered ...I'm intrigued as to why the GIL is considered so difficult to remove in CPython when IronPython seems to not have it. What safety is the .NET runtime providing, and at what cost?Ben Sizerhttps://www.blogger.com/profile/16973645498493273495noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-90716601439407463572009-06-15T08:49:04.090+08:002009-06-15T08:49:04.090+08:00Just to be clear, it's important to stress tha...Just to be clear, it's important to stress that my talk was about a very specific aspect of thread-programming involving CPU-bound processing. This obviously doesn't apply to every conceivable use of threads. For instance, if everything is I/O bound, you won't run into the problems I described. So, to say that threading is fundamentally broken is probably a bit extreme.<br /><br />However, I think there is a class of problems where threads will be used with a certain mix of CPU-bound processing--even in applications with a lot of I/O. It's hard to say how the GIL impacts these applications, but it's probably worthy of some further study.<br /><br />If anything, I think the main take-away from the talk should be just how difficult the underlying problem of the GIL really is--especially when multiple cores enter the picture. It will be interesting to see what the unladen swallow guys have up their sleeve.David Beazleyhttp://www.dabeaz.comnoreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-2340573989150165272009-06-14T09:54:44.146+08:002009-06-14T09:54:44.146+08:00You might also be interested in David's talk, ...You might also be interested in David's talk, which he did at the ChiPy meeting this past Thursday. There's a bit more detail in his explanation than what you might get directly from the slides:<br /><br />http://blip.tv/file/2232410<br /><br />(props to Carl Karsten and Cosmin Stejerean for recording and getting the video up quickly :-)James Snyderhttp://fanplastic.org/noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-64522517442255223802009-06-13T23:28:05.327+08:002009-06-13T23:28:05.327+08:00@Michael: Right, just to be clear I'm not sugg...@Michael: Right, just to be clear I'm not suggesting green threads are useful for solving problems which require genuine concurrency. <br /><br />However, Stackless does have features which force a tasklet to yield after a number of ticks, which appears to be very similar to how regular Python works.Simon Wittberhttps://www.blogger.com/profile/02730025645144151014noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-13560242314873126922009-06-13T22:52:18.912+08:002009-06-13T22:52:18.912+08:00The green threading provided by stackless is not s...The green threading provided by stackless is not suitable for applications with very coarse grained units of work (i.e. nowhere suitable to yield to the other threads).<br /><br />Thankfully the threading code I've written has been in IronPython, where we don't have the GIL, but the project I've been working on would be severely hampered by the GIL if we had started in CPython. (Threads are used on large shared datasets so multi-processes aren't suitable.)Michael Foordhttps://www.blogger.com/profile/06229713779852499022noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-28002617731631379602009-06-13T10:44:36.670+08:002009-06-13T10:44:36.670+08:00@Jesse: I understand what you are saying, its true...@Jesse: I understand what you are saying, its true, we always knew that there was _some_ slowdown. What astounded me from the slides was the way the problem grew exponentially as more cores were added.<br /><br />This is pretty fatal for threading in CPython.Simon Wittberhttps://www.blogger.com/profile/02730025645144151014noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-28147356869032454182009-06-13T10:43:17.264+08:002009-06-13T10:43:17.264+08:00@manuelg: Agreed. Thats exactly what Stackless pro...@manuelg: Agreed. Thats exactly what Stackless provides. Application controlled threading, built into the language runtime.Simon Wittberhttps://www.blogger.com/profile/02730025645144151014noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-67636546613394275332009-06-13T10:04:37.870+08:002009-06-13T10:04:37.870+08:00Thanks for the slides, they are great! Now I have ...Thanks for the slides, they are great! Now I have something to link to when telling people to not use threads in python.nosklohttps://www.blogger.com/profile/12957911527688631560noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-22408878507020060602009-06-13T07:06:11.864+08:002009-06-13T07:06:11.864+08:00It's a good thing that Google is helping us ge...It's a good thing that Google is helping us get rid of the GIL then: <a href="http://code.google.com/p/unladen-swallow/wiki/ProjectPlan" rel="nofollow">Unladen Swallow Project Plan</a>Ycroshttps://www.blogger.com/profile/15215756393733527513noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-69507348978800535542009-06-13T05:47:01.943+08:002009-06-13T05:47:01.943+08:00Technically, 1 misplaced "nonexistant_needle ...Technically, 1 misplaced "nonexistant_needle in big_haystack" statement could bring any _single_ _threaded_ process to its knees (forgetting to update an index variable in a loop, for instance). That is the nature of coding, multi or single threaded or whatnot. But you knew that already.<br /><br />It would be nice to have support for "green threads" for CPU bound threading, on top of GIL/OS-threads for IO bound threading. The green threads would run in a single process, and multiple process support would have to be explicitly (for exampling, importing a module like "multiprocessing"), depending on the size and nature of the shared state of the threads.manuel moe ghttps://www.blogger.com/profile/04878149837118503541noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-19083120331164846792009-06-13T05:12:24.670+08:002009-06-13T05:12:24.670+08:00@Jesse,
It appears from the slides that even 1 CP...@Jesse,<br /><br />It appears from the slides that even 1 CPU bound thread could potentially kill the performance for IO bound threads and cause lots of signal noise between threads as the OS tries to give the IO threads priority but the GIL refuses to give up on the CPU bound thread.<br /><br />So it sounds like 1 misplaced "nonexistant_needle in big_haystack" statement could bring an otherwise IO bound multithreaded process to its knees.schmichaelhttps://www.blogger.com/profile/09052666448496490147noreply@blogger.comtag:blogger.com,1999:blog-8935780327334775165.post-61595271467133313162009-06-13T03:16:12.066+08:002009-06-13T03:16:12.066+08:00Simon; his slides only show CPU bound execution, a...Simon; his slides only show CPU bound execution, and everyone already knew adding threads to CPU bound apps within python caused a slowdown.<br /><br />However, adding threads to I/O bound applications still gives a speedup, despite GIL contention.Jessehttps://www.blogger.com/profile/07543015027323408421noreply@blogger.com