Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.212.46': 0.03; 'received:mail-vw0-f46.google.com': 0.03; 'frameworks': 0.04; '(especially': 0.07; 'cpython': 0.07; 'django,': 0.07; 'json': 0.07; 'rest,': 0.07; 'python': 0.07; 'admit': 0.09; 'concurrency': 0.09; 'web2py,': 0.09; 'looked': 0.10; 'essentially': 0.12; 'url:moin': 0.12; 'am,': 0.14; 'extension': 0.14; 'request,': 0.14; 'wrote:': 0.14; '3.2,': 0.16; 'cores': 0.16; 'coupling': 0.16; 'cpython,': 0.16; 'discrete': 0.16; 'gil.': 0.16; 'ironpython,': 0.16; 'pypy': 0.16; 'subject:GIL': 0.16; 'threading': 0.16; '\xa0this': 0.16; 'subject:Questions': 0.19; 'modules': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code,': 0.20; 'programming': 0.20; 'seems': 0.21; 'software.': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:addr:python- list': 0.22; 'gil': 0.23; 'topic.': 0.23; '\xa0if': 0.23; 'runs': 0.24; "what's": 0.24; 'url:wiki': 0.24; 'received:209.85.212': 0.25; 'xml': 0.26; "i'm": 0.26; 'chris': 0.27; 'google': 0.27; 'message-id:@mail.gmail.com': 0.28; 'looks': 0.28; 'shared': 0.29; 'fri,': 0.29; 'are.': 0.29; 'good.': 0.29; 'indicated': 0.29; 'probably': 0.30; 'yet': 0.30; 'cc:addr:python.org': 0.31; 'arrays': 0.31; 'lock': 0.31; 'threads': 0.31; 'called': 0.32; 'presentation': 0.32; "i've": 0.33; 'components': 0.33; 'page': 0.33; 'bit': 0.33; 'data.': 0.33; 'module': 0.33; 'reference': 0.34; 'skip:" 10': 0.34; 'actually': 0.34; 'summary': 0.35; 'there': 0.35; 'finding': 0.35; 'module.': 0.35; 'options:': 0.35; 'status,': 0.35; 'quite': 0.36; 'running': 0.36; 'data': 0.37; 'rest': 0.37; 'way.': 0.37; 'received:209.85': 0.37; 'url:python': 0.37; 'issue': 0.37; 'apr': 0.38; 'faster': 0.38; 'feels': 0.38; 'other,': 0.38; 'subject:web': 0.38; 'received:google.com': 0.38; 'less': 0.38; 'but': 0.38; 'pretty': 0.38; 'url:org': 0.38; 'though': 0.38; 'not,': 0.39; 'back.': 0.39; 'likely': 0.39; 'received:209': 0.39; 'how': 0.39; 'similar': 0.40; 'attempt': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'allows': 0.40; 'might': 0.40; 'simple': 0.60; 'fact,': 0.60; 'best': 0.60; 'give': 0.61; 'bring': 0.62; 'further': 0.62; '2011': 0.62; 'safe': 0.65; 'subject:about': 0.66; 'believe': 0.66; 'due': 0.67; 'articles': 0.67; 'thousands': 0.69; '(more)': 0.84; 'compiles': 0.84; 'dialect': 0.84; 'remember:': 0.84; 'service?': 0.84; 'exchanging': 0.93; 'subject:services': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=1SzA+Yrnc2FTgecCRy3DNhuq0313zZmD6DCImOK6TK8=; b=o+P8uc955moXBVMNs6XT1nB+r5zFjzcQyoUYJThYFTXX5FTZkRs1rs+lESU3svFpiq qJEBgn3gj7slltS68JfrsEUYliWN6mnq5t/fPwqdTgi3timj4Wo/QmecFrD8mW1n8gtA rwWVXyJ2D8P5EEgtzu2u6fjG6hD8VDgMyH3z8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Q5XvFUUP7rObff33I/5owTMTIXRF/mtYrmmjqYvx9A9lrzcpuhOCFYh2m8031uBSpp XFKVMFSFyKXZf+xWi7A1q+xrLcWBWobP0XLA/C2vWotkVjzErVpUL+kNHPaXagLy2eAn bo08K24weXIXWk7jxK6Y1m7MDPkvSlcdSo3es= MIME-Version: 1.0 In-Reply-To: <4DA8734C.1080706@WindsorCircle.com> References: <4DA8734C.1080706@WindsorCircle.com> Date: Fri, 15 Apr 2011 12:17:28 -0700 Subject: Re: Questions about GIL and web services from a n00b From: Dan Stromberg To: Chris H Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 65 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302895051 news.xs4all.nl 41114 [::ffff:82.94.164.166]:56799 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3279 On Fri, Apr 15, 2011 at 9:33 AM, Chris H wrote: > 1. Are you sure you want to use python because threading is not good due = to > the Global Lock (GIL)? =A0Is this really an issue for multi-threaded web > services as seems to be indicated by the articles from a Google search? = =A0If > not, how do you avoid this issue in a multi-threaded process to take > advantage of all the CPU cores available? Concurrency in Python is a largish topic. It's true that CPython's multithreading is poor. In fact, running a multithreaded CPython application on n vs 2n cores can actually take more time on the 2n cores. However: 1) In Jython, and likely IronPython, threading is good. 2) In CPython, there's a module called "multiprocessing" that's a little slower than a good threading implementation, but gives looser coupling between the discrete components of your software. Programming with multiprocessing feels similar to programming with threads - you have safe queues, safe scalars or simple arrays in shared memory, etc. 3) There's something called "stackless" and (similar to stackless) "greenlets". While stackless allows you to use thousands of threads comfortably, it's still pretty single-core. It's essentially a fork of CPython, and is being made a part of PyPy. I believe greenlets are an attempt to bring what's good about stackless to CPython, in the form of a C extension module. 4) I've heard that in CPython 3.2, the GIL is less troublesome, though I've not yet heard in what way. 5) Even in CPython, I/O-bound processes are not slowed significantly by the GIL. It's really CPU-bound processes that are. 6) PyPy is quite a bit faster than CPython for non-concurrent applications, but also has a GIL. 7) Cython, which compiles a dialect of Python into faster C (especially if you give it a few type declarations), has GIL-implications. I've heard that Cython can selectively release the GIL on request, but I've also heard that C extension modules always release the GIL. This seems contradictory, and merits further investigation. It's important to remember: Python !=3D CPython. CPython remains the reference implementation, and runs the most Python code, but there are other, significant implementations now. This page looks like a summary of many (more) options: http://wiki.python.org/moin/Concurrency/ > 2. Are there good web services frameworks available for building a REST > based service? =A0I admit I have looked at web2py, Django, pyramid/pylons= , and > a few others. =A0SOAP seems to be pretty well supported but I'm not findi= ng > the same for quick development of REST based services for exchanging JSON= or > XML formatted data. =A0This is probably just my n00b status, but what too= ls > are best for building a simple REST data exchange API? I have no experience with REST, but Grig of SoCal Piggies did a presentation on "restish" a while back. You might see if you can find something about that.