Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'frameworks': 0.04; '(using': 0.05; 'scaling': 0.05; 'anyway).': 0.07; 'hettinger': 0.07; 'python': 0.07; 'box:': 0.09; 'mentions': 0.09; 'am,': 0.14; 'blocking': 0.14; 'wrote:': 0.14; 'library': 0.15; '(assuming': 0.16; 'async': 0.16; 'bound,': 0.16; 'event-driven': 0.16; 'factor,': 0.16; 'simultaneous': 0.16; 'subject:GIL': 0.16; 'twisted)': 0.16; 'url:documentation': 0.16; '16,': 0.16; '(i.e.': 0.18; 'question.': 0.18; 'subject:Questions': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'programming': 0.20; 'seems': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'insert': 0.22; 'raymond': 0.22; 'gil': 0.23; 'point,': 0.25; '(e.g.': 0.26; 'david': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'load': 0.28; 'received:209.85.161': 0.29; 'concern': 0.29; 'depends': 0.29; 'sat,': 0.29; '(the': 0.30; "won't": 0.30; 'cc:addr:python.org': 0.31; 'points': 0.31; 'asynchronous': 0.31; 'loads': 0.31; 'threads': 0.31; 'does': 0.31; 'language.': 0.31; 'usual': 0.32; 'idea': 0.32; 'scale': 0.33; 'handling': 0.33; "isn't": 0.34; 'using': 0.34; 'there': 0.35; 'instances': 0.35; 'quite': 0.36; 'running': 0.36; 'rather': 0.36; 'processing': 0.37; 'way.': 0.37; 'received:209.85': 0.37; 'run': 0.37; 'apr': 0.38; 'designing': 0.38; 'parallel': 0.38; 'subject:web': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'url:org': 0.38; 'though': 0.38; 'common': 0.39; 'received:209': 0.39; 'solution': 0.40; 'header:Received:5': 0.40; 'factor': 0.60; 'simple': 0.60; '2011': 0.62; 'natural': 0.63; 'harder': 0.65; 'high': 0.66; 'subject:about': 0.66; 'profiling': 0.84; 'service)': 0.84; 'curse': 0.91; '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=uBoi+z0n2cJr1VxcKGOmPGTHtJdgEE3ETAFmgePsKFQ=; b=p5UVWp5ZNWG+TC6kcM177fO7RZWE1d5dqmRIbXy3hqCoM//s2+pGMGQtsY02Q9qUKG t08Z1i4RdRo4cLb/hfXZ1rPABSq+4f0OZj2QTHHavPzvAXu5L5tyHczfpHIrI0POT4dh 7PQLWkeM1lfEF6P87SWVS+0EornWzOVllqZ/o= 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=GRNfPtc8uTmP5Nzcj+AA5MnKvZwSI8cQMPkuWml6vZ1rA88HIUQmyzHAdEfTjYDiVj j8svs6t7tXslzPsL7rjiQmydEp+hU/J7P/zU4+JfWJOpnlVNTrfXymVWGfGe+hf/ZxhY AMUdNDZXHIn39M1lk6Rbw2W7llLiLf7ursCDs= MIME-Version: 1.0 In-Reply-To: References: <4DA8734C.1080706@WindsorCircle.com> <1302887012.27269.2.camel@tim-laptop> Date: Sat, 16 Apr 2011 11:59:57 +0900 Subject: Re: Questions about GIL and web services from a n00b From: David Cournapeau To: Raymond Hettinger Content-Type: text/plain; charset=UTF-8 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: 44 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302922799 news.xs4all.nl 41103 [::ffff:82.94.164.166]:41144 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3284 On Sat, Apr 16, 2011 at 10:05 AM, Raymond Hettinger wrote: >> > Is the limiting factor CPU? >> >> > If it isn't (i.e. you're blocking on IO to/from a web service) then th= e >> > GIL won't get in your way. >> >> > If it is, then run as many parallel *processes* as you have cores/CPUs >> > (assuming you're designing an application that can have multiple >> > instances running in parallel so that you can run over multiple server= s >> > anyway). >> >> Great question. =C2=A0At this point, there isn't a limiting factor, but = yes >> the concern is around CPU in the future with lots of threads handling >> many simultaneous transactions. > > In the Python world, the usual solution to high transaction loads is > to use event-driven processing (using an async library such as > Twisted) rather than using multi-threading which doesn't scale well in > any language. My experience is that if you are CPU bound, asynchronous programming in python can be more a curse than a blessing, mostly because the need to insert "scheduling points" at the right points to avoid blocking and because profiling becomes that much harder in something like twisted. It depends of course of the application, but designing from the ground up with the idea of running multiple processes is what seems to be the most natural way of scaling - this does not prevent using async in each process. This has its own issues, though (e.g. in terms of administration and monitoring). Chris, the tornado documention mentions a simple way to get multiple processes on one box: http://www.tornadoweb.org/documentation (section mentiong nginx for load balancing). The principle is quite common and is applicable to most frameworks (the solution is not specific to tornado). cheers. David