SlideShare a Scribd company logo
Comet implementations for Perl




                                    Marian HackMan Marinov
                               Co-founder and CEO of 1H Ltd.
                                               mm@1h.com
Bulgarian Perl Workshop 2013
Replacing browser PULL
                               with server PUSH

       What is Comet?



                               AJAX Push
                               Reverse AJAX
                               Two-way-web
                               HTTP Streaming
                               HTTP Server Push
Bulgarian Perl Workshop 2013
Hidden iframe
                               XMLHttpRequest
                               long polling with
                                  - AJAX
                                  - XMLHttpRequest
                                  - Script tag




      Implementations



Bulgarian Perl Workshop 2013
Bulgarian Perl Workshop 2013
Iframe sent as                          Hidden iframe
  chunked blcok

  Infinitely long




                               Works on every browser

                               Lacks reliable error handling
                               Connection state unavailable

Bulgarian Perl Workshop 2013
hackman@gamelon:~$ curl http://localhost:4670/push/12345/iframe/channel1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT">
</head>
<body>
<script>document.getElementById('counter').innerHTML = '1';</script>
<script>document.getElementById('counter').innerHTML = '2';</script>
<script>document.getElementById('counter').innerHTML = '3';</script>
<script>document.getElementById('counter').innerHTML = '4';</script>
<script>document.getElementById('counter').innerHTML = '5';</script>
<script>document.getElementById('counter').innerHTML = '6';</script>

<html>
<head>
<title>Comet test Page</title>
</head>
<body>
<h2 align="center">My counter: </h2> <span id='counter'></span>
<iframe href='http://localhost:8000' height=0 width=0></iframe>
</body>
</html>

Bulgarian Perl Workshop 2013
XMLHttpRequest
Content-type:
 multipart/x-mixed-replace;
 boundary=NEXTPARTrnrn




                               The Ajax way of using Comet
                               Reliable connection handling
                               Connection state information



Bulgarian Perl Workshop 2013
hackman@gamelon:~$ curl http://localhost:8000/

--NEXTPART
Content-type: text/plain

<script>document.getElementById('counter').innerHTML = '0';</script>
--NEXTPART
Content-type: text/plain

<script>document.getElementById('counter').innerHTML = '1';</script>
--NEXTPART
Content-type: text/plain

<script>document.getElementById('counter').innerHTML = '2';</script>
--NEXTPART




Bulgarian Perl Workshop 2013
Long Polling




XMLHttpRequest
- creates a request
- when all data is received
- creates subsequent request


Bulgarian Perl Workshop 2013
Long Polling




<script> tag
- creates a script tag
- when all data is received
- creates new script tag


Bulgarian Perl Workshop 2013
Meteor
                               Stardust

                               Frameworks:
                                - Mojolicious
                                - PSGI
                                - Continuity




What Comet implementations
we have in Perl


Bulgarian Perl Workshop 2013
http://meteorserver.org/



 Meteor



                               Stand alone web server
                               Supports:
                                - iframe
                                - xhrinteractive
                               - simplepoll & smartpoll
                               - longpoll
                               - flash & flashloadvars

Bulgarian Perl Workshop 2013
Event controller commands




                               ADDMESSAGE chan msg
                               COUNTSUBSCRIBERS chan
                               LISTCHANNELS
                               SHOWSTATS
                               QUIT
Bulgarian Perl Workshop 2013
hackman@gamelon:~/Comet$ nc localhost 4671
  SHOWSTATS
  OK
  uptime: 279
  channel_count: 0
  subscriber_connections_accepted: 3
  controller_connections_accepted: 1
  total_inbound_bytes: 524
  total_outbound_bytes: 646
  documents_not_found: 3
  current_controllers: 1
  total_requests: 4
  current_subscribers: 0
  --EOT--
  ADDMESSAGE channel1 testing
  OK     0
  LISTCHANNELS
  OK
  channel1(1/0)
  --EOT--
  ADDMESSAGE channel1 dddddd
  OK     1
Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/iframe/channel1
  <html><head>
  <script type="text/javascript">
  window.onError = null;
  var domainparts = document.domain.split(".");
  document.domain = domainparts[domainparts.length-2]+".
   "+domainparts[domainparts.length-1];
  parent.Meteor.register(this);
  </script>
  </head>
  <body onload="try { parent.Meteor.reset(this) } catch (e) {}">
  <script>ch("channel1", 1);</script>

  <script>p(-1,"");</script>
  <script>p(-1,"");</script>
  <script>p(2,"channel1","fufufu");</script>
  <script>p(-1,"");</script>
  ^C
  hackman@gamelon:~$

Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/xhrinteractive/channel1
.............................................................................................................
.............................................................................................................
.............................................................................................................
.............................................................................................................
.............................................................................................................
.........................................
<script>ch("channel1", 2);</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(3,"channel1","s1dasda");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
^C

hackman@gamelon:~$

 Bulgarian Perl Workshop 2013
$ curl http://localhost:4670/push/12345/simplepoll/channel1
<script>ch("channel1", 3);</script>
hackman@gamelon:~$

$ curl http://localhost:4670/push/12345/smartpoll/channel1
<script>ch("channel1", 3);</script>
hackman@gamelon:~$

$ curl http://localhost:4670/push/12345/longpoll/channel1
<script>ch("channel1", 3);</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>
<script>p(4,"channel1","gtwedsada");</script>
hackman@gamelon:~$



Bulgarian Perl Workshop 2013
Stand alone web server
Almost no documentation                  Stardust
No updates since 2011
Supports:
stream and longpoll




remove With::Log from stardust.pl   cpan Stardust

Bulgarian Perl Workshop 2013
$ curl -d 'm={ "type": "Test", "data": [1,2,3] }' http://localhost:5742/channel/foo/stream/foo/
/channel/foo/stream/foo/ not found.[root@gamelon script]#
hackman@gamelon:~$
$ curl -d 'm={ "type": "Test", "data": [1,2,3] }' http://localhost:5742/channel/foo
$ curl http://localhost:5742/channel/foo
[{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"}],
  "name":"foo","subscribers":[],"size":8,"i":1}]
hackman@gamelon:~$

$ curl -d 'm={ "type": "Test", "data": [2,3] }' http://localhost:5742/channel/foo
$ curl http://localhost:5742/channel/foo
[{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"},
  {"_ts":1360399605.81986,"data":[2,3],"type":"Test","_ch":"foo"}],
  "name":"foo","subscribers":[],"size":8,"i":2}]


Bulgarian Perl Workshop 2013
Other Perl comet implementations:
 - POE-Component-Server-Bayeux
 - Tatsumaki




 Additional readings:
   http://toroid.org/ams/etc/mojolicious-http-streaming
   http://infrequently.org/2006/03/comet-low-latency-data-for-the-browser/
  http://showmetheco.de/articles/2011/2/diving-into-html5-with-websockets-and-perl.html


Bulgarian Perl Workshop 2013
More on the subject here:
          http://www.slideshare.net/simon/time-for-comet


         ?                     ?
                                       ?                  ?
               ?
                               ?       ?
  ?       My slides can be found here:                ?
           http://www.slideshare.net/azilian/perl-comet
Bulgarian Perl Workshop 2013

More Related Content

PDF
44CON London 2015 - Going AUTH the Rails on a Crazy Train
PDF
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
PDF
Service Oriented Integration With ServiceMix
PPTX
0-60 with Goliath: Building High Performance Ruby Web-Services
PDF
Making the Most of HTTP In Your Apps
PDF
HipHop VM: overclocking Symfony
PPTX
Real-Time Web applications with WebSockets
PDF
Camel and JBoss
44CON London 2015 - Going AUTH the Rails on a Crazy Train
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
Service Oriented Integration With ServiceMix
0-60 with Goliath: Building High Performance Ruby Web-Services
Making the Most of HTTP In Your Apps
HipHop VM: overclocking Symfony
Real-Time Web applications with WebSockets
Camel and JBoss

What's hot (20)

KEY
Genkidama:実装と課題
PPT
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
PPTX
Smart Gamma - Real-Time Web applications with PHP and Websocket.
PPTX
0-60 with Goliath: High performance web services
ODP
Inter-Process/Task Communication With Message Queues
PDF
"Swoole: double troubles in c", Alexandr Vronskiy
PPT
Find bottleneck and tuning in Java Application
PDF
Crash course to the Apache Camel
PDF
PPTX
Ruby C10K: High Performance Networking - RubyKaigi '09
ODP
Performance Optimization of Rails Applications
PPTX
Ruby Proxies for Scale, Performance, and Monitoring
PDF
Rails Application Optimization Techniques & Tools
PDF
Faster & Greater Messaging System HornetQ zzz
PDF
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
PPTX
Service workers - Velocity 2016 Training
KEY
The HTML5 WebSocket API
PDF
I know why your Java is slow
PDF
Mobile web performance - MoDev East
PDF
HAProxy tech talk
Genkidama:実装と課題
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Smart Gamma - Real-Time Web applications with PHP and Websocket.
0-60 with Goliath: High performance web services
Inter-Process/Task Communication With Message Queues
"Swoole: double troubles in c", Alexandr Vronskiy
Find bottleneck and tuning in Java Application
Crash course to the Apache Camel
Ruby C10K: High Performance Networking - RubyKaigi '09
Performance Optimization of Rails Applications
Ruby Proxies for Scale, Performance, and Monitoring
Rails Application Optimization Techniques & Tools
Faster & Greater Messaging System HornetQ zzz
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
Service workers - Velocity 2016 Training
The HTML5 WebSocket API
I know why your Java is slow
Mobile web performance - MoDev East
HAProxy tech talk
Ad

Similar to Perl comet (20)

PDF
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
PDF
Camel overview
PDF
Easy Integration with Apache Camel and Fuse IDE
PPTX
Nodejs Performance Debug
PPTX
Practical Operation Automation with StackStorm
ODP
Hand-on Resources II: Extending SCMSWeb
PPT
AppengineJS
PDF
Gpars - the coolest bits
PPTX
Expand Your Testing with Virtual Services
ODP
Perl Usage In Security and Penetration testing
PPT
Rapid java backend and api development for mobile devices
PDF
Foomo / Zugspitze Presentation
PDF
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
PPT
Positive Hack Days. Goltsev. Web Vulnerabilities: Difficult Cases
PDF
Http Parameter Pollution, a new category of web attacks
PDF
mri ruby gil
KEY
Deploying JRuby Web Applications
PDF
LogStash - Yes, logging can be awesome
PDF
Serverless orchestration and automation with Cloud Workflows
PDF
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Camel overview
Easy Integration with Apache Camel and Fuse IDE
Nodejs Performance Debug
Practical Operation Automation with StackStorm
Hand-on Resources II: Extending SCMSWeb
AppengineJS
Gpars - the coolest bits
Expand Your Testing with Virtual Services
Perl Usage In Security and Penetration testing
Rapid java backend and api development for mobile devices
Foomo / Zugspitze Presentation
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Positive Hack Days. Goltsev. Web Vulnerabilities: Difficult Cases
Http Parameter Pollution, a new category of web attacks
mri ruby gil
Deploying JRuby Web Applications
LogStash - Yes, logging can be awesome
Serverless orchestration and automation with Cloud Workflows
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
Ad

More from Marian Marinov (20)

PDF
How to start and then move forward in IT
PDF
Thinking about highly-available systems and their setup
PDF
Understanding your memory usage under Linux
PDF
How to implement PassKeys in your application
PDF
Dev.bg DevOps March 2024 Monitoring & Logging
PDF
Basic presentation of cryptography mechanisms
PDF
Microservices: Benefits, drawbacks and are they for me?
PDF
Introduction and replication to DragonflyDB
PDF
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
PDF
How to successfully migrate to DevOps .pdf
PDF
How to survive in the work from home era
PDF
Managing sysadmins
PDF
Improve your storage with bcachefs
PDF
Control your service resources with systemd
PDF
Comparison of-foss-distributed-storage
PDF
Защо и как да обогатяваме знанията си?
PDF
Securing your MySQL server
PDF
Sysadmin vs. dev ops
PDF
DoS and DDoS mitigations with eBPF, XDP and DPDK
PDF
Challenges with high density networks
How to start and then move forward in IT
Thinking about highly-available systems and their setup
Understanding your memory usage under Linux
How to implement PassKeys in your application
Dev.bg DevOps March 2024 Monitoring & Logging
Basic presentation of cryptography mechanisms
Microservices: Benefits, drawbacks and are they for me?
Introduction and replication to DragonflyDB
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
How to successfully migrate to DevOps .pdf
How to survive in the work from home era
Managing sysadmins
Improve your storage with bcachefs
Control your service resources with systemd
Comparison of-foss-distributed-storage
Защо и как да обогатяваме знанията си?
Securing your MySQL server
Sysadmin vs. dev ops
DoS and DDoS mitigations with eBPF, XDP and DPDK
Challenges with high density networks

Perl comet

  • 1. Comet implementations for Perl Marian HackMan Marinov Co-founder and CEO of 1H Ltd. mm@1h.com Bulgarian Perl Workshop 2013
  • 2. Replacing browser PULL with server PUSH What is Comet? AJAX Push Reverse AJAX Two-way-web HTTP Streaming HTTP Server Push Bulgarian Perl Workshop 2013
  • 3. Hidden iframe XMLHttpRequest long polling with - AJAX - XMLHttpRequest - Script tag Implementations Bulgarian Perl Workshop 2013
  • 5. Iframe sent as Hidden iframe chunked blcok Infinitely long Works on every browser Lacks reliable error handling Connection state unavailable Bulgarian Perl Workshop 2013
  • 6. hackman@gamelon:~$ curl http://localhost:4670/push/12345/iframe/channel1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" <meta http-equiv="Cache-Control" content="no-store"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT"> </head> <body> <script>document.getElementById('counter').innerHTML = '1';</script> <script>document.getElementById('counter').innerHTML = '2';</script> <script>document.getElementById('counter').innerHTML = '3';</script> <script>document.getElementById('counter').innerHTML = '4';</script> <script>document.getElementById('counter').innerHTML = '5';</script> <script>document.getElementById('counter').innerHTML = '6';</script> <html> <head> <title>Comet test Page</title> </head> <body> <h2 align="center">My counter: </h2> <span id='counter'></span> <iframe href='http://localhost:8000' height=0 width=0></iframe> </body> </html> Bulgarian Perl Workshop 2013
  • 7. XMLHttpRequest Content-type: multipart/x-mixed-replace; boundary=NEXTPARTrnrn The Ajax way of using Comet Reliable connection handling Connection state information Bulgarian Perl Workshop 2013
  • 8. hackman@gamelon:~$ curl http://localhost:8000/ --NEXTPART Content-type: text/plain <script>document.getElementById('counter').innerHTML = '0';</script> --NEXTPART Content-type: text/plain <script>document.getElementById('counter').innerHTML = '1';</script> --NEXTPART Content-type: text/plain <script>document.getElementById('counter').innerHTML = '2';</script> --NEXTPART Bulgarian Perl Workshop 2013
  • 9. Long Polling XMLHttpRequest - creates a request - when all data is received - creates subsequent request Bulgarian Perl Workshop 2013
  • 10. Long Polling <script> tag - creates a script tag - when all data is received - creates new script tag Bulgarian Perl Workshop 2013
  • 11. Meteor Stardust Frameworks: - Mojolicious - PSGI - Continuity What Comet implementations we have in Perl Bulgarian Perl Workshop 2013
  • 12. http://meteorserver.org/ Meteor Stand alone web server Supports: - iframe - xhrinteractive - simplepoll & smartpoll - longpoll - flash & flashloadvars Bulgarian Perl Workshop 2013
  • 13. Event controller commands ADDMESSAGE chan msg COUNTSUBSCRIBERS chan LISTCHANNELS SHOWSTATS QUIT Bulgarian Perl Workshop 2013
  • 14. hackman@gamelon:~/Comet$ nc localhost 4671 SHOWSTATS OK uptime: 279 channel_count: 0 subscriber_connections_accepted: 3 controller_connections_accepted: 1 total_inbound_bytes: 524 total_outbound_bytes: 646 documents_not_found: 3 current_controllers: 1 total_requests: 4 current_subscribers: 0 --EOT-- ADDMESSAGE channel1 testing OK 0 LISTCHANNELS OK channel1(1/0) --EOT-- ADDMESSAGE channel1 dddddd OK 1 Bulgarian Perl Workshop 2013
  • 15. $ curl http://localhost:4670/push/12345/iframe/channel1 <html><head> <script type="text/javascript"> window.onError = null; var domainparts = document.domain.split("."); document.domain = domainparts[domainparts.length-2]+". "+domainparts[domainparts.length-1]; parent.Meteor.register(this); </script> </head> <body onload="try { parent.Meteor.reset(this) } catch (e) {}"> <script>ch("channel1", 1);</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(2,"channel1","fufufu");</script> <script>p(-1,"");</script> ^C hackman@gamelon:~$ Bulgarian Perl Workshop 2013
  • 16. $ curl http://localhost:4670/push/12345/xhrinteractive/channel1 ............................................................................................................. ............................................................................................................. ............................................................................................................. ............................................................................................................. ............................................................................................................. ......................................... <script>ch("channel1", 2);</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(3,"channel1","s1dasda");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> ^C hackman@gamelon:~$ Bulgarian Perl Workshop 2013
  • 17. $ curl http://localhost:4670/push/12345/simplepoll/channel1 <script>ch("channel1", 3);</script> hackman@gamelon:~$ $ curl http://localhost:4670/push/12345/smartpoll/channel1 <script>ch("channel1", 3);</script> hackman@gamelon:~$ $ curl http://localhost:4670/push/12345/longpoll/channel1 <script>ch("channel1", 3);</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(-1,"");</script> <script>p(4,"channel1","gtwedsada");</script> hackman@gamelon:~$ Bulgarian Perl Workshop 2013
  • 18. Stand alone web server Almost no documentation Stardust No updates since 2011 Supports: stream and longpoll remove With::Log from stardust.pl cpan Stardust Bulgarian Perl Workshop 2013
  • 19. $ curl -d 'm={ "type": "Test", "data": [1,2,3] }' http://localhost:5742/channel/foo/stream/foo/ /channel/foo/stream/foo/ not found.[root@gamelon script]# hackman@gamelon:~$ $ curl -d 'm={ "type": "Test", "data": [1,2,3] }' http://localhost:5742/channel/foo $ curl http://localhost:5742/channel/foo [{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"}], "name":"foo","subscribers":[],"size":8,"i":1}] hackman@gamelon:~$ $ curl -d 'm={ "type": "Test", "data": [2,3] }' http://localhost:5742/channel/foo $ curl http://localhost:5742/channel/foo [{"messages":[{"_ts":1360399562.89221,"data":[1,2,3],"type":"Test","_ch":"foo"}, {"_ts":1360399605.81986,"data":[2,3],"type":"Test","_ch":"foo"}], "name":"foo","subscribers":[],"size":8,"i":2}] Bulgarian Perl Workshop 2013
  • 20. Other Perl comet implementations: - POE-Component-Server-Bayeux - Tatsumaki Additional readings: http://toroid.org/ams/etc/mojolicious-http-streaming http://infrequently.org/2006/03/comet-low-latency-data-for-the-browser/ http://showmetheco.de/articles/2011/2/diving-into-html5-with-websockets-and-perl.html Bulgarian Perl Workshop 2013
  • 21. More on the subject here: http://www.slideshare.net/simon/time-for-comet ? ? ? ? ? ? ? ? My slides can be found here: ? http://www.slideshare.net/azilian/perl-comet Bulgarian Perl Workshop 2013

Editor's Notes

  • #3: A lot of names for the same technology :)
  • #5: Streaming Short polling Long polling
  • #6: Does not support cross domain access Before IE needs minimum 256bytes of data before executing anything The same issue is present in Safari
  • #8: x-mixed-replace is invented by Netscape 1995 since 2004 has support in Gecko browsers it is also included in IE 10 and newer Does not support cross domain access
  • #10: Does not support cross domain access Works on all browsers
  • #11: Supports cross domain access Works on all browsers
  • #12: You can do it with CGI.pm but it is not advisable
  • #13: You can do it with CGI.pm but it is not advisable
  • #14: You can do it with CGI.pm but it is not advisable
  • #15: You can do it with CGI.pm but it is not advisable
  • #16: You can do it with CGI.pm but it is not advisable
  • #17: You can do it with CGI.pm but it is not advisable
  • #18: You can do it with CGI.pm but it is not advisable
  • #19: You can do it with CGI.pm but it is not advisable
  • #20: You can do it with CGI.pm but it is not advisable
  • #21: You can do it with CGI.pm but it is not advisable
  • #22: You can do it with CGI.pm but it is not advisable