“Because as rapid as the arrival of networked pull media was, the second act - networked push media - is coming even faster. ” March 1997 WIRED Magazine Thursday, March 11, 2010
Oct 31, 2014
“Because as rapid as the arrival of networked pull media was, the second act - networked push media - is coming even faster. ”
March 1997WIRED Magazine
Thursday, March 11, 2010
PushA 2010 case study with
the NGINX HTTP Push Module,Ruby on Rails, and friends
Luke Melia
Thursday, March 11, 2010
Who’s this guy?
★ VP, Engineering at weplay.com
★ Agilist
★ nyc.rb’er since ~2006
★ Ruby in Practice contributor
★ Interested in startup tech leadership
★ Beach volleyball player
★ Dad
Thursday, March 11, 2010
What’s this talk?★ The goal and the problem
★ A quick survey of solutions
★ About the NGINX HTTP Push Module
★ How to use it with Ruby, by example
★ Gotchyas
★ Q & A
Thursday, March 11, 2010
The Goal★ Immediate encouragement
of positive on-site actions
★ “Points!”
Thursday, March 11, 2010
+10
Thursday, March 11, 2010
Constraints★ Don’t want to figure out points earned
while processing the request (offload it to a background work queue)
★ Do want to inform about points earned through another user’s actions
★ Don’t want to wait for a second page load
Thursday, March 11, 2010
Pure pushdoesn’t exist
on the open web
Thursday, March 11, 2010
Push-likesolutions
XMPP
Comet
WebSockets
StreamingThursday, March 11, 2010
Streaming
★ Don’t close the connection after sending down the page
★ multipart/x-mixed-replace★ Supported in non-Microsoft
browsers only
Thursday, March 11, 2010
★ Designed for presence and messaging★ Browsers don’t speak XMPP natively★ BOSH★ Hemlock: Flex + ejabberd, by NYC’s
Mint Digital
XMPP
Thursday, March 11, 2010
Comet
★ Push data over a long held Ajax request using browser-native technologies
★ Bayeaux protocol★ Long-polling Ajax
Thursday, March 11, 2010
WebSockets
★ HTML 5★ Full-duplex single socket connection
between browser and server★ ex: ws://websockets.org:8787★ very limited browser support today
Thursday, March 11, 2010
XMPP
Comet
WebSockets
StreamingThursday, March 11, 2010
Servers
NGINX HTTP Push Module
Faye
Tornado
ejabberd
Orbited
Diesel
CrampRainbows!
Sunshowers
Juggernaut
Thursday, March 11, 2010
NGINX HTTP Push Module
★ Turns NGINX into a Comet server
★ “A useful tool with a boring name.”
★ By Leo P
★ http://pushmodule.slact.net/
★ Currently at 0.692β
Thursday, March 11, 2010
Basic HTTP PushRelay Protocol
★ Subscriber locations
★ HTTP GET with channel ID
★ Publisher locations
★ HTTP POST with channel ID
★ POSTed data is passed through, becoming the response to the subscriber’s GET
Thursday, March 11, 2010
NGINX
Subscriber endpoint
Publisher endpoint
End User
BACK-END
PROCESS
Diagramming the simple case
1. HTTP GET
2. HTTP POST
3. POST BODYIS ROUTED BYCHANNEL ID
4. RESPONSE ISDATA FROMPOST BODY
Thursday, March 11, 2010
ChannelConcurrency Styles
★Broadcast★Last-in, first-out★ First-in, last-out
Thursday, March 11, 2010
Subscriber config
# public long‐polling endpoint
location /rt/notifications {
push_subscriber;
set $push_channel_id $arg_id;
push_subscriber_concurrency last;
}
Thursday, March 11, 2010
# internal publish endpoint# (keep it private / protected)location /rt/publish { push_publisher; set $push_channel_id $arg_id; push_store_messages on; push_message_timeout 5m; push_max_message_buffer_length 5; push_min_message_buffer_length 0; push_delete_oldest_received_message on;}
Publisher config
Thursday, March 11, 2010
NGINX
Subscriber endpoint
Publisher endpoint
End User
BACK-END
PROCESS
Diagram with storage
3. HTTP GET
1. HTTP POST
5. RESPONSE ISDATA FROM
QUEUE
Queue
2. POST BODYIS QUEUED
BY CHANNEL ID
4. MESSAGEIS RETRIEVEDFROM QUEUE
BY CHANNEL ID
Thursday, March 11, 2010
Code it up.
Thursday, March 11, 2010
Client-side Gotchas
★ Javascript blocking
★ Put it in an iframe
★ Per domain connection limit
★ use subdomain, with JSONP
Thursday, March 11, 2010
Server-side Gotchas★ “Too many open connections”
★ Reduce worker_connections to less than ulimit -n
★ Increase worker_processes to give you enough total connection to serve your users
★ Ours: worker_processes 24 worker_connections 960
Thursday, March 11, 2010
Testing
★ Fake Publisher for in-memory cucumber scenarios
★ Run selenium scenarios through NGINX to incorporate actual push module behavior
Thursday, March 11, 2010
NGINX Configuration Management
★Template it★Version it★Automate it
Thursday, March 11, 2010
The Future
★ Multiplexing: subscribe to more than one channel
★ Use Redis as a message store
★ Convention-based approach for raising javascript events
Thursday, March 11, 2010
Questions?
Thursday, March 11, 2010