Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asyncio/Aiohttp — предел производительности

Asyncio/Aiohttp — предел производительности

Павел Петлинский @ Moscow Python

Moscow Python Meetup

May 23, 2016
Tweet

More Decks by Moscow Python Meetup

Other Decks in Programming

Transcript

  1. 40 50+ 700 1700+ млн человек суммарная аудитория группы количество

    изданий,
 сервисов и проектов разработчиков человек в хорошей компании
  2. Контакты В группе компаний Rambler&Co всегда есть открытые вакансии для

    тех, кто хочет профессионально расти и развиваться, занимаясь тем, что по-настоящему нравится [email protected] www.rambler-co.ru/jobs
  3. Python 3.5 @asyncio.coroutine vs. async def Coroutines used with asyncio

    may be implemented using the async def statement, or by using generators. … Things a coroutine can do: • result = await future or result = yield from future – suspends the coroutine until the future is done, then returns the future’s result, or raises an exception, which will be propagated. (If the future is cancelled, it will raise a CancelledError exception.) Note that tasks are futures, and everything said about futures also applies to tasks. • result = await coroutine or result = yield from coroutine – wait for another coroutine to produce a result (or raise an exception, which will be propagated). The coroutine expression must be a call to another coroutine. (c) https://docs.python.org/3/library/asyncio-task.html 7
  4. Как измерить RPS? wrk -t 80 -c 80 -d 10s

    http://127.0.0.1:8080/test 80 threads and 80 connections …. Requests/sec: 2339.74 13
  5. Как измерить RPS? /usr/local/bin/weighttp -n 800 -c 80 127.0.0.1:8080/test/ …

    spawning thread #1: 80 concurrent requests, 800 total requests … finished in 0 sec, 619 millisec and 649 microsec, 1291 req/s, 220 kbyte/s status codes: 800 2xx, 0 3xx, 0 4xx, 0 5xx 14
  6. 15

  7. Как измерить RPS? “wrk creates all TCP connections first, and,

    then only, it sends HTTP requests” • real Web users send an HTTP request immediately after the TCP handshake • wrk masks the ability (or the inability) of a server to quickly accept and close connections (c) http://gwan.com/en_apachebench_httperf.html 16
  8. UVLoop - маркетинг или реальность? wrk -t 80 -c 80

    -d 10s http://127.0.0.1:8080/test … 80 threads and 80 connections … Requests/sec: 2739.65 19
  9. UVLoop - маркетинг или реальность? /usr/local/bin/weighttp -n 8000 -c 80

    127.0.0.1:8080/test/ …. spawning thread #1: 80 concurrent requests, 8000 total requests … finished in 3 sec, 201 millisec and 135 microsec, 2499 req/s, 427 kbyte/s status codes: 8000 2xx, 0 3xx, 0 4xx, 0 5xx 20
  10. Где наши 10k rps??? 23 •Получение и парсинг http запроса

    - 100 мкс •Роутинг - 30 мкс •Метод send_headers - 180 мкс • etc…
  11. Выводы 24 • HTTP протокол - это дорого! • Используйте

    правильные инструменты для замеров • Читайте исходники • Бенчмарки врут :-)