https://gist.github.com/yihuang/eb0a670c9fab188c6e3e
I've done a benchmark shows that twisted-mode asyncio can handle more
request than gevent (though the latency seems bigger), which is exciting,
but coroutine-mode is slower(I'll post that code latter).
I'll do some profiling latter, I guess I can profile asyncio's coroutine
with standard cProfile, right?

On Friday, July 18, 2014, Victor Stinner <[email protected]> wrote:

> Hi,
>
> Here is a very basic example to show how to use start_server().
> echo_server() coroutines will run in parallel.
> ---
> import asyncio
>
> @asyncio.coroutine
> def echo_server(reader, writer):
>     line = yield from reader.readline()
>     print("Reply %r" % line)
>     writer.write(line)
>     yield from writer.drain()
>     writer.close()
>
> loop = asyncio.get_event_loop()
> loop.run_until_complete(asyncio.start_server(echo_server, port=8000))
> loop.run_forever()
> loop.close()
> ---
>
> You may add something like that to the documentation.
>
> Victor
>
> 2014-07-18 10:47 GMT+02:00 yi huang <[email protected]
> <javascript:;>>:
> > The example in asyncio documentation only shows how to write echo server
> in
> > twisted style, and i wonder how can i write server handler as a coroutine
> > like in gevent, something like:
> >
> > def handle_client(transport):
> >     while True:
> >         buf = yield from transport.read(4096)
> >         # handle request
> >
> >         # read some result from database without blocking other
> coroutine.
> >         result = yield from block_read_from_database()
> >
> > loop.create_server(handle_client, '127.0.0.1', 3000)
> >
> >
> > Thanks.
> >
> > --
> > http://yi-programmer.com/
>


-- 
http://yi-programmer.com/

Reply via email to