SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Comet web applications with Python,
                 Django & Orbited


@ PyCon Italia Qu4ttro       Massimo Scamarcia
http://www.pycon.it/           http://www.webright.it/




                        
Comet web applications with Python,
        Django & Orbited




How to push real-time data to
      web browsers?



              
Comet web applications with Python,
                  Django & Orbited


AJAX Polling
   Client: sends AJAX request.
   Server:
       Data available: sends response.
       No data: sends empty response.
   Client: sends AJAX request again.




                        
Comet web applications with Python,
              Django & Orbited




Latency, bandwidth, memory usage and scaling issues!


                    
Comet web applications with Python,
         Django & Orbited




      What about Comet?



              
Comet web applications with Python,
                Django & Orbited




Not a technology in itself
 Long Polling, IFRAME stream, HTMLFile, XHR Streaming, HTML5 SSE




                        
Comet web applications with Python,
         Django & Orbited




          It's an hack!
       Still waiting for an unanimous way to do it.




                   
Comet web applications with Python,
                      Django & Orbited


Long Polling
   Client: sends AJAX request.
   Server: holds the request.
              Data available: sends response.
              Timeout reached: empty response.
   Client: sends AJAX request again.




                            
Comet web applications with Python,
                        Django & Orbited

Http Push (HTTP Streaming*)
   Client: sends HTTP request.
   Server: doesn't terminate the connection.
   Server: sends data when available.
   Connection closed:
                Data is queued.
                Client reconnects.

    [*] http://ajaxpatterns.org/HTTP_Streaming



                               
Comet web applications with Python,
                    Django & Orbited
   HTTP Push: better for heavily-loaded apps.
       Not cross-browser.
   Long Polling: cross-browser and easy.
       Bandwidth usage.
       Too many connections.
   Async Python servers* are better for both:
       Twisted, Tornado, Dieselweb, Eventlet, Concurrence,
         Circuits, Gevent, Cogen.

[*] http://nichol.as/asynchronous-servers-in-python


                             
Comet web applications with Python,
         Django & Orbited




      What about Orbited?



              
Comet web applications with Python,
        Django & Orbited




        He's here to solve problems!

                
Comet web applications with Python,
                     Django & Orbited


   Based on Twisted.
   STOMP* (ActiveMQ, RabbitMQ), IRC and XMPP
     protocol support.
   Ready-to-use and cross-browser JavaScript client
     code.
   You don't have to reinvent the wheel!

[*] http://stomp.codehaus.org/



                             
Comet web applications with Python,
           Django & Orbited




Using Django and Orbited
        Example app developed for PyConIt4:
      http://pyconquiz.webright.it/




                   
Comet web applications with Python,
                  Django & Orbited

Django is used for:
   Application logic.
   Template rendering.
   User auth and registration.
   Handling AJAX requests.
   Sending messages to STOMP server.

                             ...Orbited and jQuery do the rest!




                          
Comet web applications with Python,
        Django & Orbited




              
Comet web applications with Python,
                    Django & Orbited

orbited.cfg                    settings.py
 [global]                       # Available using context
 #reactor=select                # processor or templatetag
 #reactor=kqueue
 reactor = epoll                ORBITED_HOST = 'localhost'
 proxy.enabled = 1              ORBITED_PORT = 8080
 session.ping_interval = 300
                                STOMP_HOST = 'localhost'
 [listen]                       STOMP_PORT = 61613
 http://localhost:8080
 stomp://localhost:61613

 [access]
 * -> localhost:61613



                            
Comet web applications with Python,
                  Django & Orbited

Django base template (<head /> tag)
 <script>document.domain = document.domain;</script>
 <script src="{{ ORBITED_MEDIA_URL }}Orbited.js"></script>
 <script type="text/javascript">
 Orbited.settings.port = {{ ORBITED_PORT }};
 Orbited.settings.hostname = "{{ ORBITED_HOST }}";
 Orbited.settings.streaming = true;

 TCPSocket = Orbited.TCPSocket;
 </script>

 <script src="{{ ORBITED_MEDIA_URL }}JSON.js"></script>
 <script
 src="{{ ORBITED_MEDIA_URL }}protocols/stomp/stomp.js"></script>



                          
Comet web applications with Python,
                     Django & Orbited
<script>
$(document).ready(function() {
    stomp = new STOMPClient();
    stomp.onopen = function() { debug('Connected.');};
    stomp.onclose = function(c) { debug(Lost Connection, Code: '+c);};
    stomp.onerror = function(error){ debug("Error: " + error);};
    stomp.onerrorframe = function(frame){ debug("Error: " + frame.body);};
    stomp.onconnectedframe = function() {
        {% if game %}
        stomp.subscribe('/games/{{ game.id }}/status');
        stomp.subscribe('/games/{{ game.id }}/players');
       {% else %}// subscribe to other channels...{% endif %}
    };
    stomp.onmessageframe = function(frame){
        // frame.headers.destination for channel, frame.body for JSON data
        destpatterns.dispatch(frame);
    };
    stomp.connect('{{ STOMP_HOST }}', {{ STOMP_PORT }});
});
</script>
                              
Comet web applications with Python,
                   Django & Orbited

Django view
 @require_POST
 @login_required
 def game_start(request, game_id):
   game = get_object_or_404(Game, id=game_id)
   if request.user != game.author:
      return HttpResponseForbidden()
   try:
       # start() method set game start_time and send JSON
       # to ”/games/{{ game.id }}/status” using stomp.py
      game.start()
   except GameError, e:
       return JSONResponse({'error': str(e)})
   return JSONResponse({})



                           
Comet web applications with Python,
        Django & Orbited




       Does it scale?



              
Comet web applications with Python,
        Django & Orbited




              
Comet web applications with Python,
        Django & Orbited




              
Comet web applications with Python,
         Django & Orbited




           Thank you
       and have fun with the quiz game!




                

Weitere ähnliche Inhalte

Was ist angesagt?

State of the art: Server-Side JavaScript - dejeuner fulljs
State of the art: Server-Side JavaScript - dejeuner fulljsState of the art: Server-Side JavaScript - dejeuner fulljs
State of the art: Server-Side JavaScript - dejeuner fulljsAlexandre Morgaut
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosBruno Oliveira
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the ServerDavid Ruiz
 
NeXTPLAN: Enterprise software that rocks!
NeXTPLAN: Enterprise software that rocks!NeXTPLAN: Enterprise software that rocks!
NeXTPLAN: Enterprise software that rocks!ESUG
 

Was ist angesagt? (6)

State of the art: Server-Side JavaScript - dejeuner fulljs
State of the art: Server-Side JavaScript - dejeuner fulljsState of the art: Server-Side JavaScript - dejeuner fulljs
State of the art: Server-Side JavaScript - dejeuner fulljs
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Server
 
NeXTPLAN: Enterprise software that rocks!
NeXTPLAN: Enterprise software that rocks!NeXTPLAN: Enterprise software that rocks!
NeXTPLAN: Enterprise software that rocks!
 

Andere mochten auch

SWDC 2010: Programming to Patterns
SWDC 2010: Programming to PatternsSWDC 2010: Programming to Patterns
SWDC 2010: Programming to Patternsdylanks
 
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann Chen
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann ChenICBA Webinar, 2015 Strategies. Ben Pankonin, Ann Chen
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann ChenBen Pankonin
 
London Ajax User Group Meetup: Comet Panel
London Ajax User Group Meetup: Comet PanelLondon Ajax User Group Meetup: Comet Panel
London Ajax User Group Meetup: Comet Paneldylanks
 
College House Computing: ITAs and Our Role
College House Computing: ITAs and Our RoleCollege House Computing: ITAs and Our Role
College House Computing: ITAs and Our RoleFrederick Ding
 
Communities: Build Or Join
Communities:  Build Or JoinCommunities:  Build Or Join
Communities: Build Or JoinRobyn Tippins
 
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"PyCon Italia
 

Andere mochten auch (6)

SWDC 2010: Programming to Patterns
SWDC 2010: Programming to PatternsSWDC 2010: Programming to Patterns
SWDC 2010: Programming to Patterns
 
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann Chen
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann ChenICBA Webinar, 2015 Strategies. Ben Pankonin, Ann Chen
ICBA Webinar, 2015 Strategies. Ben Pankonin, Ann Chen
 
London Ajax User Group Meetup: Comet Panel
London Ajax User Group Meetup: Comet PanelLondon Ajax User Group Meetup: Comet Panel
London Ajax User Group Meetup: Comet Panel
 
College House Computing: ITAs and Our Role
College House Computing: ITAs and Our RoleCollege House Computing: ITAs and Our Role
College House Computing: ITAs and Our Role
 
Communities: Build Or Join
Communities:  Build Or JoinCommunities:  Build Or Join
Communities: Build Or Join
 
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
 

Ähnlich wie Comet web applications with Python, Django & Orbited

Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & OrbitedComet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbitedskam
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Alex Kavanagh
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineAndy McKay
 
Connecting to Web Services on Android
Connecting to Web Services on AndroidConnecting to Web Services on Android
Connecting to Web Services on Androidsullis
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better NetworkingITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better NetworkingIstanbul Tech Talks
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with CometSimon Willison
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009sullis
 
Ring: Web Apps in Idiomatic Clojure
Ring: Web Apps in Idiomatic ClojureRing: Web Apps in Idiomatic Clojure
Ring: Web Apps in Idiomatic ClojureMark McGranaghan
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioRick Copeland
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008Joe Walker
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Frameworkjfarcand
 
Djabot – Python Jabber Bot
Djabot – Python Jabber BotDjabot – Python Jabber Bot
Djabot – Python Jabber Botmarekkuziel
 
asyncio community, one year later
asyncio community, one year laterasyncio community, one year later
asyncio community, one year laterVictor Stinner
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NETAlessandro Giorgetti
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scalajfarcand
 

Ähnlich wie Comet web applications with Python, Django & Orbited (20)

Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & OrbitedComet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Connecting to Web Services on Android
Connecting to Web Services on AndroidConnecting to Web Services on Android
Connecting to Web Services on Android
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better NetworkingITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with Comet
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009
 
Ring: Web Apps in Idiomatic Clojure
Ring: Web Apps in Idiomatic ClojureRing: Web Apps in Idiomatic Clojure
Ring: Web Apps in Idiomatic Clojure
 
huhu
huhuhuhu
huhu
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
 
Djabot – Python Jabber Bot
Djabot – Python Jabber BotDjabot – Python Jabber Bot
Djabot – Python Jabber Bot
 
asyncio community, one year later
asyncio community, one year laterasyncio community, one year later
asyncio community, one year later
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
 
Python, WebRTC and You (v2)
Python, WebRTC and You (v2)Python, WebRTC and You (v2)
Python, WebRTC and You (v2)
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 

Mehr von PyCon Italia

Feed back report 2010
Feed back report 2010Feed back report 2010
Feed back report 2010PyCon Italia
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolarePyCon Italia
 
Undici anni di lavoro con Python
Undici anni di lavoro con PythonUndici anni di lavoro con Python
Undici anni di lavoro con PythonPyCon Italia
 
socket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Pythonsocket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in PythonPyCon Italia
 
Qt mobile PySide bindings
Qt mobile PySide bindingsQt mobile PySide bindings
Qt mobile PySide bindingsPyCon Italia
 
Python: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPython: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPyCon Italia
 
Python in the browser
Python in the browserPython in the browser
Python in the browserPyCon Italia
 
PyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyCon Italia
 
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCon Italia
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonPyCon Italia
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest modulePyCon Italia
 
Monitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopMonitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopPyCon Italia
 
Jython for embedded software validation
Jython for embedded software validationJython for embedded software validation
Jython for embedded software validationPyCon Italia
 
Foxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoFoxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoPyCon Italia
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'EnterprisePyCon Italia
 
Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.PyCon Italia
 
Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1PyCon Italia
 

Mehr von PyCon Italia (19)

Feed back report 2010
Feed back report 2010Feed back report 2010
Feed back report 2010
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolare
 
Undici anni di lavoro con Python
Undici anni di lavoro con PythonUndici anni di lavoro con Python
Undici anni di lavoro con Python
 
socket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Pythonsocket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Python
 
Qt mobile PySide bindings
Qt mobile PySide bindingsQt mobile PySide bindings
Qt mobile PySide bindings
 
Python: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPython: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi genetici
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Python in the browser
Python in the browserPython in the browser
Python in the browser
 
PyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fast
 
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
Monitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopMonitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntop
 
Jython for embedded software validation
Jython for embedded software validationJython for embedded software validation
Jython for embedded software validation
 
Foxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoFoxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automatico
 
Effective EC2
Effective EC2Effective EC2
Effective EC2
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'Enterprise
 
Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.
 
Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Comet web applications with Python, Django & Orbited

  • 1. Comet web applications with Python, Django & Orbited @ PyCon Italia Qu4ttro Massimo Scamarcia http://www.pycon.it/ http://www.webright.it/    
  • 2. Comet web applications with Python, Django & Orbited How to push real-time data to web browsers?    
  • 3. Comet web applications with Python, Django & Orbited AJAX Polling  Client: sends AJAX request.  Server:  Data available: sends response.  No data: sends empty response.  Client: sends AJAX request again.    
  • 4. Comet web applications with Python, Django & Orbited Latency, bandwidth, memory usage and scaling issues!    
  • 5. Comet web applications with Python, Django & Orbited What about Comet?    
  • 6. Comet web applications with Python, Django & Orbited Not a technology in itself Long Polling, IFRAME stream, HTMLFile, XHR Streaming, HTML5 SSE    
  • 7. Comet web applications with Python, Django & Orbited It's an hack! Still waiting for an unanimous way to do it.    
  • 8. Comet web applications with Python, Django & Orbited Long Polling  Client: sends AJAX request.  Server: holds the request.  Data available: sends response.  Timeout reached: empty response.  Client: sends AJAX request again.    
  • 9. Comet web applications with Python, Django & Orbited Http Push (HTTP Streaming*)  Client: sends HTTP request.  Server: doesn't terminate the connection.  Server: sends data when available.  Connection closed:  Data is queued.  Client reconnects. [*] http://ajaxpatterns.org/HTTP_Streaming    
  • 10. Comet web applications with Python, Django & Orbited  HTTP Push: better for heavily-loaded apps.  Not cross-browser.  Long Polling: cross-browser and easy.  Bandwidth usage.  Too many connections.  Async Python servers* are better for both:  Twisted, Tornado, Dieselweb, Eventlet, Concurrence, Circuits, Gevent, Cogen. [*] http://nichol.as/asynchronous-servers-in-python    
  • 11. Comet web applications with Python, Django & Orbited What about Orbited?    
  • 12. Comet web applications with Python, Django & Orbited He's here to solve problems!    
  • 13. Comet web applications with Python, Django & Orbited  Based on Twisted.  STOMP* (ActiveMQ, RabbitMQ), IRC and XMPP protocol support.  Ready-to-use and cross-browser JavaScript client code.  You don't have to reinvent the wheel! [*] http://stomp.codehaus.org/    
  • 14. Comet web applications with Python, Django & Orbited Using Django and Orbited Example app developed for PyConIt4: http://pyconquiz.webright.it/    
  • 15. Comet web applications with Python, Django & Orbited Django is used for:  Application logic.  Template rendering.  User auth and registration.  Handling AJAX requests.  Sending messages to STOMP server. ...Orbited and jQuery do the rest!    
  • 16. Comet web applications with Python, Django & Orbited    
  • 17. Comet web applications with Python, Django & Orbited orbited.cfg settings.py [global] # Available using context #reactor=select # processor or templatetag #reactor=kqueue reactor = epoll ORBITED_HOST = 'localhost' proxy.enabled = 1 ORBITED_PORT = 8080 session.ping_interval = 300 STOMP_HOST = 'localhost' [listen] STOMP_PORT = 61613 http://localhost:8080 stomp://localhost:61613 [access] * -> localhost:61613    
  • 18. Comet web applications with Python, Django & Orbited Django base template (<head /> tag) <script>document.domain = document.domain;</script> <script src="{{ ORBITED_MEDIA_URL }}Orbited.js"></script> <script type="text/javascript"> Orbited.settings.port = {{ ORBITED_PORT }}; Orbited.settings.hostname = "{{ ORBITED_HOST }}"; Orbited.settings.streaming = true; TCPSocket = Orbited.TCPSocket; </script> <script src="{{ ORBITED_MEDIA_URL }}JSON.js"></script> <script src="{{ ORBITED_MEDIA_URL }}protocols/stomp/stomp.js"></script>    
  • 19. Comet web applications with Python, Django & Orbited <script> $(document).ready(function() { stomp = new STOMPClient(); stomp.onopen = function() { debug('Connected.');}; stomp.onclose = function(c) { debug(Lost Connection, Code: '+c);}; stomp.onerror = function(error){ debug("Error: " + error);}; stomp.onerrorframe = function(frame){ debug("Error: " + frame.body);}; stomp.onconnectedframe = function() { {% if game %} stomp.subscribe('/games/{{ game.id }}/status'); stomp.subscribe('/games/{{ game.id }}/players'); {% else %}// subscribe to other channels...{% endif %} }; stomp.onmessageframe = function(frame){ // frame.headers.destination for channel, frame.body for JSON data destpatterns.dispatch(frame); }; stomp.connect('{{ STOMP_HOST }}', {{ STOMP_PORT }}); }); </script>    
  • 20. Comet web applications with Python, Django & Orbited Django view @require_POST @login_required def game_start(request, game_id): game = get_object_or_404(Game, id=game_id) if request.user != game.author: return HttpResponseForbidden() try: # start() method set game start_time and send JSON # to ”/games/{{ game.id }}/status” using stomp.py game.start() except GameError, e: return JSONResponse({'error': str(e)}) return JSONResponse({})    
  • 21. Comet web applications with Python, Django & Orbited Does it scale?    
  • 22. Comet web applications with Python, Django & Orbited    
  • 23. Comet web applications with Python, Django & Orbited    
  • 24. Comet web applications with Python, Django & Orbited Thank you and have fun with the quiz game!