Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Post on 17-Aug-2015

43 views 3 download

Tags:

transcript

Send Balls Into Orbit with Python3, AsyncIO,

WebSockets, Redis and React Taras Lyapun, KhmelnitskiyPy#1

About me

- Organizer of KhmelnytskyiPy- CTO at Turfmapp.com- Founder of Four-Eyes.IO

Turfmapp.com

• Find places and company to play soccer

• Like meetup.com, but soccer specific

• Like runkeeper.com, but for team sports

• Chicago based startup, with R&D office in Khmelnitskiy

What is this story about?

- We had everything for players before game

- But we didn’t have anything for game

- Introduce - Mini Challenges

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Python• Simple

• Maintainable

• Powerful

• Great syntax

• Can be used for anything:

• web

• network

• math

• ML

• NLP

• etc

• Great community!

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Python3

• New, modern version of Language

• A lot of improvements

• Unicode everywhere

• Lazy by default

• One more thing…

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

AsyncIO

• Allows you to start event loop, and execute your code asynchronously without additional libraries or frameworks

• So you can write your python code in both ways - sync and async, depends on your task

• Allows you easy support thousands persistent connections without threads overhead

• The best way to deal with network

Introduction to Asynchronous Programming

http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf

PEP-0492

PEP-0492

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

WebSockets

• Full-duplex communication channel over TCP

• Allow you to have real-time communication between server and client

• Supported by most browsers, but can be used also with any client (ios, android, whatever)

• aiohttp handles it well

aiohttp

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Redis

• Advanced Key-Value cache and store

• Strings, hashes, lists, sets, etc

• Publish Subscribe

• High performance with good enough level of persistency for this task

asyncio-redis

Another Decisions

• Always send full state of game (everything needed to display screen), instead of sending incremental updates - easy and error prone

• How to deal with concurrency updates? - Some sort of optimistic locks

• Use JSON for easy extending protocol

• Process all data through Redis - for easy scale

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Thanks!