This is exciting! It's quite possible that cProfile will find some issues in asyncio that are easy to fix -- we haven't done much tuning. I'm not sure whether cProfile will correctly profile generators, but if there are any issues they will be obvious when you try (and then we'll figure out what to do about it).
Have you run the benchmarks several times and found that the results match what you posted? Have you tried varying the number of threads? Finally, it looks like you are using Python 2 for the gevent test, while the asyncio requires Python 3. I worry that the differences between these Python versions might overwhelm any other useful data you might find. Other things to vary would be the selector used by the event loop (select, kqueue or epoll, the latter depending on your platform). On Fri, Jul 18, 2014 at 9:03 AM, yi huang <[email protected]> wrote: > 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]>: >> > 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/ > -- --Guido van Rossum (python.org/~guido)
