SlideShare a Scribd company logo
1 of 24
Download to read offline
REAL TIME EVENT DASHBOARDS
— MUJTABA HUSSAIN —
Who am I?
Infrastructure engineer and developer @ Fillr

Reluctant javascript code maintainer. 

Blatant code copier.
Whats happening now?
Dashboard?

Real time? Is there an un-real time one? Can I get
that one?

What?
At the end …
Its not that hard! Its much harder muhahahahah

Know where to start looking!

For multiple users!
Why did I do this?
Investors. 

Looks cool.

I learnt new stuff.
How I started?
Google “How do I build a google map?”

Google “How do I get norse map source code?”

Google “Please help!”
Screw it, I will build it
myself.
Highmaps

AWS JS SDK

Amazingly horrible JavaScript.
Done, but … meh
Looked OK. 

Updates were basically bubbles. 

My Javascript.
Enter DataMaps
Built on d3js

Solely for maps.

Bit more functionality compared to HighMaps.
Start Simple.
Data on the map.
Data from queue to map.
Did it work?
init: function(){
setTimeout(
jQuery.proxy(this.getData, this),
this.interval
);
}
var sqs = new AWS.SQS({
apiVersion: '2012-11-05',
accessKeyId: 'GREEDOSHOTFIRST',
secretAccessKey: 'TWILIGHTISCOOL',
region: 'ap-southeast-2'
});
Authentication?
I do not want to make this complicated.

Simplest procedure.

AWS::Cognito
Multi-users
Polling the queue within the client would have
issues.

Needed to set it up for a lot of clients.
WebSockets
em-websocket (ruby) as server

WebSocket (JavaScript) for client
EM.run {
EM::WebSocket.run(:host => WS_HOST, :port => WS_PORT) do |ws|
ws.onopen { |handshake|
queue.poll do |msg|
logger.debug 'Websocket connection open'
ws.send MESSAGE_FROM_QUEUE
end
}
ws.onclose { |msg| logger.info "Connection closed" }
ws.onerror { |msg| logger.error "Something went wrong" }
}
end
}
end
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "STATEMENT_ID",
"Effect": "Allow",
"Action": [
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
"sqs:ListDeadLetterSourceQueues",
"sqs:ListQueues",
"sqs:ReceiveMessage"
],
"Resource": [
"QUEUE_ARN"
]
}
]
}
Timeout
Client and server kept timing out.

Messages kept getting lost.

I kept losing hair.
@channel = EM::Channel.new
threads << Thread.new do
queue.poll do |msg|
logger.debug "Message received #{msg.body}"
@channel.push msg.body
end
end
threads << Thread.new do
EM.run {
EM::WebSocket.run(:host => WS_HOST, :port => WS_PORT) do |ws|
EventMachine.add_periodic_timer(3) { ws.send HEARTBEAT }
ws.onopen { |handshake|
sid = @channel.subscribe {|msg| ws.send msg }
logger.debug 'Websocket connection open'
ws.onmessage {|msg| ws.send “—heartbeat—" }
ws.onclose { |msg| }
ws.onerror { |msg| }
}
end
}
end
ws = new WebSocket("SERVER");
var heartbeat_msg = '--heartbeat--';
ws.onopen = function(evt) {
if (heartbeat_interval == null) {
missed_heartbeats = 0;
heartbeat_interval = setInterval(function() {
SEND_HEARTBEAT }, X_TIME_UNITS
);
}
};
ws.onclose = function(evt) { console.log("CLOSE" + evt); };
ws.onerror = function(evt) { console.log("ERROR" + evt); };
ws.onmessage = function(evt) {
if (evt.data === heartbeat_msg) {
ACK_HEARTBEAT_AND_RESET;
}
PROCESS_DATA;
};
But wait, there is more.
Deployment intended to AWS.

Where to set up the WebSocket server? 

Surely binding to 0.0.0.0
Cue NGinX awesomeness
server {
listen HTTP_PORT;
server_name MAP_ENDPOINT;
location /socketcluster {
proxy_pass http://0.0.0.0:WS_PORT;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
rewrite ^/(.*) /$1 break;
proxy_ignore_client_abort on;
proxy_pass http://localhost:LOCAL_HTTP_PORT;
proxy_redirect http://localhost:LOCAL_HTTP_PORT MAP_ENDPOINT;
proxy_set_header HEADERS;
}
}
Real time event dashboards

More Related Content

What's hot

Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
 

What's hot (20)

Service worker API
Service worker APIService worker API
Service worker API
 
Service worker - Offline Web
Service worker - Offline WebService worker - Offline Web
Service worker - Offline Web
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it all
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
MinbilDinbil Django Speed Tricks
MinbilDinbil Django Speed TricksMinbilDinbil Django Speed Tricks
MinbilDinbil Django Speed Tricks
 
Forensic Tools for In-Depth Performance Investigations
Forensic Tools for In-Depth Performance InvestigationsForensic Tools for In-Depth Performance Investigations
Forensic Tools for In-Depth Performance Investigations
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
 
Service workers
Service workersService workers
Service workers
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moible
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and React
 
Service workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsService workers and the role they play in modern day web apps
Service workers and the role they play in modern day web apps
 
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-appsJSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
 
Building Faster Websites
Building Faster WebsitesBuilding Faster Websites
Building Faster Websites
 
Kubernetes Native Java
Kubernetes Native JavaKubernetes Native Java
Kubernetes Native Java
 
Drupal point of vue
Drupal point of vueDrupal point of vue
Drupal point of vue
 
Real World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker CachingReal World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker Caching
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 

Similar to Real time event dashboards

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
tkramar
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 

Similar to Real time event dashboards (20)

AngularJS and SPA
AngularJS and SPAAngularJS and SPA
AngularJS and SPA
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node azure
Node azureNode azure
Node azure
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Coolblue - Behind the Scenes Continuous Integration & Deployment
Coolblue - Behind the Scenes Continuous Integration & DeploymentCoolblue - Behind the Scenes Continuous Integration & Deployment
Coolblue - Behind the Scenes Continuous Integration & Deployment
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
Introducing to node.js
Introducing to node.jsIntroducing to node.js
Introducing to node.js
 
Modern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaumModern server side development with node.js - Benjamin gruenbaum
Modern server side development with node.js - Benjamin gruenbaum
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Sufan presentation
Sufan presentationSufan presentation
Sufan presentation
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Recently uploaded (20)

Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 

Real time event dashboards

  • 1. REAL TIME EVENT DASHBOARDS — MUJTABA HUSSAIN —
  • 2. Who am I? Infrastructure engineer and developer @ Fillr Reluctant javascript code maintainer. Blatant code copier.
  • 3. Whats happening now? Dashboard? Real time? Is there an un-real time one? Can I get that one? What?
  • 4. At the end … Its not that hard! Its much harder muhahahahah Know where to start looking! For multiple users!
  • 5. Why did I do this? Investors. Looks cool. I learnt new stuff.
  • 6. How I started? Google “How do I build a google map?” Google “How do I get norse map source code?” Google “Please help!”
  • 7. Screw it, I will build it myself. Highmaps AWS JS SDK Amazingly horrible JavaScript.
  • 8. Done, but … meh Looked OK. Updates were basically bubbles. My Javascript.
  • 9. Enter DataMaps Built on d3js Solely for maps. Bit more functionality compared to HighMaps.
  • 11. Data on the map.
  • 12. Data from queue to map.
  • 14. init: function(){ setTimeout( jQuery.proxy(this.getData, this), this.interval ); } var sqs = new AWS.SQS({ apiVersion: '2012-11-05', accessKeyId: 'GREEDOSHOTFIRST', secretAccessKey: 'TWILIGHTISCOOL', region: 'ap-southeast-2' });
  • 15. Authentication? I do not want to make this complicated. Simplest procedure. AWS::Cognito
  • 16. Multi-users Polling the queue within the client would have issues. Needed to set it up for a lot of clients.
  • 17. WebSockets em-websocket (ruby) as server WebSocket (JavaScript) for client
  • 18. EM.run { EM::WebSocket.run(:host => WS_HOST, :port => WS_PORT) do |ws| ws.onopen { |handshake| queue.poll do |msg| logger.debug 'Websocket connection open' ws.send MESSAGE_FROM_QUEUE end } ws.onclose { |msg| logger.info "Connection closed" } ws.onerror { |msg| logger.error "Something went wrong" } } end } end
  • 19. { "Version": "2012-10-17", "Statement": [ { "Sid": "STATEMENT_ID", "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:GetQueueAttributes", "sqs:GetQueueUrl", "sqs:ListDeadLetterSourceQueues", "sqs:ListQueues", "sqs:ReceiveMessage" ], "Resource": [ "QUEUE_ARN" ] } ] }
  • 20. Timeout Client and server kept timing out. Messages kept getting lost. I kept losing hair.
  • 21. @channel = EM::Channel.new threads << Thread.new do queue.poll do |msg| logger.debug "Message received #{msg.body}" @channel.push msg.body end end threads << Thread.new do EM.run { EM::WebSocket.run(:host => WS_HOST, :port => WS_PORT) do |ws| EventMachine.add_periodic_timer(3) { ws.send HEARTBEAT } ws.onopen { |handshake| sid = @channel.subscribe {|msg| ws.send msg } logger.debug 'Websocket connection open' ws.onmessage {|msg| ws.send “—heartbeat—" } ws.onclose { |msg| } ws.onerror { |msg| } } end } end ws = new WebSocket("SERVER"); var heartbeat_msg = '--heartbeat--'; ws.onopen = function(evt) { if (heartbeat_interval == null) { missed_heartbeats = 0; heartbeat_interval = setInterval(function() { SEND_HEARTBEAT }, X_TIME_UNITS ); } }; ws.onclose = function(evt) { console.log("CLOSE" + evt); }; ws.onerror = function(evt) { console.log("ERROR" + evt); }; ws.onmessage = function(evt) { if (evt.data === heartbeat_msg) { ACK_HEARTBEAT_AND_RESET; } PROCESS_DATA; };
  • 22. But wait, there is more. Deployment intended to AWS. Where to set up the WebSocket server? Surely binding to 0.0.0.0
  • 23. Cue NGinX awesomeness server { listen HTTP_PORT; server_name MAP_ENDPOINT; location /socketcluster { proxy_pass http://0.0.0.0:WS_PORT; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { rewrite ^/(.*) /$1 break; proxy_ignore_client_abort on; proxy_pass http://localhost:LOCAL_HTTP_PORT; proxy_redirect http://localhost:LOCAL_HTTP_PORT MAP_ENDPOINT; proxy_set_header HEADERS; } }