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


Groups > comp.lang.python > #102787

Re: asyncio and blocking - an update

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: asyncio and blocking - an update
Date Thu, 11 Feb 2016 16:57:49 +1100
Lines 36
Message-ID <mailman.34.1455170277.22075.python-list@python.org> (permalink)
References <n9c4p3$gmp$1@ger.gmane.org> <n9h75i$ag1$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de sfxnYQjcDlbDXlT2QDerNwq2wCTt1JNc98CmhtWWKm6Q==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'handler': 0.04; 'socket': 0.07; 'cc:addr:python-list': 0.09; 'block.': 0.09; 'rows': 0.09; 'rows,': 0.09; 'index': 0.13; 'subsequent': 0.15; 'thu,': 0.15; '2016': 0.16; 'async': 0.16; 'fetches': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'plan.': 0.16; 'query,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'stuff,': 0.16; 'stuff.': 0.16; 'wrote:': 0.16; 'library,': 0.18; 'resolved': 0.18; 'network,': 0.18; 'solution.': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fraction': 0.22; 'parse': 0.22; 'seems': 0.23; 'feb': 0.23; 'slightly': 0.23; 'tried': 0.24; 'unix': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'connected': 0.27; 'figure': 0.27; 'checking': 0.27; 'pages,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'disk': 0.27; 'page.': 0.28; 'function': 0.28; 'actual': 0.28; '(maybe': 0.29; '50,': 0.29; 'arrival': 0.29; 'subject:update': 0.29; 'table,': 0.29; 'usable': 0.29; 'query': 0.30; 'probably': 0.31; "can't": 0.32; 'table': 0.32; 'operate': 0.32; 'maybe': 0.33; 'errors,': 0.33; 'though.': 0.33; 'server': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'easiest': 0.35; 'involving': 0.35; 'something': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'faster': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'goes': 0.39; 'submit': 0.39; 'build': 0.40; 'some': 0.40; 'save': 0.60; 'your': 0.60; 'increased': 0.61; "you'll": 0.61; 'provide': 0.61; 'skip:n 10': 0.62; 'more': 0.63; 'real-world': 0.66; 'worth': 0.67; 'frank': 0.72; '100': 0.79; 'chrisa': 0.84; 'faster.': 0.84; 'presumably': 0.84; 'to:none': 0.91; 'optimum': 0.93
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=r5oQFEDy/2i20MqOHsgXM+7jt1bHZIgK+g4uET5simU=; b=zHxLec6oknqA411R/8J+48duFfTggDpdYwVMw7QGEB4/OAmdue41o8SxbX42TZIMoB IyYwBTFDmyT7oH1qQV3nbCMLaZ0oz94Vsr5VQObT9SCwZ7Jaju/CruQIIGgGxcq+uQVl dHxanN7EBiNperM2uNkG1VOWdQ19sBmtyoZWmx1StAJLUATDW09IF8l29keYi12eQO9v wjh8i5GPuWW4Cg4z4s0z3a/tNLiveHZpPgbVrcR5Ycv/UvDZBdEVK9Ps0hO5OtGJ6w/K HtMHKoRgLHYe2beL4vMXSs98Xflu6hhNKcw1lZeiJyJPc8F1pn2BOboPldlasbK9dqTC vYug==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=r5oQFEDy/2i20MqOHsgXM+7jt1bHZIgK+g4uET5simU=; b=CQa8mE322se4TpGeqmXI0ptqaPeGNUsA+a0BVSfwGLl36QIrxdAxc39F+8EPLQHc0H 5yeoWgLKiCfKonmDoP+NHKiRT76Hc0BKPJ95YvZtRUFMNNGTteWgSPA03Uv7Li2X1Flh nJdBhmZ2rrcpJkiDMTR3uRa45L1WY98uYsEof3seyGyXWeQjDOBP1ampDBLiaC2yZF6B +Ba50eoACJh7jXR0xXeZiKxZq3TCxz+gOghHdm0uC0+4bAxazpqqsVPxx0b1cG+gig9c hQ0gf9fjNXkUDr9GxkV2jp+fHT41xooP/sOhm5YfUSNerBMVDdZ4IDRsj6Jn/sZo77I+ v48g==
X-Gm-Message-State AG10YOQwERr2mWqQjadyPQP21Di69fVaK6wBvyZAhKv44EjBynkelenkadybg3LhPjODHFgeb9znURsv4KzCEQ==
X-Received by 10.107.14.73 with SMTP id 70mr42224670ioo.31.1455170269228; Wed, 10 Feb 2016 21:57:49 -0800 (PST)
In-Reply-To <n9h75i$ag1$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
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>
Xref csiph.com comp.lang.python:102787

Show key headers only | View raw


On Thu, Feb 11, 2016 at 4:45 PM, Frank Millman <frank@chagford.com> wrote:
> I have come up with a plan that seems to provide a solution.
>
> Instead of 'putting' one row at a time, let the database handler build up a
> block of rows, and then 'put' the block.
>
> I tried a block of 10, and it ran a lot faster. I increased it to 50, and it
> ran faster again. I tried 100 and there was not much improvement, so 50
> seems like an optimum number. The speed is now only slightly slower than
> run_in_executor(), and it is more truly asynchronous.

Something worth checking would be real-world database performance
metrics: what's time-to-first-row versus time-to-subsequent-rows? When
you submit a query, the server first has to parse it and check for
errors, then do all its optimization and stuff, and figure out an
access plan. Then it goes and fetches stuff. If your query is a simple
"select * from tablename" on a huge table, then it's entirely possible
that you save a lot of time by fetching subsequent rows
asynchronously; but if there's an ORDER BY that can't be resolved from
an index (maybe involving a table join or a non-optimizable function
call), the database might have to read everything from the disk before
it can return a single row, so the time from first row to last row is
a tiny fraction of the time to first row. What are your actual
real-world queries like?

Most likely, the database is reading rows in pages, and you'll have no
way of predicting how many usable result rows are on any page. I
wonder, is there any way you can actually operate this the other way
around? Presumably the database is connected to you via a socket of
some sort (TCP if you're going over a network, maybe a Unix socket for
local connections), which you could select() on same as any other; if
you can react to the arrival of more rows, that might be the easiest
solution. That would probably require a dedicated async database
library, though.

ChrisA

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


Thread

Re: asyncio and blocking - an update Chris Angelico <rosuav@gmail.com> - 2016-02-11 16:57 +1100

csiph-web