SlideShare a Scribd company logo
1 of 22
Download to read offline
Publish / Subscribe
in Ruby
Adrien Siami - Dimelo
@Intrepidd
What’s Pub / Sub ?
• Bidirectional communication between server and
clients

• Clients subscribe to channels

• Server or client pushes events to some channels

• Clients are notified in realtime!
Use case
• Private messaging

• Broadcasting

• Server-sent events
Possible Solutions (in ruby)
• Pusher

• PubNub

• Faye
Pusher
Pros

• SaaS

• Batteries Included (Auth, Presence)

Cons 

• SaaS
PubNub
Pros

• SaaS

• Batteries Included (Auth, Presence)

Cons

• SaaS

• One event = one channel
Faye
Pros

• Built with ! (And Javascript)

• Open Source and self hosted

• Extensible

• Server level hooks

• Globbing (/users/*)

• Great Maintainer (@jcoglan)

Cons

• Les batteries included
Benchmarks
Websocket Json-p Cors Failure rate
Faye 84.68% 5.46% 9.81% 0.62%
Pusher 88.4% 6,67% 4,94% 3.7%
Faye Overview - Javascript
var client = new Faye.Client('http://foo.bar/faye');
!
client.subscribe('/user/123', function(message) {
console.log(message.content);
});
!
client.publish('/user/999', {content: 'Hey dude wassup?'});
Faye Overview - Ruby
require 'faye'
require 'eventmachine'
!
EM.run {
!
client = Faye::Client.new('http://foo.bar/faye')
!
client.subscribe('/user/123') do |message|
puts message.content
end
!
client.publish('/user/999', {content: 'Hey dude wassup?'})
}
Faye Hosting
• It’s a Rack system ! I Know this.

• EventMachine, one thread, tons of connections

• In-Memory by default

• Faye engines, e.g faye-redis, for multiple process
architecture
Benchmarks
Server
Without redis!
(1 worker)!
With redis!
(1 worker)
with redis !
(4 workers)
Passenger
+ nginx
43 sec 1m 25 sec 53 sec
Node!
1m 18 sec 1m 42 sec
Thin 38 sec 1m 28 sec
Puma 30 sec 1m 28 sec 43 sec
• Connect 10k clients
• Subscribe
• send some messages
• disconnect
Gotchas
• Tune your file descriptors

• Use EM.epoll

• PhusionPassenger.advertised_concurrency_level = 0

• passenger_max_requests 0;
DIY !
• Authentication

• Presence
Faye Authentication
• JWT based signature, generated by the Rails
Server when allowed

• Inserted into the faye request through a plugin
executing an Ajax Call

• Check at the faye server level
dimelo/faye-authentication
Faye Authentication
In a controller app (route /faye/auth):
def auth
if can?(:read, params[:message].try(:channel))
render :json => {signature: Faye::Authentication.sign(params[:message], 'faye
secret')}
else
render :text => "Forbidden", :status => '403'
end
In your JS :
client.addExtension(new FayeAuthentication(client));
Faye Authentication
On the faye server (config.ru):
server = Faye::RackAdapter.new mount: '/faye'
server.add_extension Faye::Authentication::ServerExtension.new('faye secret')
run server
Faye Presence
• Keep track of several clients per user

• Notify connection / disconnection

• Keep infos about the session (away / available)
Faye Presence
{
"event": "user-disconnected",
"user": {
"id": 42,
"infos" : {
"status": "away"
}
}
}
Thank you.
Dimelo contest!
• Submit a pull request on a 20+ stars ruby Github repository
• Have it merged
• Have a chance to win a Xbox One or a PS4
• http://contest.dimelo.com
• http://jobs.dimelo.com

More Related Content

What's hot

Building a Messaging Framework on the Salesforce1 Platform
Building a Messaging Framework on the Salesforce1 PlatformBuilding a Messaging Framework on the Salesforce1 Platform
Building a Messaging Framework on the Salesforce1 PlatformAnup Jadhav
 
Lifecycleofhostdeployedwithforemanandautomated
LifecycleofhostdeployedwithforemanandautomatedLifecycleofhostdeployedwithforemanandautomated
LifecycleofhostdeployedwithforemanandautomatedKanwar Batra
 
SCCM Intune Windows 10 Co Management Architecture Decisions
SCCM Intune Windows 10 Co Management Architecture DecisionsSCCM Intune Windows 10 Co Management Architecture Decisions
SCCM Intune Windows 10 Co Management Architecture DecisionsAnoop Nair
 
ESB Online Training Part 2
ESB Online Training Part 2ESB Online Training Part 2
ESB Online Training Part 2Vince Soliza
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITASIT
 
Cache control directive
Cache control directiveCache control directive
Cache control directiveMohamed Mamoon
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabnerStephen Thair
 
Real Time with Rails 5
Real Time with Rails 5Real Time with Rails 5
Real Time with Rails 5Lucas Renan
 
BlazeMeter Presents at the High Performance Drupal Meetup
BlazeMeter Presents at the High Performance Drupal MeetupBlazeMeter Presents at the High Performance Drupal Meetup
BlazeMeter Presents at the High Performance Drupal MeetupBlazeMeter
 
Scaling CometD by Kevin Nilson
Scaling CometD by Kevin Nilson Scaling CometD by Kevin Nilson
Scaling CometD by Kevin Nilson Jug Chennai
 
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexWhat is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexHaehnchen
 
Betfair's Site Rebuild: Fast - We promise
Betfair's Site Rebuild: Fast - We promiseBetfair's Site Rebuild: Fast - We promise
Betfair's Site Rebuild: Fast - We promiseTim Morrow
 
Java Servlet Lifecycle
Java Servlet LifecycleJava Servlet Lifecycle
Java Servlet LifecycleAathikaJava
 
Design & Secure Your Cloud Infrastructure
Design & Secure Your Cloud Infrastructure Design & Secure Your Cloud Infrastructure
Design & Secure Your Cloud Infrastructure Anoop Nair
 

What's hot (20)

Building a Messaging Framework on the Salesforce1 Platform
Building a Messaging Framework on the Salesforce1 PlatformBuilding a Messaging Framework on the Salesforce1 Platform
Building a Messaging Framework on the Salesforce1 Platform
 
Increase automation to rest
Increase automation to restIncrease automation to rest
Increase automation to rest
 
Lifecycleofhostdeployedwithforemanandautomated
LifecycleofhostdeployedwithforemanandautomatedLifecycleofhostdeployedwithforemanandautomated
Lifecycleofhostdeployedwithforemanandautomated
 
SCCM Intune Windows 10 Co Management Architecture Decisions
SCCM Intune Windows 10 Co Management Architecture DecisionsSCCM Intune Windows 10 Co Management Architecture Decisions
SCCM Intune Windows 10 Co Management Architecture Decisions
 
ESB Online Training Part 2
ESB Online Training Part 2ESB Online Training Part 2
ESB Online Training Part 2
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASIT
 
Cache control directive
Cache control directiveCache control directive
Cache control directive
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
 
VPC Hands-on
VPC Hands-onVPC Hands-on
VPC Hands-on
 
Real Time with Rails 5
Real Time with Rails 5Real Time with Rails 5
Real Time with Rails 5
 
BlazeMeter Presents at the High Performance Drupal Meetup
BlazeMeter Presents at the High Performance Drupal MeetupBlazeMeter Presents at the High Performance Drupal Meetup
BlazeMeter Presents at the High Performance Drupal Meetup
 
Soap xp-wg
Soap xp-wgSoap xp-wg
Soap xp-wg
 
Scaling CometD by Kevin Nilson
Scaling CometD by Kevin Nilson Scaling CometD by Kevin Nilson
Scaling CometD by Kevin Nilson
 
Hidden gems in cf2016
Hidden gems in cf2016Hidden gems in cf2016
Hidden gems in cf2016
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
 
Web Services Testing
Web Services TestingWeb Services Testing
Web Services Testing
 
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexWhat is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
 
Betfair's Site Rebuild: Fast - We promise
Betfair's Site Rebuild: Fast - We promiseBetfair's Site Rebuild: Fast - We promise
Betfair's Site Rebuild: Fast - We promise
 
Java Servlet Lifecycle
Java Servlet LifecycleJava Servlet Lifecycle
Java Servlet Lifecycle
 
Design & Secure Your Cloud Infrastructure
Design & Secure Your Cloud Infrastructure Design & Secure Your Cloud Infrastructure
Design & Secure Your Cloud Infrastructure
 

Similar to Pub / Sub in Ruby

Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Vinícius Carvalho
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...VMware Tanzu
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008Joe Walker
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2Pratik Khasnabis
 
Realtime web experience with signal r
Realtime web experience with signal rRealtime web experience with signal r
Realtime web experience with signal rRan Wahle
 
Realtime web experience with signalR
Realtime web experience with signalRRealtime web experience with signalR
Realtime web experience with signalRRan Wahle
 
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysUsing communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysCodemotion Tel Aviv
 
Architecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web APIArchitecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web APISHAKIL AKHTAR
 
Ntu workshop : REST, PayPal APIs & Async
Ntu workshop : REST, PayPal APIs & AsyncNtu workshop : REST, PayPal APIs & Async
Ntu workshop : REST, PayPal APIs & AsyncAeshan Wijetunge
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleC2B2 Consulting
 
ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2Jaliya Udagedara
 
Cloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route serviceCloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route serviceGwenn Etourneau
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultJeff Horwitz
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with FayeMatjaž Lipuš
 
Exploring Contact Lens and Amazon Connect
Exploring Contact Lens and Amazon ConnectExploring Contact Lens and Amazon Connect
Exploring Contact Lens and Amazon ConnectCloudHesive
 
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...Daniel Bryant
 
Consuming Web Services in Microsoft Silverlight 3
Consuming Web Services in Microsoft Silverlight 3Consuming Web Services in Microsoft Silverlight 3
Consuming Web Services in Microsoft Silverlight 3goodfriday
 

Similar to Pub / Sub in Ruby (20)

Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
 
WebSocket
WebSocketWebSocket
WebSocket
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008
 
Palestra VCR
Palestra VCRPalestra VCR
Palestra VCR
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2
 
Realtime web experience with signal r
Realtime web experience with signal rRealtime web experience with signal r
Realtime web experience with signal r
 
Realtime web experience with signalR
Realtime web experience with signalRRealtime web experience with signalR
Realtime web experience with signalR
 
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysUsing communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
 
Architecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web APIArchitecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web API
 
Operating your Production API
Operating your Production APIOperating your Production API
Operating your Production API
 
Ntu workshop : REST, PayPal APIs & Async
Ntu workshop : REST, PayPal APIs & AsyncNtu workshop : REST, PayPal APIs & Async
Ntu workshop : REST, PayPal APIs & Async
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2
 
Cloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route serviceCloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route service
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
 
Exploring Contact Lens and Amazon Connect
Exploring Contact Lens and Amazon ConnectExploring Contact Lens and Amazon Connect
Exploring Contact Lens and Amazon Connect
 
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
Canadian CNCF: "Emissary-ingress 101: An introduction to the CNCF incubation-...
 
Consuming Web Services in Microsoft Silverlight 3
Consuming Web Services in Microsoft Silverlight 3Consuming Web Services in Microsoft Silverlight 3
Consuming Web Services in Microsoft Silverlight 3
 

Recently uploaded

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Recently uploaded (20)

Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Pub / Sub in Ruby

  • 1. Publish / Subscribe in Ruby Adrien Siami - Dimelo @Intrepidd
  • 2. What’s Pub / Sub ? • Bidirectional communication between server and clients • Clients subscribe to channels • Server or client pushes events to some channels • Clients are notified in realtime!
  • 3. Use case • Private messaging • Broadcasting • Server-sent events
  • 4. Possible Solutions (in ruby) • Pusher • PubNub • Faye
  • 5. Pusher Pros • SaaS • Batteries Included (Auth, Presence) Cons • SaaS
  • 6. PubNub Pros • SaaS • Batteries Included (Auth, Presence) Cons • SaaS • One event = one channel
  • 7. Faye Pros • Built with ! (And Javascript) • Open Source and self hosted • Extensible • Server level hooks • Globbing (/users/*) • Great Maintainer (@jcoglan) Cons • Les batteries included
  • 8.
  • 9. Benchmarks Websocket Json-p Cors Failure rate Faye 84.68% 5.46% 9.81% 0.62% Pusher 88.4% 6,67% 4,94% 3.7%
  • 10. Faye Overview - Javascript var client = new Faye.Client('http://foo.bar/faye'); ! client.subscribe('/user/123', function(message) { console.log(message.content); }); ! client.publish('/user/999', {content: 'Hey dude wassup?'});
  • 11. Faye Overview - Ruby require 'faye' require 'eventmachine' ! EM.run { ! client = Faye::Client.new('http://foo.bar/faye') ! client.subscribe('/user/123') do |message| puts message.content end ! client.publish('/user/999', {content: 'Hey dude wassup?'}) }
  • 12. Faye Hosting • It’s a Rack system ! I Know this. • EventMachine, one thread, tons of connections • In-Memory by default • Faye engines, e.g faye-redis, for multiple process architecture
  • 13. Benchmarks Server Without redis! (1 worker)! With redis! (1 worker) with redis ! (4 workers) Passenger + nginx 43 sec 1m 25 sec 53 sec Node! 1m 18 sec 1m 42 sec Thin 38 sec 1m 28 sec Puma 30 sec 1m 28 sec 43 sec • Connect 10k clients • Subscribe • send some messages • disconnect
  • 14. Gotchas • Tune your file descriptors • Use EM.epoll • PhusionPassenger.advertised_concurrency_level = 0 • passenger_max_requests 0;
  • 16. Faye Authentication • JWT based signature, generated by the Rails Server when allowed • Inserted into the faye request through a plugin executing an Ajax Call • Check at the faye server level dimelo/faye-authentication
  • 17. Faye Authentication In a controller app (route /faye/auth): def auth if can?(:read, params[:message].try(:channel)) render :json => {signature: Faye::Authentication.sign(params[:message], 'faye secret')} else render :text => "Forbidden", :status => '403' end In your JS : client.addExtension(new FayeAuthentication(client));
  • 18. Faye Authentication On the faye server (config.ru): server = Faye::RackAdapter.new mount: '/faye' server.add_extension Faye::Authentication::ServerExtension.new('faye secret') run server
  • 19. Faye Presence • Keep track of several clients per user • Notify connection / disconnection • Keep infos about the session (away / available)
  • 20. Faye Presence { "event": "user-disconnected", "user": { "id": 42, "infos" : { "status": "away" } } }
  • 22. Dimelo contest! • Submit a pull request on a 20+ stars ruby Github repository • Have it merged • Have a chance to win a Xbox One or a PS4 • http://contest.dimelo.com • http://jobs.dimelo.com