42
asyncio-stack for web- development Misha Behersky

asyncio stack for web-development

Embed Size (px)

Citation preview

Page 1: asyncio stack for web-development

asyncio-stack for web-development

Misha Behersky

Page 2: asyncio stack for web-development

About

Python developer @ DataRobot

2

Page 3: asyncio stack for web-development

Benchmark [1]

3

Page 4: asyncio stack for web-development

Benchmark

4

Page 6: asyncio stack for web-development

SQLAlchemy

6

Page 7: asyncio stack for web-development

Faster postgre client?

$ pip install asyncpg

7

Page 8: asyncio stack for web-development

Mongo? [2]

8

Page 9: asyncio stack for web-development

aiohttp_jinja2

9

Page 10: asyncio stack for web-development

aiohttp_debugtoolbar

10

Page 11: asyncio stack for web-development

aiohttp_debugtoolbar

$ pip install aiohttp_debugtoolbar

11

Page 12: asyncio stack for web-development

aiohttp_debugtoolbar

12

Page 13: asyncio stack for web-development

aiohttp_debugtoolbar

13

Page 14: asyncio stack for web-development

aiohttp_debugtoolbar

14

Page 16: asyncio stack for web-development

aiohttp_session

16

Page 18: asyncio stack for web-development

aiohttp_security

18

Page 19: asyncio stack for web-development

aiohttp_security

19

Page 20: asyncio stack for web-development

Slowloris

$ nmap --script http-slowloris-check 127.0.0.1 -p 8080

20

Page 21: asyncio stack for web-development

Web-sockets [3]

21

Page 22: asyncio stack for web-development

Middleware

22

Page 23: asyncio stack for web-development

Middleware

23

Page 24: asyncio stack for web-development

aiohttp client [4]

24

Page 25: asyncio stack for web-development

aiohttp_admin

25

Page 26: asyncio stack for web-development

aiohttp_admin

26

Page 27: asyncio stack for web-development

Other tools [5]

● aiohttp_runserver

● aiohttp_cors

● aiohttp_traversal

● aiothrottle

● aiohttp_mako

● and more ...

27

Page 28: asyncio stack for web-development

Project structure

28

Page 29: asyncio stack for web-development

Debug

$ export PYTHONASYNCIODEBUG=1

● explicit loop

● releasing resources

● awaititng coroutines

$ python script.py -Wdefault

29

Page 30: asyncio stack for web-development

Debug

$ Task was destroyed but it is pending!task: <Task pending coro=<fetch_bad() running at demo.py:14> wait_for=<Future pending cb=[Task._wakeup(), BaseSelectorEventLoop._sock_connect_done(10)()]>>

30

Page 31: asyncio stack for web-development

Debug

$ ConnectionResetError: [Errno 54] Connect call failed ('127.0.0.1', 8080)

$ OSError: [Errno 24] Too many open files

31

Page 32: asyncio stack for web-development

Debug

32

Page 33: asyncio stack for web-development

Testing

33

Page 34: asyncio stack for web-development

Testing

34

Page 35: asyncio stack for web-development

Testing [6]

35

Page 36: asyncio stack for web-development

Go production!

$ gunicorn app_module:app --bind localhost:8080 --worker-class aiohttp.worker.GunicornWebWorker

36

Page 37: asyncio stack for web-development

Graceful shutdown

37

Page 38: asyncio stack for web-development

Production architecture 38

Page 40: asyncio stack for web-development

Thanks for your attention

https://github.com/kpidata/webcamp16

[email protected]

@bmwant

bmwlog.pp.ua

40