{"id":217143,"date":"2014-03-26T18:27:03","date_gmt":"2014-03-26T14:27:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217143"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217143","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f asyncio: HTTPServer?!<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0437\u0430\u0440\u0435\u043b\u0438\u0437\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <b>Python 3.4<\/b> \u0432 <a href=\"https:\/\/www.python.org\/download\/releases\/3.4.0\/\">changelog<\/a> \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043e\u0448\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u00ab\u0432\u043a\u0443\u0441\u043d\u043e\u0441\u0442\u0435\u0439\u00bb. \u041e\u0434\u043d\u0430 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u2014 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"http:\/\/docs.python.org\/dev\/library\/asyncio.html\">asyncio<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u0443\u044e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (coroutines), \u043a\u043e\u0434 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438. <\/p>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e TCP (Echo) \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441 \u0447\u0435\u043c \u0435\u0434\u044f\u0442 <code>asyncio<\/code>, \u0438 \u0440\u0438\u0441\u043a\u043d\u0443 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u00ab\u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a\u00bb \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e HTTP \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>INTRO<\/h4>\n<p>  \u041f\u0440\u044f\u043c\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442 \u0438 \u00ab\u0431\u0440\u0430\u0442\u00bb \u2014 \u044d\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <a href=\"http:\/\/tornadoweb.org\">tornado<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0441\u0435\u0431\u044f \u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0441\u043b\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, asyncore \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0449\u0435, \u0431\u043e\u043b\u0435\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0438 \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d. \u0412\u043f\u0440\u043e\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0435 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>  \u0412\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435, \u0447\u0442\u043e \u043d\u0430 Python \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0440\u0430\u0432\u044b. \u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\/\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f callback \u0441\u0442\u0438\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f coroutine \u0434\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Python \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043b\u0438\u0448\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0445\u043e\u0447\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u044f \u043f\u0438\u0441\u0430\u043b \u043f\u043e\u0434 Linux, \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u043e\u0434 Windows \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u043e \u0432\u0435\u0440\u0441\u0438\u044f Python 3.4 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430.<\/p>\n<h4>EchoServer<\/h4>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 Echo \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0435\u0441\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u044d\u0442\u043e \u043a <a href=\"http:\/\/docs.python.org\/dev\/library\/asyncio-protocol.html\">low-level API \u00abTransports and protocols\u00bb<\/a>. \u0414\u043b\u044f \u00ab\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0433\u043e\u00bb \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f <a href=\"http:\/\/docs.python.org\/dev\/library\/asyncio-stream.html\">high-level API \u00abStreams\u00bb<\/a>. \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 TCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 \u043d\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u0437\u0443\u0447\u0438\u0432 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 low-level API \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0442\u043e\u0433\u043e \u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 TCP \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0443\u0434\u0430.<\/p>\n<pre><code class=\"python\">import asyncio import logging import concurrent.futures  @asyncio.coroutine def handle_connection(reader, writer):     peername = writer.get_extra_info('peername')     logging.info('Accepted connection from {}'.format(peername))     while True:         try:             data = yield from asyncio.wait_for(reader.readline(), timeout=10.0)             if data:                  writer.write(data)             else:                 logging.info('Connection from {} closed by peer'.format(peername))                 break         except concurrent.futures.TimeoutError:             logging.info('Connection from {} closed by timeout'.format(peername))             break     writer.close()  if __name__ == '__main__':     loop = asyncio.get_event_loop()     logging.basicConfig(level=logging.INFO)     server_gen = asyncio.start_server(handle_connection, port=2007)     server = loop.run_until_complete(server_gen)     logging.info('Listening established on {0}'.format(server.sockets[0].getsockname()))     try:         loop.run_forever()     except KeyboardInterrupt:         pass # Press Ctrl+C to stop     finally:         server.close()         loop.close() <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<pre><code class=\"python\">    server_gen = asyncio.start_server(handle_connection, port=2007)     server = loop.run_until_complete(server_gen) <\/code><\/pre>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u0430\u043c \u0441\u0435\u0440\u0432\u0435\u0440, \u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0435\u043c\u0443 \u0438 \u043d\u0435\u0434\u0440 <code>asyncio<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c TCP \u0441\u0435\u0440\u0432\u0435\u0440. \u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">        try:             data = yield from asyncio.wait_for(reader.readline(), timeout=10.0)             if data:                  writer.write(data)             else:                 logging.info('Connection from {} closed by peer'.format(peername))                 break         except concurrent.futures.TimeoutError:             logging.info('Connection from {} closed by timeout'.format(peername))             break <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f-coroutine <code>reader.readline()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041d\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-coroutine \u0432 <code>asyncio.wait_for()<\/code>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043d\u044f\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>concurrent.futures.TimeoutError<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<br \/>  \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0447\u0442\u043e <code>reader.readline()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430. \u0418\u043d\u0430\u0447\u0435 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c (connection reset by peer), \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h5>\u0410 \u043a\u0430\u043a \u0436\u0435 \u041e\u041e\u041f?<\/h5>\n<p>  \u0421 \u041e\u041e\u041f \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439-coroutine \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 @asyncio.coroutine. \u041a\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a coroutine \u0432 API \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 EchoServer.<\/p>\n<pre><code class=\"python\">import asyncio import logging import concurrent.futures  class EchoServer(object):     &quot;&quot;&quot;Echo server class&quot;&quot;&quot;          def __init__(self, host, port, loop=None):         self._loop = loop or asyncio.get_event_loop()          self._server = asyncio.start_server(self.handle_connection, port=2007)          def start(self, and_loop=True):         self._server = self._loop.run_until_complete(self._server)         logging.info('Listening established on {0}'.format(self._server.sockets[0].getsockname()))         if and_loop:             self._loop.run_forever()          def stop(self, and_loop=True):         self._server.close()         if and_loop:             self._loop.close()          @asyncio.coroutine         def handle_connection(self, reader, writer):         peername = writer.get_extra_info('peername')         logging.info('Accepted connection from {}'.format(peername))         while reader.at_eof():             try:                 data = yield from asyncio.wait_for(reader.readline(), timeout=10.0)                 writer.write(data)             except concurrent.futures.TimeoutError:                 break         writer.close()  if __name__ == '__main__':     logging.basicConfig(level=logging.DEBUG)     server = EchoServer('127.0.0.1', 2007)     try:         server.start()     except KeyboardInterrupt:         pass # Press Ctrl+C to stop     finally:         server.stop() <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0434 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439. \u0410 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043a\u043e\u0434 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d \u0432 \u0441\u0430\u043c\u043e\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<h4>HTTP Server<\/h4>\n<p>  \u0420\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u043d\u0435\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435. \u041c\u043e\u0434\u0443\u043b\u044c <code>asyncio<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438 \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u0412 \u043d\u0435\u043c \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 <code>tornado<\/code> \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d HTTP \u0441\u0435\u0440\u0432\u0435\u0440. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f \u0433\u0440\u0435\u0445 \u043d\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0443\u043f\u0443\u0449\u0435\u043d\u0438\u0435 \ud83d\ude42 <\/p>\n<p>  \u041f\u0438\u0441\u0430\u0442\u044c \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0441 \u043d\u0443\u043b\u044f HTTP \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 HTTPRequest \u0438 \u0442.\u00a0\u043f. \u2014 \u043d\u0435 \u0441\u043f\u043e\u0440\u0442\u0438\u0432\u043d\u043e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0430 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 WSGI. \u0422\u0435 \u043a\u0442\u043e \u0432 \u043a\u0443\u0440\u0441\u0435 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0437\u0430\u043c\u0435\u0442\u044f\u0442, \u0447\u0442\u043e WSGI \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b. \u042d\u0442\u043e \u0432\u0435\u0440\u043d\u043e, \u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f environ \u0438 \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0412\u044b\u0434\u0430\u0447\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 WSGI \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0438 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e coroutines \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0443\u044e \u0432 <code>asyncio<\/code>.<\/p>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"http:\/\/bottlepy.org\/docs\/0.12\/index.html\">bottle<\/a>. \u0422\u0430\u043a \u043e\u043d \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 \u043d\u0435 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0430 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0435\u0433\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e WSGI \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. <\/p>\n<p>  \u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/Alesh\/aqua\">\u0443 \u043c\u0435\u043d\u044f \u043d\u0430 github<\/a>. \u041d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432, \u043d\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u0430\u043c \u043f\u043e\u043a\u0430 \u043d\u0435\u0442, \u0437\u0430\u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0435\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 bottle \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u041e\u043d\u043e \u0432\u044b\u0434\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0438 \u043e\u0442\u0434\u0430\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0432 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043a\u0438\u0434\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0444\u0438\u043b\u044c\u043c\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u0445\u043e\u0441\u0442\u0438\u043d\u0433 \ud83d\ude42 <\/p>\n<p>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 <a href=\"https:\/\/bitbucket.org\/cherrypy\/cherrypy\/wiki\/Home\">CherryPy<\/a>, \u0432 \u0438\u0445 \u043a\u043e\u0434 \u044f \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u043b \u0438 \u043a\u043e\u0435-\u0447\u0442\u043e \u0432\u0437\u044f\u043b \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u00ab\u0441\u0432\u043e\u0438\u0445 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u043e\u0432\u00bb.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import bottle import os.path from os import listdir from bottle import route, template, static_file  root = os.path.abspath(os.path.dirname(__file__))    @route('\/') def index():     tmpl = &quot;&quot;&quot;&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Bottle of Aqua&lt;\/title&gt;&lt;\/head&gt; &lt;\/body&gt; &lt;h3&gt;List of files:&lt;\/h3&gt; &lt;ul&gt;   % for item in files:     &lt;li&gt;&lt;a href=&quot;\/files\/{{item}}&quot;&gt;{{item}}&lt;\/a&gt;&lt;\/li&gt;   % end &lt;\/ul&gt; &lt;\/body&gt; &lt;\/html&gt; &quot;&quot;&quot;     files = [file_name for file_name in listdir(os.path.join(root, 'files'))                         if os.path.isfile(os.path.join(root, 'files', file_name))]     return template(tmpl, files=files)   @route('\/files\/&lt;filename&gt;') def server_static(filename):     return static_file(filename, root=os.path.join(root,'files'))   class AquaServer(bottle.ServerAdapter):     &quot;&quot;&quot;Bottle server adapter&quot;&quot;&quot;     def run(self, handler):         import asyncio         import logging         from aqua.wsgiserver import WSGIServer                  logging.basicConfig(level=logging.ERROR)         loop = asyncio.get_event_loop()         server = WSGIServer(handler, loop=loop)         server.bind(self.host, self.port)          try:             loop.run_forever()         except KeyboardInterrupt:             pass # Press Ctrl+C to stop         finally:             server.unbindAll()             loop.close()  if __name__ == '__main__':     bottle.run(server=AquaServer, port=5000) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 WSGI \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u044f \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043d\u044e\u0430\u043d\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b \u0431\u044b\u043b\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0441\u0447\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044f <code>asyncio<\/code>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u044d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0445\u0440\u043e\u043c\u0430), \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0435\u0441\u043b\u0438 \u043e\u043d \u0432\u0438\u0434\u0438\u0442 \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0438\u0431\u043e \u0441\u043b\u0435\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u0438 \u0444\u0430\u0439\u043b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0448\u0442\u0430\u0442\u043d\u043e. \u041d\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>ConnectionResetError<\/code>, \u0435\u0441\u043b\u0438 \u043e\u0442\u0434\u0430\u0447\u0430 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u043d\u0435\u043c\u0443 \u0443\u0436\u0435 \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>StreamWriter.write()<\/code>. \u042d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>StreamWriter.close()<\/code>.<\/p>\n<h4>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0443\u0442\u0438\u043b\u0438\u0442\u0443 <a href=\"http:\/\/www.joedog.org\/siege-home\/\">siege<\/a>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0432\u044b\u0441\u0442\u0443\u043f\u0438\u043b\u0438 \u00ab\u043d\u0430\u0448 \u043f\u0430\u0446\u0438\u0435\u043d\u0442\u00bb (\u043e\u043d \u0436\u0435 aqua \ud83d\ude42 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <code>bottle<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 <a href=\"http:\/\/waitress.readthedocs.org\/en\/latest\/\">Waitress WSGI \u0441\u0435\u0440\u0432\u0435\u0440<\/a> \u0442\u043e\u0436\u0435 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <code>bottle<\/code> \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 Tornado. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u044b\u043b \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 helloword. \u0422\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: 100 \u0438 1000 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439; \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u0435\u0441\u0442\u0430 10 \u0441\u0435\u043a\u0443\u043d\u0434; \u0442\u0440\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043e\u0442\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e 13 \u0431\u0430\u0439\u0442, 13 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442 \u0438 13 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442. \u041d\u0438\u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<table cellpadding=\"2\">\n<tr>\n<th rowspan=\"2\"> 100<br \/>  concurent users   <\/th>\n<th colspan=\"2\"> 13 b   <\/th>\n<th colspan=\"2\"> 13 Kb   <\/th>\n<th colspan=\"2\"> 13 Mb   <\/th>\n<\/tr>\n<tr>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<\/tr>\n<tr>\n<td> aqua+bottle   <\/td>\n<td> 100,0%   <\/td>\n<td> 835,24   <\/td>\n<td> 100,0%   <\/td>\n<td> 804,49   <\/td>\n<td> 100,0%   <\/td>\n<td> 23,66   <\/td>\n<\/tr>\n<tr>\n<td> waitress+bootle   <\/td>\n<td> 100,0%   <\/td>\n<td> 707,24   <\/td>\n<td> 100,0%   <\/td>\n<td> 642,03   <\/td>\n<td> 100,0%   <\/td>\n<td> 1,76   <\/td>\n<\/tr>\n<tr>\n<td> tornado   <\/td>\n<td> 100,0%   <\/td>\n<td> 2282,45   <\/td>\n<td> 100,0%   <\/td>\n<td> 2071,27   <\/td>\n<td> 100,0%   <\/td>\n<td> 13,06   <\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<table cellpadding=\"2\">\n<tr>\n<th rowspan=\"2\"> 1000<br \/>  concurent users   <\/th>\n<th colspan=\"2\"> 13 b   <\/th>\n<th colspan=\"2\"> 13 Kb   <\/th>\n<th colspan=\"2\"> 13 Mb   <\/th>\n<\/tr>\n<tr>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<td> Avail.   <\/td>\n<td> Trans\/sec   <\/td>\n<\/tr>\n<tr>\n<td> aqua+bottle   <\/td>\n<td> 99,9%   <\/td>\n<td> 800,41   <\/td>\n<td> 99,9%   <\/td>\n<td> 777,15   <\/td>\n<td> 100,0%   <\/td>\n<td> 25,22   <\/td>\n<\/tr>\n<tr>\n<td> waitress+bootle   <\/td>\n<td> 94,9%   <\/td>\n<td> 689,23   <\/td>\n<td> 99,9%   <\/td>\n<td> 621,03   <\/td>\n<td> 100,0%   <\/td>\n<td> 4,37   <\/td>\n<\/tr>\n<tr>\n<td> tornado   <\/td>\n<td> 100,0%   <\/td>\n<td> 1239,88   <\/td>\n<td> 100,0%   <\/td>\n<td> 978,73   <\/td>\n<td> 100,0%   <\/td>\n<td> 7,61   <\/td>\n<\/tr>\n<\/table>\n<p>  \u041d\u0443 \u0447\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c? Tornado \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0440\u0443\u043b\u0438\u0442, \u043d\u043e \u00ab\u043d\u0430\u0448 \u043f\u0430\u0446\u0438\u0435\u043d\u0442\u00bb \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u044b\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u043b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043e\u043d \u0443\u0432\u0435\u0440\u0435\u043d\u043e \u043e\u0431\u043e\u0448\u0435\u043b waitress (\u0441 \u0435\u0433\u043e \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u043f\u043e \u0447\u0438\u0441\u043b\u0443 \u044f\u0434\u0435\u0440), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043d\u0430 \u043f\u043b\u043e\u0445\u043e\u043c \u0441\u0447\u0435\u0442\u0443 \u0441\u0440\u0435\u0434\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u041d\u0435 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043c\u043e\u0451 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e \u043d\u0430 100%, \u043d\u043e \u043a\u0430\u043a \u043e\u0446\u0435\u043d\u043e\u0447\u043d\u043e\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u0441\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u043b\u043e\u0433 \u0435\u0449\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0431\u043e\u043b\u0435\u0435 \u0436\u0435\u0441\u0442\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432. 100 \u0438 1000 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, 13Mb \u0442\u0435\u043b\u043e, 60 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0434 asyncio \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u0435\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c (\u043f\u043e \u043f\u043e\u0440\u0442\u0430\u043c 5000 aqua; 5002 tornado)<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>$ siege -c 100 -b -t 60S http:\/\/127.0.0.1:5000\/ ** SIEGE 2.70 ** Preparing 100 concurrent users for battle. The server is now under siege... Lifting the server siege...      done. Transactions:               1556 hits Availability:              99.87 % Elapsed time:              59.21 secs Data transferred:       20228.00 MB Response time:              3.69 secs Transaction rate:          26.28 trans\/sec Throughput:           341.63 MB\/sec Concurrency:               96.87 Successful transactions:        1556 Failed transactions:               2 Longest transaction:            4.53 Shortest transaction:           1.15  $ siege -c 1000 -b -t 60S http:\/\/127.0.0.1:5000\/ ** SIEGE 2.70 ** Preparing 1000 concurrent users for battle. Transactions:               1570 hits Availability:              60.18 % Elapsed time:              59.84 secs Data transferred:       20410.00 MB Response time:              5.56 secs Transaction rate:          26.24 trans\/sec Throughput:           341.08 MB\/sec Concurrency:              145.80 Successful transactions:        1570 Failed transactions:            1039 Longest transaction:           20.44 Shortest transaction:           0.00  $ siege -c 100 -b -t 60S http:\/\/127.0.0.1:5002\/ ** SIEGE 2.70 ** Preparing 100 concurrent users for battle. The server is now under siege... Lifting the server siege...      done. Transactions:                942 hits Availability:             100.00 % Elapsed time:              59.69 secs Data transferred:       12246.00 MB Response time:              5.97 secs Transaction rate:          15.78 trans\/sec Throughput:           205.16 MB\/sec Concurrency:               94.25 Successful transactions:         942 Failed transactions:               0 Longest transaction:           14.82 Shortest transaction:           0.57  $ siege -c 1000 -b -t 60S http:\/\/127.0.0.1:5002\/ ** SIEGE 2.70 ** Preparing 1000 concurrent users for battle. The server is now under siege... Lifting the server siege...      done. Transactions:                857 hits Availability:              55.65 % Elapsed time:              59.07 secs Data transferred:       11141.00 MB Response time:             20.14 secs Transaction rate:          14.51 trans\/sec Throughput:           188.61 MB\/sec Concurrency:              292.16 Successful transactions:         857 Failed transactions:             683 Longest transaction:           51.19 Shortest transaction:           3.26 <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>OUTRO<\/h4>\n<p>  \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u0435\u0431\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>asyncio<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043d\u0430 \u0436\u0438\u0437\u043d\u044c. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0432 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043f\u043e\u043a\u0430 \u0440\u0430\u043d\u043e, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0431\u043a\u0430\u0442\u043a\u0438 \u0438 \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 <code>asyncio<\/code> \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u043c \u2014 \u044d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/217143\/\"> http:\/\/habrahabr.ru\/post\/217143\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0437\u0430\u0440\u0435\u043b\u0438\u0437\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <b>Python 3.4<\/b> \u0432 <a href=\"https:\/\/www.python.org\/download\/releases\/3.4.0\/\">changelog<\/a> \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043e\u0448\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u00ab\u0432\u043a\u0443\u0441\u043d\u043e\u0441\u0442\u0435\u0439\u00bb. \u041e\u0434\u043d\u0430 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u2014 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"http:\/\/docs.python.org\/dev\/library\/asyncio.html\">asyncio<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u0443\u044e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (coroutines), \u043a\u043e\u0434 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438. <\/p>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e TCP (Echo) \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441 \u0447\u0435\u043c \u0435\u0434\u044f\u0442 <code>asyncio<\/code>, \u0438 \u0440\u0438\u0441\u043a\u043d\u0443 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u00ab\u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a\u00bb \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e HTTP \u0441\u0435\u0440\u0432\u0435\u0440\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217143","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217143"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217143\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}