Top Banner
“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
29

Http Push

Oct 31, 2014

Download

Technology

Luke Melia

A 2010 case study with the NGINX HTTP Push Module, Ruby on Rails, and friends, by Luke Melia of Weplay
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Http Push

“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

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

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

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

The Goal★ Immediate encouragement

of positive on-site actions

★ “Points!”

Thursday, March 11, 2010

Page 6: Http Push

+10

Thursday, March 11, 2010

Page 7: Http Push

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

Pure pushdoesn’t exist

on the open web

Thursday, March 11, 2010

Page 9: Http Push

Push-likesolutions

XMPP

Comet

WebSockets

StreamingThursday, March 11, 2010

Page 10: Http Push

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

★ 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

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

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

XMPP

Comet

WebSockets

StreamingThursday, March 11, 2010

Page 15: Http Push

Servers

NGINX HTTP Push Module

Faye

Tornado

ejabberd

Orbited

Diesel

CrampRainbows!

Sunshowers

Juggernaut

Thursday, March 11, 2010

Page 16: Http Push

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

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

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

ChannelConcurrency Styles

★Broadcast★Last-in, first-out★ First-in, last-out

Thursday, March 11, 2010

Page 20: Http Push

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

# 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

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

Code it up.

Thursday, March 11, 2010

Page 24: Http Push

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

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

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

NGINX Configuration Management

★Template it★Version it★Automate it

Thursday, March 11, 2010

Page 28: Http Push

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

Questions?

Thursday, March 11, 2010