Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72496

Re: Benefits of asyncio

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'syntax': 0.04; 'anyway.': 0.05; '101': 0.09; 'apis': 0.09; 'rewrite': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; 'thread': 0.14; '*must*': 0.16; 'above?': 0.16; 'apis.': 0.16; 'blocking': 0.16; 'concurrent': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'internally': 0.16; 'limit,': 0.16; 'reasonably': 0.16; 'threads.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'commit': 0.19; 'memory': 0.22; 'otherwise,': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'logical': 0.24; "shouldn't": 0.24; 'fairly': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'query': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'possibility': 0.29; 'scale': 0.29; 'database,': 0.30; 'matching': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'getting': 0.31; 'requests': 0.31; 'purely': 0.31; 'probably': 0.32; 'implemented': 0.33; 'connection': 0.35; 'transaction': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'half': 0.37; 'unit': 0.37; 'turn': 0.37; 'two': 0.37; 'easily': 0.37; 'handle': 0.38; 'pm,': 0.38; 'ability': 0.39; 'realize': 0.39; 'major': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'around.': 0.60; 'dangerous': 0.60; 'most': 0.60; 'numbers': 0.61; "you'll": 0.62; 'happen': 0.63; 'close': 0.67; 'advantages': 0.68; 'delegate': 0.68; 'request.': 0.70; 'million': 0.74; 'asynchronous': 0.84; 'desperately': 0.84; 'forced': 0.84; 'issues;': 0.84; 'inefficient': 0.91; 'transactions': 0.91; 'to:none': 0.92; 'connection,': 0.95; 'hundred': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=k3AZyWQP7iBXx1JGla4mSH7c+ZulPEOpfb0cmsIBbSQ=; b=ClpU52TgEElU0o9D9/s6+6594GajrrBncp+QTpSlRD5oVvdBSskxS0ylXs9CrmVEMB YYTpIBZiPq22dudVi/upA6brRccHBVNXh1nrLyQY1pH73dqXDQbaa9KWRflXvEnedpCr qx9EYlhdT5aiczDQaPz1K1anojN2gXXQlLayfXxNmw8IxDhj5+xR2eVBdPSLpPYc0j2x 40uT3V5InvIX9iSk+vkPe1y1w6P9gZmgCyuJCkwSZaXdUAMEHUaBC1L0C/jsfPIgJ48X ZnJ2EeHWxnIuobkafDvMPtyrm4xerKwNN0ay4JGPOxTVLhzUCfrsLc/IsMLzDLsg3/0k Uhsg==
MIME-Version 1.0
X-Received by 10.52.167.132 with SMTP id zo4mr20164vdb.97.1401787814495; Tue, 03 Jun 2014 02:30:14 -0700 (PDT)
In-Reply-To <87wqcyuznv.fsf@elektro.pacujo.net>
References <d1634744-39e8-4bfa-be76-1fd2292fd59f@googlegroups.com> <mailman.10573.1401739639.18130.python-list@python.org> <874n03t5t9.fsf@elektro.pacujo.net> <7x4n03dor0.fsf@ruckus.brouhaha.com> <878upe8poc.fsf@elektro.pacujo.net> <mailman.10606.1401785234.18130.python-list@python.org> <87wqcyuznv.fsf@elektro.pacujo.net>
Date Tue, 3 Jun 2014 19:30:14 +1000
Subject Re: Benefits of asyncio
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10609.1401787816.18130.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401787816 news.xs4all.nl 2887 [2001:888:2000:d::a6]:60023
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72496

Show key headers only | View raw


On Tue, Jun 3, 2014 at 7:10 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> def request.process(self): # I know this isn't valid syntax
>>     db.act(whatever) # may block but shouldn't for long
>>     db.commit() # ditto
>>     write(self, response) # won't block
>>
>> This works as long as your database is reasonably fast and close
>
> I find that assumption unacceptable.

It is a dangerous assumption.

> The DB APIs desperately need asynchronous variants. As it stands, you
> are forced to delegate your DB access to threads/processes.
>
>> So how do you deal with the possibility that the database will block?
>
> You separate the request and response parts of the DB methods. That's
> how it is implemented internally anyway.
>
> Say no to blocking APIs.

Okay, but how do you handle two simultaneous requests going through
the processing that you see above? You *MUST* separate them onto two
transactions, otherwise one will commit half of the other's work. (Or
are you forgetting Databasing 101 - a transaction should be a logical
unit of work?) And since you can't, with most databases, have two
transactions on one connection, that means you need a separate
connection for each request. Given that the advantages of asyncio
include the ability to scale to arbitrary numbers of connections, it's
not really a good idea to then say "oh but you need that many
concurrent database connections". Most systems can probably handle a
few thousand threads without a problem, but a few million is going to
cause major issues; but most databases start getting inefficient at a
few thousand concurrent sessions.

>> but otherwise, you would need to completely rewrite the main code.
>
> That's a good reason to avoid threads. Once you realize you would have
> been better off with an async approach, you'll have to start over. You
> can easily turn a nonblocking solution into a blocking one but not the
> other way around.

Alright. I'm throwing down the gauntlet. Write me a purely nonblocking
web site concept that can handle a million concurrent connections,
where each one requires one query against the database, and one in a
hundred of them require five queries which happen atomically. I can do
it with a thread pool and blocking database queries, and by matching
the thread pool size and the database concurrent connection limit, I
can manage memory usage fairly easily; how do you do it efficiently
with pure async I/O?

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Benefits of asyncio Aseem Bansal <asmbansal2@gmail.com> - 2014-06-02 10:40 -0700
  Re: Benefits of asyncio Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-02 12:37 -0600
  Re: Benefits of asyncio Terry Reedy <tjreedy@udel.edu> - 2014-06-02 16:07 -0400
    Re: Benefits of asyncio Roy Smith <roy@panix.com> - 2014-06-02 16:19 -0400
    Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-02 23:28 +0300
      Re: Benefits of asyncio Paul Rubin <no.email@nospam.invalid> - 2014-06-02 13:45 -0700
        Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 07:49 +1000
        Re: Benefits of asyncio Terry Reedy <tjreedy@udel.edu> - 2014-06-02 21:51 -0400
        Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 09:36 +0300
          Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 18:47 +1000
            Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 12:10 +0300
              Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 19:30 +1000
                Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 13:08 +0300
                Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 20:23 +1000
                Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 14:12 +0300
                Re: Benefits of asyncio Paul Rubin <no.email@nospam.invalid> - 2014-06-04 00:52 -0700
              Re: Benefits of asyncio Burak Arslan <burak.arslan@arskom.com.tr> - 2014-06-03 14:05 +0300
              Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 21:57 +1000
              Re: Benefits of asyncio Burak Arslan <burak.arslan@arskom.com.tr> - 2014-06-04 08:10 +0300
              Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-04 17:30 +1000
              Re: Benefits of asyncio Paul Rubin <no.email@nospam.invalid> - 2014-06-04 00:48 -0700
          Re: Benefits of asyncio "Frank Millman" <frank@chagford.com> - 2014-06-03 13:09 +0200
          Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 22:01 +1000
            Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 16:05 +0300
              Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 23:31 +1000
                Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 16:42 +0300
                Re: Benefits of asyncio Chris Angelico <rosuav@gmail.com> - 2014-06-03 23:49 +1000
                Re: Benefits of asyncio Marko Rauhamaa <marko@pacujo.net> - 2014-06-03 19:18 +0300
              Re: Benefits of asyncio Roy Smith <roy@panix.com> - 2014-06-03 11:40 -0400
        Re: Benefits of asyncio Paul Sokolovsky <pmiscml@gmail.com> - 2014-06-03 11:31 +0300
  Re: Benefits of asyncio Burak Arslan <burak.arslan@arskom.com.tr> - 2014-06-03 00:07 +0300
  Re: Benefits of asyncio Aseem Bansal <asmbansal2@gmail.com> - 2014-06-02 21:54 -0700

csiph-web