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

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Recently uploaded (20)

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

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