SlideShare a Scribd company logo
1 of 33
Download to read offline
REAL-TIME SPORTS STATISTICS
WITH NODE.JS, WEBSOCKETS AND SYMFONY2
#42 TOBIAS JOSEFSSON
Chief Technology Officer
”Bobbe” / ”Bobby”
@TobiasJosefsson
#8 EMANUEL WINBLAD
Soware Engineer
”Manne” / ”Manny”
@ManneW
SPORTS EDITING SWEDEN
A MEDIA HOUSE FOCUSED ON SPORTS
Overview: Data flow from Operators to Clients
Overview: Data flow from Operators to Clients
Why this complex setup?
”Independent” decoupled parts
- Easier to test
- Easier to maintain / replace
- Each part only does one thing
Multiple languages
- There is no silver bullet
Messaging: ZeroMQ
"ZeroMQ is a messaging library, which allows you
to design a complex communication system
without much effort."
– Nicholas Piël
”Messaging makes everything possible!”
– Alvaro Videla, JSDay 2013 (yesterday)
Messaging: ZeroMQ
RabbitMQ ZeroMQ
Broker Brokerless
Messaging
System
Messaging
Library
Why:
- Lightweight
- Minimalistic
- Small feature set needed
Messaging: ZeroMQ
Core pattern used:
Overview: Statistics input
Statistics input: External system
Seven Operators per arena, logging events.
- Shots on net, shots wide, shots blocked
- Goals and assists
- Players currently on the ice, shifts
- Penalties
- Hits
- ...and much more...
Data is transferred using XML files and http(s).
Overview: Parser
Parser: PHP, mongoDB
PHP: Familiar, XML processing
Doctrine ODM to share documents
with CMS system (Symfony2).
MongoDB: Different attributes/fields
depending on event type.
Shot Goal Penalty
Player Player Player
Goal section Goal section
Assists
POP, NEP (players on
ice)
Penalty reason
Parser: PHP, mongoDB
Possible improvements (when needed):
Scale - one parser process per game
(only changes in this component)
Alternatives (PHP based):
- Symfony2 (full-stack)
- Silex (micro)
…
Overview: Editorial input
Editorial input: Symfony2, MySQL
Multiple Operators located in different places
- Live text comments describing the events
- Data tagged with games and teams for filtering
- Flexible, adjustable, custom made functionality
- CMS also includes REST-ish API used by clients
Overview: Queue Controller
Queue Controller: PHP
Decides what messages that should go where.
Isn’t this a broker!?
Yes, kind of…
- Decides which queue(s) to send to.
- No information about actual end points.
How?
Queue Controller: PHP
// Prepare our context and socket
$context = new ZMQContext();
 
// Subscribe to messages from parser
$parser = $context->getSocket(ZMQ::SOCKET_SUB);
 
// Connect to publishing socket
$parser->connect('tcp://192.168.0.11:9900');
// Define the channel(s) for
// delivery servers to subscribe to
$channel = $context->getSocket(ZMQ::SOCKET_PUB);
 
// Bind each channel to an IP and port
$channel->bind('tcp://192.168.0.12:5555');
Queue Controller: PHP
// All in an infinite loop
// ...
// Receive messages from the parser
$msg = $parser->recv();
 
// Which channels will the message go to
$recievingChannels = getChannelsForMsg($msg);
 
// Send message to appropriate channels
foreach ($recievingChannels as $channel) {
    $channel->send($msg);
}
Overview: Delivery
Delivery: Node.js, SockJS
Why Node.JS?
- High concurrency
- Same language as client
Why SockJS?
- Lightweight, but still fallbacks for Web Sockets
- Option to get ”raw” sockets
Alternatives:
- socket.io (or simply polling...)
http://bit.ly/143An2a
NodeJS server code
var server = sockjs.createServer();
    server.on(‘connection’, function(conn) {
    conn.on(‘data’, function(msg) {
        // Check the action passed
        switch (msg.action) {
         // ...
         // Do the corresponding thing...
         // I.e. let the client join a channel
         // ...
        }
    });
});
// Game event message received from Queue Controller
var gameEventMessage = ”blablabla”;
 
// Send a message to a client
var conn = getNextClient(clients);
 
conn.write(gameEventMessage);
NodeJS server code (cont.)
Delivery: Node.js, SockJS
SockJS client code
var sockjs = new SockJS('http://192.168.0.13:8080');
sockjs.onopen = function() {
    // SockJS connection opened
};
 
sockjs.onmessage = function(e) {
    // Message recieved
    var msg = JSON.parse(e.data);
};
 
sockjs.onclose = function() {
  // Connection closed
  // Offer the user possibility to reconnect
    $('button#reconnect').show();
};
Overview: Monitoring and Logging
Overview: Monitoring and Logging
Overview: Clients
Several versions
- Web
- Mobile version
- Mobile version for arenas (using local WiFi)
The different versions share a lot of functionality.
Clients: Symfony2, HTML5, JavaScript
Clients: Desktop version
Clients: Mobile versions
What have we learned?
- Good to keep things separated
- Don’t over engineer the solution!
But...
...by keeping things separated you can re-engineer later –
when needed!
- Use the tools you know how to handle
- Select the most appropriate tool from your own toolchain
Software
ZeroMQ: http://www.zeromq.org
NodeJS: http://nodejs.org
SockJS: https://github.com/sockjs
Examples
Web: http://www.hockeyligan.se
Mobile: http://m.hockeyligan.se
REFERENCES AND RESOURCES

More Related Content

What's hot

Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ihor Banadiga
 
Ansible with-junos
Ansible with-junosAnsible with-junos
Ansible with-junosAkhmad Zaimi
 
Building a moat bastion server
Building a moat   bastion serverBuilding a moat   bastion server
Building a moat bastion servernseemiller
 
Salt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaSalt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaDevOpsBangalore
 
PV-Drivers for SeaBIOS using Upstream Qemu
PV-Drivers for SeaBIOS using Upstream QemuPV-Drivers for SeaBIOS using Upstream Qemu
PV-Drivers for SeaBIOS using Upstream QemuThe Linux Foundation
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016Dave Stokes
 
EuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo DriverEuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo DriverJoe Drumgoole
 
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...The Linux Foundation
 
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...NETWAYS
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, Citrix
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, CitrixXPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, Citrix
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, CitrixThe Linux Foundation
 
1. Core Features of Apache RocketMQ
1. Core Features of Apache RocketMQ1. Core Features of Apache RocketMQ
1. Core Features of Apache RocketMQ振东 刘
 
Ømq - Distributed queues, threads and sockets
Ømq - Distributed queues, threads and socketsØmq - Distributed queues, threads and sockets
Ømq - Distributed queues, threads and socketsTihomir Trifonov
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsSaltStack
 
Salt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementSalt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementUmberto Nicoletti
 
Network Automation: Ansible 101
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101APNIC
 
Intercepting Windows Printing by Modifying GDI Subsystem
Intercepting Windows Printing by Modifying GDI SubsystemIntercepting Windows Printing by Modifying GDI Subsystem
Intercepting Windows Printing by Modifying GDI SubsystemPositive Hack Days
 

What's hot (19)

Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
 
Ansible with-junos
Ansible with-junosAnsible with-junos
Ansible with-junos
 
Building a moat bastion server
Building a moat   bastion serverBuilding a moat   bastion server
Building a moat bastion server
 
Salt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaSalt Stack - Subhankar Sengupta
Salt Stack - Subhankar Sengupta
 
PV-Drivers for SeaBIOS using Upstream Qemu
PV-Drivers for SeaBIOS using Upstream QemuPV-Drivers for SeaBIOS using Upstream Qemu
PV-Drivers for SeaBIOS using Upstream Qemu
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
EuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo DriverEuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo Driver
 
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...
XPDS14 - RT-Xen: Real-Time Virtualization in Xen - Sisu Xi, Washington Univer...
 
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, Citrix
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, CitrixXPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, Citrix
XPDS14 - Scaling Xen's Aggregate Storage Performance - Felipe Franciosi, Citrix
 
1. Core Features of Apache RocketMQ
1. Core Features of Apache RocketMQ1. Core Features of Apache RocketMQ
1. Core Features of Apache RocketMQ
 
Phoenix: Sent 200 OK in 3 μs
Phoenix: Sent 200 OK in 3 μsPhoenix: Sent 200 OK in 3 μs
Phoenix: Sent 200 OK in 3 μs
 
Ømq - Distributed queues, threads and sockets
Ømq - Distributed queues, threads and socketsØmq - Distributed queues, threads and sockets
Ømq - Distributed queues, threads and sockets
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management tools
 
Salt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementSalt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration Management
 
Network Automation: Ansible 101
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101
 
RunX ELCE 2020
RunX ELCE 2020RunX ELCE 2020
RunX ELCE 2020
 
Intercepting Windows Printing by Modifying GDI Subsystem
Intercepting Windows Printing by Modifying GDI SubsystemIntercepting Windows Printing by Modifying GDI Subsystem
Intercepting Windows Printing by Modifying GDI Subsystem
 

Viewers also liked

Rekap setoran maret 2013
Rekap setoran maret 2013Rekap setoran maret 2013
Rekap setoran maret 2013Azam Serak
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
Sports 2.0 : The Changing Face Of Sports & The Sporting Experience
Sports 2.0 : The Changing Face Of Sports & The Sporting ExperienceSports 2.0 : The Changing Face Of Sports & The Sporting Experience
Sports 2.0 : The Changing Face Of Sports & The Sporting ExperienceInstitute of Customer Experience
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (7)

Rekap setoran maret 2013
Rekap setoran maret 2013Rekap setoran maret 2013
Rekap setoran maret 2013
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Sports 2.0 : The Changing Face Of Sports & The Sporting Experience
Sports 2.0 : The Changing Face Of Sports & The Sporting ExperienceSports 2.0 : The Changing Face Of Sports & The Sporting Experience
Sports 2.0 : The Changing Face Of Sports & The Sporting Experience
 
India in sports
India in sportsIndia in sports
India in sports
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Php day2013 sports_statistics

Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf euXie ChengChao
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.jsXie ChengChao
 
Scrum alliance 2013-mmog
Scrum alliance 2013-mmogScrum alliance 2013-mmog
Scrum alliance 2013-mmogsajitv
 
BonAHA framework - IEEE CCNC 2009
BonAHA framework - IEEE CCNC 2009BonAHA framework - IEEE CCNC 2009
BonAHA framework - IEEE CCNC 2009Suman Srinivasan
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Puppet
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''OdessaJS Conf
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson
 
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021WDDay
 
Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1Yongyoon Shin
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics PlatformSrinath Perera
 
Openstack Networking Internals - first part
Openstack Networking Internals - first partOpenstack Networking Internals - first part
Openstack Networking Internals - first partlilliput12
 
Sharing-Knowledge-OAM-3G-Ericsson .ppt
Sharing-Knowledge-OAM-3G-Ericsson   .pptSharing-Knowledge-OAM-3G-Ericsson   .ppt
Sharing-Knowledge-OAM-3G-Ericsson .pptwafawafa52
 
How Microsoft will MiTM your network
How Microsoft will MiTM your networkHow Microsoft will MiTM your network
How Microsoft will MiTM your networkBrandon DeVault
 
Game server development in node.js
Game server development in node.jsGame server development in node.js
Game server development in node.jsXie ChengChao
 
Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Fwdays
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesWSO2
 
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routers
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routersConfiguring cisco site to site ip sec vpn with dynamic ip endpoint cisco routers
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routersphosika sithisane
 
How to build own IoT Platform
How to build own IoT PlatformHow to build own IoT Platform
How to build own IoT PlatformPatryk Omiotek
 
DCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep diveDCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep diveMadhu Venugopal
 

Similar to Php day2013 sports_statistics (20)

Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
 
Scrum alliance 2013-mmog
Scrum alliance 2013-mmogScrum alliance 2013-mmog
Scrum alliance 2013-mmog
 
BonAHA framework - IEEE CCNC 2009
BonAHA framework - IEEE CCNC 2009BonAHA framework - IEEE CCNC 2009
BonAHA framework - IEEE CCNC 2009
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
 
Sgin2013 scrum accomplished-mmog-sajitvasudevan
Sgin2013 scrum accomplished-mmog-sajitvasudevanSgin2013 scrum accomplished-mmog-sajitvasudevan
Sgin2013 scrum accomplished-mmog-sajitvasudevan
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
ОЛЕКСАНДР ЛИПКО «Graceful Shutdown Node.js + k8s» Online WDDay 2021
 
Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics Platform
 
Openstack Networking Internals - first part
Openstack Networking Internals - first partOpenstack Networking Internals - first part
Openstack Networking Internals - first part
 
Sharing-Knowledge-OAM-3G-Ericsson .ppt
Sharing-Knowledge-OAM-3G-Ericsson   .pptSharing-Knowledge-OAM-3G-Ericsson   .ppt
Sharing-Knowledge-OAM-3G-Ericsson .ppt
 
How Microsoft will MiTM your network
How Microsoft will MiTM your networkHow Microsoft will MiTM your network
How Microsoft will MiTM your network
 
Game server development in node.js
Game server development in node.jsGame server development in node.js
Game server development in node.js
 
Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web Services
 
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routers
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routersConfiguring cisco site to site ip sec vpn with dynamic ip endpoint cisco routers
Configuring cisco site to site ip sec vpn with dynamic ip endpoint cisco routers
 
How to build own IoT Platform
How to build own IoT PlatformHow to build own IoT Platform
How to build own IoT Platform
 
DCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep diveDCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep dive
 

Php day2013 sports_statistics

  • 1. REAL-TIME SPORTS STATISTICS WITH NODE.JS, WEBSOCKETS AND SYMFONY2
  • 2. #42 TOBIAS JOSEFSSON Chief Technology Officer ”Bobbe” / ”Bobby” @TobiasJosefsson #8 EMANUEL WINBLAD Soware Engineer ”Manne” / ”Manny” @ManneW SPORTS EDITING SWEDEN A MEDIA HOUSE FOCUSED ON SPORTS
  • 3.
  • 4. Overview: Data flow from Operators to Clients
  • 5. Overview: Data flow from Operators to Clients
  • 6. Why this complex setup? ”Independent” decoupled parts - Easier to test - Easier to maintain / replace - Each part only does one thing Multiple languages - There is no silver bullet
  • 7. Messaging: ZeroMQ "ZeroMQ is a messaging library, which allows you to design a complex communication system without much effort." – Nicholas Piël ”Messaging makes everything possible!” – Alvaro Videla, JSDay 2013 (yesterday)
  • 8. Messaging: ZeroMQ RabbitMQ ZeroMQ Broker Brokerless Messaging System Messaging Library Why: - Lightweight - Minimalistic - Small feature set needed
  • 11. Statistics input: External system Seven Operators per arena, logging events. - Shots on net, shots wide, shots blocked - Goals and assists - Players currently on the ice, shifts - Penalties - Hits - ...and much more... Data is transferred using XML files and http(s).
  • 13. Parser: PHP, mongoDB PHP: Familiar, XML processing Doctrine ODM to share documents with CMS system (Symfony2). MongoDB: Different attributes/fields depending on event type. Shot Goal Penalty Player Player Player Goal section Goal section Assists POP, NEP (players on ice) Penalty reason
  • 14. Parser: PHP, mongoDB Possible improvements (when needed): Scale - one parser process per game (only changes in this component) Alternatives (PHP based): - Symfony2 (full-stack) - Silex (micro) …
  • 16. Editorial input: Symfony2, MySQL Multiple Operators located in different places - Live text comments describing the events - Data tagged with games and teams for filtering - Flexible, adjustable, custom made functionality - CMS also includes REST-ish API used by clients
  • 18. Queue Controller: PHP Decides what messages that should go where. Isn’t this a broker!? Yes, kind of… - Decides which queue(s) to send to. - No information about actual end points. How?
  • 19. Queue Controller: PHP // Prepare our context and socket $context = new ZMQContext();   // Subscribe to messages from parser $parser = $context->getSocket(ZMQ::SOCKET_SUB);   // Connect to publishing socket $parser->connect('tcp://192.168.0.11:9900'); // Define the channel(s) for // delivery servers to subscribe to $channel = $context->getSocket(ZMQ::SOCKET_PUB);   // Bind each channel to an IP and port $channel->bind('tcp://192.168.0.12:5555');
  • 20. Queue Controller: PHP // All in an infinite loop // ... // Receive messages from the parser $msg = $parser->recv();   // Which channels will the message go to $recievingChannels = getChannelsForMsg($msg);   // Send message to appropriate channels foreach ($recievingChannels as $channel) {     $channel->send($msg); }
  • 22. Delivery: Node.js, SockJS Why Node.JS? - High concurrency - Same language as client Why SockJS? - Lightweight, but still fallbacks for Web Sockets - Option to get ”raw” sockets Alternatives: - socket.io (or simply polling...) http://bit.ly/143An2a
  • 23. NodeJS server code var server = sockjs.createServer();     server.on(‘connection’, function(conn) {     conn.on(‘data’, function(msg) {         // Check the action passed         switch (msg.action) {          // ...          // Do the corresponding thing...          // I.e. let the client join a channel          // ...         }     }); });
  • 24. // Game event message received from Queue Controller var gameEventMessage = ”blablabla”;   // Send a message to a client var conn = getNextClient(clients);   conn.write(gameEventMessage); NodeJS server code (cont.)
  • 25. Delivery: Node.js, SockJS SockJS client code var sockjs = new SockJS('http://192.168.0.13:8080'); sockjs.onopen = function() {     // SockJS connection opened };   sockjs.onmessage = function(e) {     // Message recieved     var msg = JSON.parse(e.data); };   sockjs.onclose = function() {   // Connection closed   // Offer the user possibility to reconnect     $('button#reconnect').show(); };
  • 29. Several versions - Web - Mobile version - Mobile version for arenas (using local WiFi) The different versions share a lot of functionality. Clients: Symfony2, HTML5, JavaScript
  • 32. What have we learned? - Good to keep things separated - Don’t over engineer the solution! But... ...by keeping things separated you can re-engineer later – when needed! - Use the tools you know how to handle - Select the most appropriate tool from your own toolchain
  • 33. Software ZeroMQ: http://www.zeromq.org NodeJS: http://nodejs.org SockJS: https://github.com/sockjs Examples Web: http://www.hockeyligan.se Mobile: http://m.hockeyligan.se REFERENCES AND RESOURCES