WebCamp 2016: Python. Михаил Бегерский: Использование asyncio-стека...
-
Upload
webcamp -
Category
Technology
-
view
169 -
download
3
Transcript of WebCamp 2016: Python. Михаил Бегерский: Использование asyncio-стека...
1
About
Python developer @ DataRobot
2
Benchmark [1]
3
Benchmark
4
Database drivers
● aiocouchdb● aiomysql● aioredis● aiozmq● aioes● aiopg● aiokafka● aioodbc● aiomcache
5
SQLAlchemy
6
Faster postgre client?
$ pip install asyncpg
7
Mongo? [2]
8
aiohttp_jinja2
9
aiohttp_debugtoolbar
10
aiohttp_debugtoolbar
$ pip install aiohttp_debugtoolbar
11
aiohttp_debugtoolbar
12
aiohttp_debugtoolbar
13
aiohttp_debugtoolbar
14
aiohttp_session
● SimpleCookieStorage
● EncryptedCookieStorage
● RedisStorage
15
aiohttp_session
16
aiohttp_security
● AbstractIdentityPolicy
● AbstractAuthorizationPolicy
● remember()
● forget()
● authorized_userid()
● permits()
17
aiohttp_security
18
aiohttp_security
19
Slowloris
$ nmap --script http-slowloris-check 127.0.0.1 -p 8080
20
Web-sockets [3]
21
Middleware
22
Middleware
23
aiohttp client [4]
24
aiohttp_admin
25
aiohttp_admin
26
Other tools [5]
● aiohttp_runserver
● aiohttp_cors
● aiohttp_traversal
● aiothrottle
● aiohttp_mako
● and more ...
27
Project structure
28
Debug
$ export PYTHONASYNCIODEBUG=1
● explicit loop
● releasing resources
● awaititng coroutines
$ python script.py -Wdefault
29
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
Debug
$ ConnectionResetError: [Errno 54] Connect call failed ('127.0.0.1', 8080)
$ OSError: [Errno 24] Too many open files
31
Debug
32
Testing
33
Testing
34
Testing [6]
35
Go production!
$ gunicorn app_module:app --bind localhost:8080 --worker-class aiohttp.worker.GunicornWebWorker
36
Graceful shutdown
37
Production architecture 38
Resources
1. klen.github.io/py-frameworks-bench/
2. emptysqua.re/blog/
3. igordavydenko.com/talks/lvivpy-5/
4. pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html
5. github.com/python/asyncio/wiki/ThirdParty
6. asvetlov.github.io/pytest-slides/
39
Thanks for your attention
https://github.com/kpidata/webcamp16
@bmwant
bmwlog.pp.ua
40
Let’s have some fun!
my-mail [ at ] gmail [ dot ] com
41