SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
The State of WebSockets in Django
Rami Sayar - @ramisayar
Technical Evangelist
Microsoft Canada
Agenda
•  Where is WebSockets right now?
•  Where is Socket.IO?
•  Where does Django fit in?
•  Using Django SwampDragon.
•  Using Gevent.
CONFOO - @RAMISAYAR
Assumptions
•  Working knowledge of Django, JavaScript & Python.
Note: Slides will be made available.
CONFOO - @RAMISAYAR
What is a production web app?
•  Django is surrounded by tons
of applications, services and
code in production.
•  Advanced Django architecture
is needed to support Django
in production without failing
hard.
•  WebSockets falls apart from
the rest.
CONFOO - @RAMISAYAR
WebSockets
•  “WebSocket is a protocol for
full-duplex communication
channels over a single TCP
connection.” Wikipedia
•  Image Reference
CONFOO - @RAMISAYAR
WebSockets
CONFOO - @RAMISAYAR
Socket.IO
•  “Socket.IO enables real-time
bidirectional event-based
communication. It works on
every platform, browser or
device, focusing equally on
reliability and speed.”
Reference
•  Use by everyone: Microsoft
Office, Yammer, Zendesk,
Trello, etc…
CONFOO - @RAMISAYAR
Socket.IO Version 1.0 is here!
Technically, now at v1.3.4
CONFOO - @RAMISAYAR
Python, Django & WebSockets.
CONFOO - @RAMISAYAR
Python and WebSockets
•  Python and WebSockets has notoriously been very difficult.
•  Two reasons:
•  WSGI protocol does not support WebSockets. Most popular form of
web request handling in the Python web apps. Most frameworks are
designed for use with FastCGI or mod_wsgi, etc.
•  Default Python networked apps not exactly designed for event-based
communication, you have to use things like gevent and twisted/tornado.
CONFOO - @RAMISAYAR
Django & WebSockets
•  Django applications complete HttpResponses.
•  Django not well suited for WebSocket event handling structure
nor the channel approach in Socket.IO.
CONFOO - @RAMISAYAR
Presenting 3 Methods for WebSockets in Django
CONFOO - @RAMISAYAR
gevent
•  “gevent is a coroutine-based Python networking library that
uses greenlets to provide a synchronous API on top of the libev
event loop.”
•  Event loop based on libev (same as Node.js)
•  Lightweight execution units, a.k.a. “lightweight threads”.
•  Cooperative sockets with SSL support.
•  Similar programming model to Node.js.
CONFOO - @RAMISAYAR
gevent-socketio
•  gevent-socketio is a pure Python implementation of the
Socket.IO protocol. Basically, it is a port of Socket.IO and
typically behind in major releases.
•  Designed to work with multiple different WSGI-based web
frameworks.
•  Handles the “WSGI” problem by providing a custom gevent
WSGI server for use with gevent-socketio.
•  Only dependencies are gevent.
•  Imperfect solution: Django is still blocking (monkey
patching is not perfect).
CONFOO - @RAMISAYAR
Demo 1: Django chat engine with gevent-socketio
https://github.com/abourget/gevent-socketio/tree/master/examples/
django_chat
CONFOO - @RAMISAYAR
“Native” Django Implementation
•  Previous approach requires significant modifications to your
current Django app serving stack. Native as in you don’t need to
know anything besides Django.
•  Building an implementation of WebSockets on top of Django.
•  Identified two problems for WebSockets in Django:
•  Problems with WSGI still present EXCEPT in uWSGI.
•  Networked event handling model is problematic.
•  Solution:
•  Use Nginx which follows – event-driven async architecture.
•  uWSGI & Gevent for event handling.
CONFOO - @RAMISAYAR
Django-WebSocket-Redis
•  Module implements websockets on top of Django.
•  Use Redis as a data store for messaging behind uWSGI and Nginx.
•  Runs a separate Django main loop in a cooperative concurrency
model using gevent -> 1 thread for all open websockets.
•  Django can be started as usual with ‘./manage.py runserver’.
•  Normal requests communication with separate main (websocket)
loop through Redis.
•  Read:
Offloading Websockets and Server-Sent Events AKA “Combine
them with Django safely”
CONFOO - @RAMISAYAR
Demo 2: Django-WebSockets-Redis
https://github.com/jrief/django-websocket-redis
CONFOO - @RAMISAYAR
SwampDragon
•  New project that adds websocket support
•  Self-publishing models
•  Django ORM Style Data Filter for Subscription Channels –
Similar to WebSockets + Data Filter
•  Relies on Redis for messaging + Tornado
•  Angular JS Support
CONFOO - @RAMISAYAR
Demo 3: Django Swampdragon
https://github.com/jonashagstedt/swampdragon
CONFOO - @RAMISAYAR
On Redis
•  Redis is extremely popular as an easy and simple publish-
subscribe.
•  Redis is very particular about memory. Running out of memory
in Redis -> CRASH AND BURN!
•  If you don’t have enough memory in your VM to run Redis
Cache -> Change your approach, use Apache Kafka.
CONFOO - @RAMISAYAR
What did we learn?
•  The State of WebSockets in Django.
•  Django and WebSockets is not impossible.
CONFOO - @RAMISAYAR
Thank You! Questions?
Follow @ramisayar
CONFOO - @RAMISAYAR
Resources
•  http://swampdragon.net/
•  http://django-websocket-redis.readthedocs.org/en/latest/
•  https://github.com/jrief/django-websocket-redis
•  https://github.com/abourget/gevent-socketio/tree/master/
examples/django_chat
•  http://jpadilla.com/post/74391616727/the-easiest-way-to-add-
websockets-to-django
•  http://ferretfarmer.net/2013/09/05/tutorial-real-time-chat-with-
django-twisted-and-websockets-part-1/
CONFOO - @RAMISAYAR
©2013	
  Microso-	
  Corpora1on.	
  All	
  rights	
  reserved.	
  Microso-,	
  Windows,	
  Office,	
  Azure,	
  System	
  Center,	
  Dynamics	
  and	
  other	
  product	
  names	
  are	
  or	
  may	
  be	
  registered	
  trademarks	
  and/or	
  trademarks	
  in	
  the	
  
U.S.	
  and/or	
  other	
  countries.	
  The	
  informa1on	
  herein	
  is	
  for	
  informa1onal	
  purposes	
  only	
  and	
  represents	
  the	
  current	
  view	
  of	
  Microso-	
  Corpora1on	
  as	
  of	
  the	
  date	
  of	
  this	
  presenta1on.	
  Because	
  Microso-	
  
must	
  respond	
  to	
  changing	
  market	
  condi1ons,	
  it	
  should	
  not	
  be	
  interpreted	
  to	
  be	
  a	
  commitment	
  on	
  the	
  part	
  of	
  Microso-,	
  and	
  Microso-	
  cannot	
  guarantee	
  the	
  accuracy	
  of	
  any	
  informa1on	
  provided	
  a-er	
  
the	
  date	
  of	
  this	
  presenta1on.	
  MICROSOFT	
  MAKES	
  NO	
  WARRANTIES,	
  EXPRESS,	
  IMPLIED	
  OR	
  STATUTORY,	
  AS	
  TO	
  THE	
  INFORMATION	
  IN	
  THIS	
  PRESENTATION.	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Codemotion
 
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...Codemotion
 
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...Demi Ben-Ari
 
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Ontico
 
Web frameworks don't matter
Web frameworks don't matterWeb frameworks don't matter
Web frameworks don't matterTomas Doran
 
Cloudstack China User Group Report
Cloudstack China User Group ReportCloudstack China User Group Report
Cloudstack China User Group Reportgavin_lee
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentationasync_io
 
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016Chris Gates
 
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...Codemotion
 
JavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAPJavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAPSimon Bennetts
 
OWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced FeaturesOWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced FeaturesSimon Bennetts
 
OWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAPOWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAPSimon Bennetts
 
RSYSLOG v8 improvements and how to write plugins in any language.
RSYSLOG v8 improvements and how to write plugins in any language.RSYSLOG v8 improvements and how to write plugins in any language.
RSYSLOG v8 improvements and how to write plugins in any language.Rainer Gerhards
 
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...Zabbix
 
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP InnovationsOWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP InnovationsSimon Bennetts
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git togetherColdFusionConference
 
Automating OWASP ZAP - DevCSecCon talk
Automating OWASP ZAP - DevCSecCon talk Automating OWASP ZAP - DevCSecCon talk
Automating OWASP ZAP - DevCSecCon talk Simon Bennetts
 
OWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP IntroOWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP IntroSimon Bennetts
 

Was ist angesagt? (20)

Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
 
Mini-Training: Redis
Mini-Training: RedisMini-Training: Redis
Mini-Training: Redis
 
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
 
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
 
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
 
Web frameworks don't matter
Web frameworks don't matterWeb frameworks don't matter
Web frameworks don't matter
 
Cloudstack China User Group Report
Cloudstack China User Group ReportCloudstack China User Group Report
Cloudstack China User Group Report
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
 
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
 
JavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAPJavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAP
 
OWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced FeaturesOWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced Features
 
OWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAPOWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAP
 
RSYSLOG v8 improvements and how to write plugins in any language.
RSYSLOG v8 improvements and how to write plugins in any language.RSYSLOG v8 improvements and how to write plugins in any language.
RSYSLOG v8 improvements and how to write plugins in any language.
 
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
 
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP InnovationsOWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
 
Automating OWASP ZAP - DevCSecCon talk
Automating OWASP ZAP - DevCSecCon talk Automating OWASP ZAP - DevCSecCon talk
Automating OWASP ZAP - DevCSecCon talk
 
OWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP IntroOWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP Intro
 

Andere mochten auch

JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
Websockets: Pushing the web forward
Websockets: Pushing the web forwardWebsockets: Pushing the web forward
Websockets: Pushing the web forwardMark Roden
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...Frank Munz
 
Maximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPMaximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPKenneth Peeples
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListMainstreethost
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes EverythingLori MacVittie
 
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAmazon Web Services
 
HTML5 WebSockets in Python/Django
HTML5 WebSockets in Python/DjangoHTML5 WebSockets in Python/Django
HTML5 WebSockets in Python/DjangoTony Abou-Assaleh
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisYork Tsai
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
Real time web_apps_pycon2012-v1
Real time web_apps_pycon2012-v1Real time web_apps_pycon2012-v1
Real time web_apps_pycon2012-v1Avinash Prasad
 
PyConMY 2016 Django Channels
PyConMY 2016 Django ChannelsPyConMY 2016 Django Channels
PyConMY 2016 Django ChannelsKok Hoor Chew
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeRami Sayar
 
FITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedFITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedRami Sayar
 
Redis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button gamesRedis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button gamesRedis Labs
 
Hacking websockets
Hacking websocketsHacking websockets
Hacking websocketsTomek Cejner
 
laravel websocket(use redis pubsub) [Laravel meetup tokyo]
laravel websocket(use redis pubsub) [Laravel meetup tokyo]laravel websocket(use redis pubsub) [Laravel meetup tokyo]
laravel websocket(use redis pubsub) [Laravel meetup tokyo]Yuuki Takezawa
 
Implementation of RSA Algorithm for Speech Data Encryption and Decryption
Implementation of RSA Algorithm for Speech Data Encryption and DecryptionImplementation of RSA Algorithm for Speech Data Encryption and Decryption
Implementation of RSA Algorithm for Speech Data Encryption and DecryptionMd. Ariful Hoque
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 

Andere mochten auch (20)

JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
Websockets: Pushing the web forward
Websockets: Pushing the web forwardWebsockets: Pushing the web forward
Websockets: Pushing the web forward
 
Reducing load with RabbitMQ
Reducing load with RabbitMQReducing load with RabbitMQ
Reducing load with RabbitMQ
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
 
Maximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPMaximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQP
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive List
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
 
HTML5 WebSockets in Python/Django
HTML5 WebSockets in Python/DjangoHTML5 WebSockets in Python/Django
HTML5 WebSockets in Python/Django
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Real time web_apps_pycon2012-v1
Real time web_apps_pycon2012-v1Real time web_apps_pycon2012-v1
Real time web_apps_pycon2012-v1
 
PyConMY 2016 Django Channels
PyConMY 2016 Django ChannelsPyConMY 2016 Django Channels
PyConMY 2016 Django Channels
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
FITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedFITC - Bootstrap Unleashed
FITC - Bootstrap Unleashed
 
Redis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button gamesRedis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button games
 
Hacking websockets
Hacking websocketsHacking websockets
Hacking websockets
 
laravel websocket(use redis pubsub) [Laravel meetup tokyo]
laravel websocket(use redis pubsub) [Laravel meetup tokyo]laravel websocket(use redis pubsub) [Laravel meetup tokyo]
laravel websocket(use redis pubsub) [Laravel meetup tokyo]
 
Implementation of RSA Algorithm for Speech Data Encryption and Decryption
Implementation of RSA Algorithm for Speech Data Encryption and DecryptionImplementation of RSA Algorithm for Speech Data Encryption and Decryption
Implementation of RSA Algorithm for Speech Data Encryption and Decryption
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 

Ähnlich wie The State of WebSockets in Django

Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django ArchitectureRami Sayar
 
Realtime rocks
Realtime rocksRealtime rocks
Realtime rocksVanbosse
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Pierre Joye
 
Python Web Framework – A Detailed List of Web Frameworks in Python
Python Web Framework – A Detailed List of Web Frameworks in PythonPython Web Framework – A Detailed List of Web Frameworks in Python
Python Web Framework – A Detailed List of Web Frameworks in Pythonabhishekdf3
 
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTWebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTFrank Greco
 
End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013Alexandre Morgaut
 
Laug Mootools And Common Js
Laug   Mootools And Common JsLaug   Mootools And Common Js
Laug Mootools And Common JsSkills Matter
 
Web Frameworks of the Future
Web Frameworks of the FutureWeb Frameworks of the Future
Web Frameworks of the Futureelliando dias
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.jsKasey McCurdy
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsKonrad Malawski
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Todaydavyjones
 
Janus Workshop @ ClueCon 2020
Janus Workshop @ ClueCon 2020Janus Workshop @ ClueCon 2020
Janus Workshop @ ClueCon 2020Lorenzo Miniero
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Tom Brander
 

Ähnlich wie The State of WebSockets in Django (20)

Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 
Realtime rocks
Realtime rocksRealtime rocks
Realtime rocks
 
Realtime web2012
Realtime web2012Realtime web2012
Realtime web2012
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18
 
Python Web Framework – A Detailed List of Web Frameworks in Python
Python Web Framework – A Detailed List of Web Frameworks in PythonPython Web Framework – A Detailed List of Web Frameworks in Python
Python Web Framework – A Detailed List of Web Frameworks in Python
 
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTWebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
 
End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013
 
Laug Mootools And Common Js
Laug   Mootools And Common JsLaug   Mootools And Common Js
Laug Mootools And Common Js
 
Web Frameworks of the Future
Web Frameworks of the FutureWeb Frameworks of the Future
Web Frameworks of the Future
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
 
Node
NodeNode
Node
 
Django
DjangoDjango
Django
 
Stackato v3
Stackato v3Stackato v3
Stackato v3
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
 
NodeJS and what is actually does
NodeJS and what is actually doesNodeJS and what is actually does
NodeJS and what is actually does
 
Splunking the JVM
Splunking the JVMSplunking the JVM
Splunking the JVM
 
Janus Workshop @ ClueCon 2020
Janus Workshop @ ClueCon 2020Janus Workshop @ ClueCon 2020
Janus Workshop @ ClueCon 2020
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
 

Mehr von Rami Sayar

FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesRami Sayar
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS DebuggingRami Sayar
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemRami Sayar
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Rami Sayar
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressRami Sayar
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingRami Sayar
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
FITC - Data Visualization in Practice
FITC - Data Visualization in PracticeFITC - Data Visualization in Practice
FITC - Data Visualization in PracticeRami Sayar
 

Mehr von Rami Sayar (8)

FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React Ecosystem
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
FITC - Data Visualization in Practice
FITC - Data Visualization in PracticeFITC - Data Visualization in Practice
FITC - Data Visualization in Practice
 

Kürzlich hochgeladen

办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 

Kürzlich hochgeladen (11)

办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 

The State of WebSockets in Django

  • 1. The State of WebSockets in Django Rami Sayar - @ramisayar Technical Evangelist Microsoft Canada
  • 2. Agenda •  Where is WebSockets right now? •  Where is Socket.IO? •  Where does Django fit in? •  Using Django SwampDragon. •  Using Gevent. CONFOO - @RAMISAYAR
  • 3. Assumptions •  Working knowledge of Django, JavaScript & Python. Note: Slides will be made available. CONFOO - @RAMISAYAR
  • 4. What is a production web app? •  Django is surrounded by tons of applications, services and code in production. •  Advanced Django architecture is needed to support Django in production without failing hard. •  WebSockets falls apart from the rest. CONFOO - @RAMISAYAR
  • 5. WebSockets •  “WebSocket is a protocol for full-duplex communication channels over a single TCP connection.” Wikipedia •  Image Reference CONFOO - @RAMISAYAR
  • 7. Socket.IO •  “Socket.IO enables real-time bidirectional event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed.” Reference •  Use by everyone: Microsoft Office, Yammer, Zendesk, Trello, etc… CONFOO - @RAMISAYAR
  • 8. Socket.IO Version 1.0 is here! Technically, now at v1.3.4 CONFOO - @RAMISAYAR
  • 9. Python, Django & WebSockets. CONFOO - @RAMISAYAR
  • 10. Python and WebSockets •  Python and WebSockets has notoriously been very difficult. •  Two reasons: •  WSGI protocol does not support WebSockets. Most popular form of web request handling in the Python web apps. Most frameworks are designed for use with FastCGI or mod_wsgi, etc. •  Default Python networked apps not exactly designed for event-based communication, you have to use things like gevent and twisted/tornado. CONFOO - @RAMISAYAR
  • 11. Django & WebSockets •  Django applications complete HttpResponses. •  Django not well suited for WebSocket event handling structure nor the channel approach in Socket.IO. CONFOO - @RAMISAYAR
  • 12. Presenting 3 Methods for WebSockets in Django CONFOO - @RAMISAYAR
  • 13. gevent •  “gevent is a coroutine-based Python networking library that uses greenlets to provide a synchronous API on top of the libev event loop.” •  Event loop based on libev (same as Node.js) •  Lightweight execution units, a.k.a. “lightweight threads”. •  Cooperative sockets with SSL support. •  Similar programming model to Node.js. CONFOO - @RAMISAYAR
  • 14. gevent-socketio •  gevent-socketio is a pure Python implementation of the Socket.IO protocol. Basically, it is a port of Socket.IO and typically behind in major releases. •  Designed to work with multiple different WSGI-based web frameworks. •  Handles the “WSGI” problem by providing a custom gevent WSGI server for use with gevent-socketio. •  Only dependencies are gevent. •  Imperfect solution: Django is still blocking (monkey patching is not perfect). CONFOO - @RAMISAYAR
  • 15. Demo 1: Django chat engine with gevent-socketio https://github.com/abourget/gevent-socketio/tree/master/examples/ django_chat CONFOO - @RAMISAYAR
  • 16. “Native” Django Implementation •  Previous approach requires significant modifications to your current Django app serving stack. Native as in you don’t need to know anything besides Django. •  Building an implementation of WebSockets on top of Django. •  Identified two problems for WebSockets in Django: •  Problems with WSGI still present EXCEPT in uWSGI. •  Networked event handling model is problematic. •  Solution: •  Use Nginx which follows – event-driven async architecture. •  uWSGI & Gevent for event handling. CONFOO - @RAMISAYAR
  • 17. Django-WebSocket-Redis •  Module implements websockets on top of Django. •  Use Redis as a data store for messaging behind uWSGI and Nginx. •  Runs a separate Django main loop in a cooperative concurrency model using gevent -> 1 thread for all open websockets. •  Django can be started as usual with ‘./manage.py runserver’. •  Normal requests communication with separate main (websocket) loop through Redis. •  Read: Offloading Websockets and Server-Sent Events AKA “Combine them with Django safely” CONFOO - @RAMISAYAR
  • 19. SwampDragon •  New project that adds websocket support •  Self-publishing models •  Django ORM Style Data Filter for Subscription Channels – Similar to WebSockets + Data Filter •  Relies on Redis for messaging + Tornado •  Angular JS Support CONFOO - @RAMISAYAR
  • 20. Demo 3: Django Swampdragon https://github.com/jonashagstedt/swampdragon CONFOO - @RAMISAYAR
  • 21. On Redis •  Redis is extremely popular as an easy and simple publish- subscribe. •  Redis is very particular about memory. Running out of memory in Redis -> CRASH AND BURN! •  If you don’t have enough memory in your VM to run Redis Cache -> Change your approach, use Apache Kafka. CONFOO - @RAMISAYAR
  • 22. What did we learn? •  The State of WebSockets in Django. •  Django and WebSockets is not impossible. CONFOO - @RAMISAYAR
  • 23. Thank You! Questions? Follow @ramisayar CONFOO - @RAMISAYAR
  • 24. Resources •  http://swampdragon.net/ •  http://django-websocket-redis.readthedocs.org/en/latest/ •  https://github.com/jrief/django-websocket-redis •  https://github.com/abourget/gevent-socketio/tree/master/ examples/django_chat •  http://jpadilla.com/post/74391616727/the-easiest-way-to-add- websockets-to-django •  http://ferretfarmer.net/2013/09/05/tutorial-real-time-chat-with- django-twisted-and-websockets-part-1/ CONFOO - @RAMISAYAR
  • 25. ©2013  Microso-  Corpora1on.  All  rights  reserved.  Microso-,  Windows,  Office,  Azure,  System  Center,  Dynamics  and  other  product  names  are  or  may  be  registered  trademarks  and/or  trademarks  in  the   U.S.  and/or  other  countries.  The  informa1on  herein  is  for  informa1onal  purposes  only  and  represents  the  current  view  of  Microso-  Corpora1on  as  of  the  date  of  this  presenta1on.  Because  Microso-   must  respond  to  changing  market  condi1ons,  it  should  not  be  interpreted  to  be  a  commitment  on  the  part  of  Microso-,  and  Microso-  cannot  guarantee  the  accuracy  of  any  informa1on  provided  a-er   the  date  of  this  presenta1on.  MICROSOFT  MAKES  NO  WARRANTIES,  EXPRESS,  IMPLIED  OR  STATUTORY,  AS  TO  THE  INFORMATION  IN  THIS  PRESENTATION.  

Hinweis der Redaktion

  1. What does a web application look like in production?