http push
DESCRIPTION
A 2010 case study with the NGINX HTTP Push Module, Ruby on Rails, and friends, by Luke Melia of WeplayTRANSCRIPT
![Page 1: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/1.jpg)
“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
![Page 2: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/2.jpg)
PushA 2010 case study with
the NGINX HTTP Push Module,Ruby on Rails, and friends
Luke Melia
Thursday, March 11, 2010
![Page 3: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/3.jpg)
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
![Page 4: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/4.jpg)
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
![Page 5: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/5.jpg)
The Goal★ Immediate encouragement
of positive on-site actions
★ “Points!”
Thursday, March 11, 2010
![Page 6: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/6.jpg)
+10
Thursday, March 11, 2010
![Page 7: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/7.jpg)
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
![Page 8: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/8.jpg)
Pure pushdoesn’t exist
on the open web
Thursday, March 11, 2010
![Page 9: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/9.jpg)
Push-likesolutions
XMPP
Comet
WebSockets
StreamingThursday, March 11, 2010
![Page 10: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/10.jpg)
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
![Page 11: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/11.jpg)
★ 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
![Page 12: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/12.jpg)
Comet
★ Push data over a long held Ajax request using browser-native technologies
★ Bayeaux protocol★ Long-polling Ajax
Thursday, March 11, 2010
![Page 13: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/13.jpg)
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
![Page 14: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/14.jpg)
XMPP
Comet
WebSockets
StreamingThursday, March 11, 2010
![Page 15: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/15.jpg)
Servers
NGINX HTTP Push Module
Faye
Tornado
ejabberd
Orbited
Diesel
CrampRainbows!
Sunshowers
Juggernaut
Thursday, March 11, 2010
![Page 16: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/16.jpg)
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
![Page 17: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/17.jpg)
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
![Page 18: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/18.jpg)
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
![Page 19: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/19.jpg)
ChannelConcurrency Styles
★Broadcast★Last-in, first-out★ First-in, last-out
Thursday, March 11, 2010
![Page 20: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/20.jpg)
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
![Page 21: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/21.jpg)
# 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
![Page 22: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/22.jpg)
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
![Page 23: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/23.jpg)
Code it up.
Thursday, March 11, 2010
![Page 24: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/24.jpg)
Client-side Gotchas
★ Javascript blocking
★ Put it in an iframe
★ Per domain connection limit
★ use subdomain, with JSONP
Thursday, March 11, 2010
![Page 25: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/25.jpg)
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
![Page 26: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/26.jpg)
Testing
★ Fake Publisher for in-memory cucumber scenarios
★ Run selenium scenarios through NGINX to incorporate actual push module behavior
Thursday, March 11, 2010
![Page 27: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/27.jpg)
NGINX Configuration Management
★Template it★Version it★Automate it
Thursday, March 11, 2010
![Page 28: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/28.jpg)
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
![Page 29: Http Push](https://reader034.vdocuments.net/reader034/viewer/2022051608/545437e8b1af9f88228b4977/html5/thumbnails/29.jpg)
Questions?
Thursday, March 11, 2010