Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103448
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: [Python-ideas] How the heck does async/await work in Python 3.5 |
| Date | Wed, 24 Feb 2016 08:41:25 -0700 |
| Lines | 76 |
| Message-ID | <mailman.97.1456328534.20994.python-list@python.org> (permalink) |
| References | <mailman.224.1455746935.22075.python-list@python.org> <56c7d145$0$1597$c3e8da3$5496439d@news.astraweb.com> <na92c0$n65$1@dont-email.me> <56CCC98C.5060504@mail.de> <CAH0mxTQE9xn3OZJ8s-oj13LtQOYGGW2Y1uC9xM3YpzAtY8pqJQ@mail.gmail.com> <CAMpsgwbO1v7318u9VZCTrPHOERAAQiEAHJ9ChWCVqYP-7aqskw@mail.gmail.com> <mailman.95.1456326057.20994.python-list@python.org> <87vb5ejfnv.fsf@elektro.pacujo.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de bVU9eH+O8poN3/juGvYDSgY3XeGXT79hicDRQF4YLKRg== |
| Return-Path | <ian.g.kelly@gmail.com> |
| 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; 'subject:: [': 0.03; 'else:': 0.03; 'exercise': 0.03; 'received:209.85.223': 0.03; 'skip:[ 20': 0.03; 'subject:Python': 0.05; 'subject:How': 0.09; 'concurrent': 0.09; 'url:github': 0.09; 'yeah,': 0.09; 'python': 0.10; 'index': 0.13; 'def': 0.13; 'wed,': 0.15; 'languages.': 0.15; 'skip:p 40': 0.15; "'from": 0.16; '2016': 0.16; '24,': 0.16; 'async': 0.16; 'concurrency': 0.16; 'coroutines': 0.16; 'descendant': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:ideas': 0.16; 'wrote:': 0.16; 'subject:] ': 0.19; 'am,': 0.23; 'feb': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'loop,': 0.29; 'subject:/': 0.30; 'skip:[ 10': 0.31; 'point': 0.33; 'running': 0.34; 'received:google.com': 0.35; 'skip:3 10': 0.35; 'involving': 0.35; 'something': 0.35; 'level': 0.35; "isn't": 0.35; 'problem.': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'faster': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'skip:5 10': 0.37; 'skip:4 10': 0.38; 'received:209': 0.38; 'wrong': 0.38; 'skip:p 20': 0.38; 'subject:the': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'son': 0.61; 'here': 0.66; 'results.': 0.67; 'skip:6 10': 0.67; 'await': 0.76; 'cheating': 0.84; 'recursion:': 0.84; 'tem': 0.84; 'to:name:python': 0.84; 'technically': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=i/5Kki2u1wnIfo4aapbzll3kssYjV167a7e5CSdn0qQ=; b=xxUEOAvRqKKjVdplTWgjV0EMLrku/xQfg2GxmXy0KBhv7t3nMcxfonswAy8dVNCPnz j8CD7COhFbx5AUAR5iL/WqPBZMFY8ctJCzqwRf1qcHS41QVlfTz3G3VrzDfN4JQaHY2i VekWVrp0jq9ED1rV9TLxg+ivciipDv+Hd28/X3smQ74ZKQ9fvSQUogsL149acAVHCoXd KDlqonMFfZExD/2fGN5nGkNKF436Fe1PsGSkjsTIev46Xz+UpYoQlTYLMbcJ97Vygzp7 Ea8O0uhPp7sSCDlZ4/7yhPRZJyQeq7CdvwEZOLxetIX5byLFN/VNkX+OCzLh/WD1YCLN bCqA== |
| 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:from:date :message-id:subject:to:content-type; bh=i/5Kki2u1wnIfo4aapbzll3kssYjV167a7e5CSdn0qQ=; b=DfQAMENchvqvqkPqxbFj4wpkuql0nbj3Yn1Wpj38NCl/I18da7HATjZGhU9Suap0mH mUSLKuxk271bRG1UuZe/4OA74GCFlFdxzD2Ow9oOcBXvcTlPf9m3+gb9Zk4bEirKqd34 N3k7R8fOtwk4WCxYCJAXLDB85Z+keKlW44KmlX5L7eFxvBP88S7Y11tZEYSRXuPusanr +2oj0GVR1SdvpNtej4XF/4zYyRKHFr0ccPx+QYYg9Rq4ijdaAFNiAQe3IqqlDj5mdgfw mqRs65xlUtQCCrUdrJEocxfrm+bMdU0HGKgKf6uJm6KBvBrQrfWYujDA/mLpoDixJcya D3Og== |
| X-Gm-Message-State | AG10YOSmPGnSEZHBGXgBaeOcq8bPHXFeg1rH7NZD8VYn7LNJVXxxk07nhvxdxAUKmfXaxWwLmk2O5JHkNZBwRg== |
| X-Received | by 10.107.185.214 with SMTP id j205mr40309301iof.111.1456328525038; Wed, 24 Feb 2016 07:42:05 -0800 (PST) |
| In-Reply-To | <87vb5ejfnv.fsf@elektro.pacujo.net> |
| 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:103448 |
Show key headers only | View raw
On Wed, Feb 24, 2016 at 8:23 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Tem Pl <rtempl31@gmail.com>:
>
>> Here are some concurrency benchmarks for python vs other languages.
>>
>> https://github.com/atemerev/skynet/pull/53
>>
>> Is there something wrong with this implementation?
>
> It's a "fork bomb".
Isn't that the point of the benchmark?
But yeah, I tried playing with this and here are my results. It's
clearly pushing all those coroutines down into the event loop that
causes the problem. If you remove the asyncio.as_completed calls and
just await the descendant coroutines in order, then it's a lot faster
-- but this may be technically cheating because then the coroutines
are effectively just running recursively without involving the event
loop, so there's no exercise of actual concurrency.
# Straight-up recursion: 400 ms
def func(level=0, index=0):
if level < LEVELS:
sons = [func(level=level+1, index=index*SONS + x) for x in range(SONS)]
sum_ = 0
for son in sons:
sum_ += son
return sum_
else:
return index
import timeit
print(timeit.repeat('func()', 'from __main__ import func', number=10))
# [4.016848850995302, 4.1330014310078695, 4.149791953997919]
# Concurrent coroutines with event loop: 30 s
import asyncio
async def coroutine(level=0, index=0):
if level < LEVELS:
sons = [coroutine(level=level+1, index=index*SONS + x) for x
in range(SONS)]
sum_ = 0
for f in asyncio.as_completed(sons):
got = await f
sum_ += got
return sum_
else:
return index
print(timeit.repeat('loop.run_until_complete(coroutine())', 'from
__main__ import coroutine; import asyncio; loop =
asyncio.get_event_loop()', number=1))
# [29.884846250002738, 30.26590966898948, 30.716448744002264]
# Recursion with coroutines: 600 ms
async def coro2(level=0, index=0):
if level < LEVELS:
sons = [coro2(level=level+1, index=index*SONS + x) for x in range(SONS)]
sum_ = 0
for son in sons:
got = await son
sum_ += got
return sum_
else:
return index
print(timeit.repeat('loop.run_until_complete(coro2())', 'from __main__
import coro2; import asyncio; loop = asyncio.get_event_loop()',
number=1))
# [0.6264017040084582, 0.590631059021689, 0.5807875629980117]
# Recursive coroutines, no event loop: 600 ms
print(timeit.repeat('list(coro2().__await__())', 'from __main__ import
coro2', number=10))
# [6.028770218021236, 6.002665672975127, 5.987304503010819]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How the heck does async/await work in Python 3.5 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-17 22:08 +0000
Re: How the heck does async/await work in Python 3.5 Steven D'Aprano <steve@pearwood.info> - 2016-02-20 13:36 +1100
Re: How the heck does async/await work in Python 3.5 Rustom Mody <rustompmody@gmail.com> - 2016-02-19 21:24 -0800
Re: How the heck does async/await work in Python 3.5 Rustom Mody <rustompmody@gmail.com> - 2016-02-19 21:34 -0800
Re: How the heck does async/await work in Python 3.5 Paul Rubin <no.email@nospam.invalid> - 2016-02-19 22:44 -0800
Re: How the heck does async/await work in Python 3.5 Steven D'Aprano <steve@pearwood.info> - 2016-02-21 18:17 +1100
Re: How the heck does async/await work in Python 3.5 Paul Rubin <no.email@nospam.invalid> - 2016-02-20 23:34 -0800
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 00:48 -0700
Re: How the heck does async/await work in Python 3.5 Chris Angelico <rosuav@gmail.com> - 2016-02-20 18:57 +1100
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 01:14 -0700
Re: How the heck does async/await work in Python 3.5 Chris Angelico <rosuav@gmail.com> - 2016-02-20 19:49 +1100
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 02:11 -0700
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 02:21 -0700
Re: How the heck does async/await work in Python 3.5 Christian Gollwitzer <auriocus@gmx.de> - 2016-02-20 07:53 +0100
Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-22 23:16 +0100
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-22 17:48 -0700
Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 17:50 +0100
Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-23 10:37 -0700
Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 20:42 +0100
Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 22:05 +0100
Re: [Python-ideas] How the heck does async/await work in Python 3.5 "Joao S. O. Bueno" <jsbueno@python.org.br> - 2016-02-23 18:25 -0300
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Paul Moore <p.f.moore@gmail.com> - 2016-02-24 09:59 +0000
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Victor Stinner <victor.stinner@gmail.com> - 2016-02-24 11:01 +0100
Re: [Python-ideas] How the heck does async/await work in Python 3.5 王珺 <wjun77@gmail.com> - 2016-02-24 18:40 +0800
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-02-25 10:00 +1300
Re: [Python-ideas] How the heck does async/await work in Python 3.5 王珺 <wjun77@gmail.com> - 2016-02-25 08:40 +0800
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-24 20:37 -0500
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Tem Pl <rtempl31@gmail.com> - 2016-02-24 06:39 -0800
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Marko Rauhamaa <marko@pacujo.net> - 2016-02-24 17:23 +0200
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-24 08:41 -0700
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Marko Rauhamaa <marko@pacujo.net> - 2016-02-24 18:13 +0200
Re: [Python-ideas] How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-24 09:47 -0700
csiph-web