SlideShare a Scribd company logo
1 of 23
Download to read offline
Websockets + Django
Ihor Harahatyi
Let's talk about:
Why we need websockets?
Why no WS in Django
Ways to get WS in Django
Not in this talk:
Async.io
How to develop a chat
Why to use websockets
Speed up transport
Bidirectional communication (live update)
Speed Up
Django web site
50K online
2M on peak
Q: How long it takes to render page?
A: 10 seconds
Use caching. Transfer is not your bottle neck with
Django
WSGI (pep333)
Request -> Middleware -> Process ->
Middleware -> Response
1 connection = 1 process
So how to get live update?
Ask if there is anything new
Separate WS provider
node.js
- No python
- No django
tornado/gevent/async.io
- Yes python
- ? django
Recycling
Django awarded MOSS Grant $150,000 to help fund the
development of Channels, the initiative to rewrite the
core of Django to support (among other things)
WebSockets and background tasks, and to integrate key
parts of the Django REST Framework request/ response
code into Django, such as content negotiation.
Django channels
in Django 1.10 Going to be in Django
Django auth
Channel
FIFO
Message expiry
At-most-once delivery to one listener
#routing.py
from app.consumers import ws_add, ws_message,
ws_disconnect
channel_routing = {
"websocket.connect": ws_add,
"websocket.receive": ws_message,
"websocket.disconnect": ws_disconnect,
}
Group
#consumers.py
@receiver(post_save, sender=LiveMatch)
def send_update(sender, instance, **kwargs):
Group("scoreboard").send({
"match": json.dumps({
"id": instance.id,
"content": MatchSerializer(instance).data
})
})
def ws_connect(message):
Group("scoreboard").add(message.reply_channel)
def ws_disconnect(message):
Group("sco").discard(message.reply_channel)
Cons
Uses ASGI (Daphne)
In Beta
Django >= 1.8
django-websocket-redis
uWSGI offers websockets
Uses gevent for WS
One line in requirements.txt
Django >=1.5
Con g
Run two uwsgi instances
Connect to redis
#nginx
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:/path/to/django.socket;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://unix:/path/to/web.socket;
}
Django auth
def get_allowed_channels(request, channels):
if not request.user.is_authenticated():
raise PermissionDenied
Incoming messages:
#settings.py
WS4REDIS_SUBSCRIBER = MyRedisSubscriber
#views.py
from django.views.generic.base import View
from ws4redis.publisher import RedisPublisher
class MyTypicalView(View):
facility = 'unique-named-facility'
audience = {'broadcast': True}
def __init__(self, *args, **kwargs):
super(MyTypicalView, self).init(*args, **kwargs)
self.redis_publisher =
RedisPublisher(facility, **self.audience)
def get(self, request)
message = 'A message'
self.redis_publisher.publish_message(message)
Kharkivpy

More Related Content

Viewers also liked

OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...OCCIware
 
Sara chamali museum
Sara chamali museumSara chamali museum
Sara chamali museumSara_Chamali
 
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8Đại Học FPT, FPT university
 
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open Wide
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open WideOCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open Wide
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open WideOCCIware
 
Django channels
Django channelsDjango channels
Django channelsAndy Dai
 
WHINT Solutions Turn-key integration content 2017-01
WHINT Solutions Turn-key integration content 2017-01WHINT Solutions Turn-key integration content 2017-01
WHINT Solutions Turn-key integration content 2017-01Adam Kiwon
 
forms of literary criticism.
forms of literary criticism.forms of literary criticism.
forms of literary criticism.nicalim
 
Разработка технологии разделения суммарного редкоземельного концентрата на гр...
Разработка технологии разделения суммарного редкоземельного концентрата на гр...Разработка технологии разделения суммарного редкоземельного концентрата на гр...
Разработка технологии разделения суммарного редкоземельного концентрата на гр...didym
 

Viewers also liked (11)

OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
 
Sara chamali museum
Sara chamali museumSara chamali museum
Sara chamali museum
 
RISE's Profile
RISE's ProfileRISE's Profile
RISE's Profile
 
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8
Câu lạc bộ Truyền thông Cóc Sài Gòn , Đại học FPT báo cáo hoạt động tháng 8
 
RISE's Training Catalog
RISE's Training CatalogRISE's Training Catalog
RISE's Training Catalog
 
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open Wide
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open WideOCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open Wide
OCCIware Project at EclipseCon France 2016, by Marc Dutoo, Open Wide
 
Django channels
Django channelsDjango channels
Django channels
 
Andrew O'Mahony CV PDF
Andrew O'Mahony CV PDFAndrew O'Mahony CV PDF
Andrew O'Mahony CV PDF
 
WHINT Solutions Turn-key integration content 2017-01
WHINT Solutions Turn-key integration content 2017-01WHINT Solutions Turn-key integration content 2017-01
WHINT Solutions Turn-key integration content 2017-01
 
forms of literary criticism.
forms of literary criticism.forms of literary criticism.
forms of literary criticism.
 
Разработка технологии разделения суммарного редкоземельного концентрата на гр...
Разработка технологии разделения суммарного редкоземельного концентрата на гр...Разработка технологии разделения суммарного редкоземельного концентрата на гр...
Разработка технологии разделения суммарного редкоземельного концентрата на гр...
 

Similar to Kharkivpy

A Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & DjangoA Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & DjangoPRASANNAVENK
 
Netty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityNetty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityC4Media
 
Understanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College StudentsUnderstanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College StudentsKetan Raval
 
The Need For Speed
The Need For SpeedThe Need For Speed
The Need For SpeedAndy Davies
 
OLPC Learning Club DC Jan 2009 Meeting
OLPC Learning Club DC Jan 2009 MeetingOLPC Learning Club DC Jan 2009 Meeting
OLPC Learning Club DC Jan 2009 MeetingMike Lee
 
Pinkoi Platform
Pinkoi PlatformPinkoi Platform
Pinkoi Platformmikeleeme
 
Tornado web
Tornado webTornado web
Tornado webkurtiss
 
Making it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceMaking it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceArjan
 
Web sockets in java EE 7 - JavaOne 2013
Web sockets in java EE 7 - JavaOne 2013Web sockets in java EE 7 - JavaOne 2013
Web sockets in java EE 7 - JavaOne 2013Siva Arunachalam
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESIKit Chan
 
WebRTC Reborn - Full Stack
WebRTC Reborn  - Full StackWebRTC Reborn  - Full Stack
WebRTC Reborn - Full StackDan Jenkins
 
WebRTC Reborn Over The Air
WebRTC Reborn Over The AirWebRTC Reborn Over The Air
WebRTC Reborn Over The AirDan Jenkins
 
CTE 323 - Lecture 1.pptx
CTE 323 - Lecture 1.pptxCTE 323 - Lecture 1.pptx
CTE 323 - Lecture 1.pptxOduniyiAdebola
 
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
 
HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)Kevin Gill
 
WebRTC Reborn - Cloud Expo / WebRTC Summit
WebRTC Reborn - Cloud Expo / WebRTC SummitWebRTC Reborn - Cloud Expo / WebRTC Summit
WebRTC Reborn - Cloud Expo / WebRTC SummitDan Jenkins
 

Similar to Kharkivpy (20)

Django
DjangoDjango
Django
 
A Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & DjangoA Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & Django
 
Netty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/ConnectivityNetty @Apple: Large Scale Deployment/Connectivity
Netty @Apple: Large Scale Deployment/Connectivity
 
Understanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College StudentsUnderstanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College Students
 
The Need For Speed
The Need For SpeedThe Need For Speed
The Need For Speed
 
OLPC Learning Club DC Jan 2009 Meeting
OLPC Learning Club DC Jan 2009 MeetingOLPC Learning Club DC Jan 2009 Meeting
OLPC Learning Club DC Jan 2009 Meeting
 
Pinkoi Platform
Pinkoi PlatformPinkoi Platform
Pinkoi Platform
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Tornado web
Tornado webTornado web
Tornado web
 
Making it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceMaking it fast: Zotonic & Performance
Making it fast: Zotonic & Performance
 
Web sockets in java EE 7 - JavaOne 2013
Web sockets in java EE 7 - JavaOne 2013Web sockets in java EE 7 - JavaOne 2013
Web sockets in java EE 7 - JavaOne 2013
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
 
WebRTC Reborn - Full Stack
WebRTC Reborn  - Full StackWebRTC Reborn  - Full Stack
WebRTC Reborn - Full Stack
 
WebRTC Reborn Over The Air
WebRTC Reborn Over The AirWebRTC Reborn Over The Air
WebRTC Reborn Over The Air
 
A jQuery for WebRTC
A jQuery for WebRTCA jQuery for WebRTC
A jQuery for WebRTC
 
CTE 323 - Lecture 1.pptx
CTE 323 - Lecture 1.pptxCTE 323 - Lecture 1.pptx
CTE 323 - Lecture 1.pptx
 
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?
 
HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)
 
dJango
dJangodJango
dJango
 
WebRTC Reborn - Cloud Expo / WebRTC Summit
WebRTC Reborn - Cloud Expo / WebRTC SummitWebRTC Reborn - Cloud Expo / WebRTC Summit
WebRTC Reborn - Cloud Expo / WebRTC Summit
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Kharkivpy