28
Scaling CometD to The Masses by Kevin Nilson Principal Architect / E*Trade Financial

Scaling CometD by Kevin Nilson

Embed Size (px)

Citation preview

Page 1: Scaling CometD by Kevin Nilson

Scaling CometD to The Masses

by Kevin Nilson

Principal Architect / E*Trade Financial

Page 2: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Learn about CometD and Scaling CometD Apps

Page 3: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Agenda

Quick Intro to CometD

Basic Steps (Outside CometD)

Advanced Steps (Inside CometD)

Page 4: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Kevin Nilson

Java Champion

Co-authored Web 2.0 Fundamentals Book

Leader Silicon Valley Web Developer JUG

Lead Silicon Valley Google Tech User Group

Leader Silicon Valley JavaScript Meetup

Taught 7 Courses College Of San Mateo

Winner of MySpace Editor's Choice Award for project YumieDate, at Open Social Weekend Apps hosted at Google

Page 5: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Intro To CometD

What’s Comet? What’s Bayeux?What’s CometD?

Pushing Data to The Net over HTTPChannel & JSON Based Comet Protocol

Comet Client and Server Implementation using BayeuxWhat’s WebSockets?

Page 6: Scaling CometD by Kevin Nilson

DEMO

Polling Interal

Page 7: Scaling CometD by Kevin Nilson

Polling

Page 8: Scaling CometD by Kevin Nilson

Long Polling

Page 9: Scaling CometD by Kevin Nilson

Streaming

Page 10: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Basic Steps (Outside CometD)

Reduce overheadAllow MultithreadingRemove Simple Bottlenecks

Page 11: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Remove Apache

Apache Has 1 Thread Per Request Limit

Browse Apache Jetty

Page 12: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Separate Client Into Tiers

Some high throughput some lowSpreads broadcast over multiple threads

Delivery to 5 channels can be handled by 5 threadsDelivery to 1 Channel can be handled by only 1

thread

/GameUpdatePublisher

/Player/GameUpdate

/Watcher/GameUpdate

High Volume

Low Volume

Page 13: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Only Deliver Changed Fields

Message 1 Message 2 Message 3 Message 4 Message 5

Green Score 0 0 0 1 2

White Score 0 1 2 2 2

Total Players 10 11 11 9 9

50% Field Delivery Reduction

Page 14: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Advanced Steps

Move Customers to slower tier if they are not consuming fast enough

Disconnect users with very “large” queues

Auto adjust throttling if overall we are producing faster than we can consume (deliver to customers)

Page 15: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Before, No Internal Visiblity

Jetty

JMSBayeuxServic

e

Browser

I can see

I can’t see

LEDGEND

filter

Page 16: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Before – Full Story

Jetty

JMSBayeuxServiceBrowser

Queue

I can see

I can’t see

LEDGEND

filter

Page 17: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

After

Jetty

JMSBayeuxServiceBrowser

Queue

I can see

I can’t see

LEDGEND

QueueListenerDeliverListener

filter

Page 18: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Queue & Deliver Listener Code

client.addListener(new DeliverListener( ) {public void deliver(Client arg0, Queue<Message> queue) {

…}

}

client.addListener(new QueueListener() {public boolean queueMaxed(Client client, Client client1, Message arg2) {

…}

}

Page 19: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Prevent Huge Queue

Jetty

JMSBayeuxServiceBrowser

Queue

I can see

I can’t see

LEDGEND

Check Queue Size:Disconnect Client if

“Large”

filter

Page 20: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Measure Average Time in Queue

Jetty

JMSBayeuxServiceBrowser

Queue

I can see

I can’t see

LEDGEND

Check Time In Queue:Move Client to Slower Tier or Increase Overall

Throttling

filter

Page 21: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Adjust Tier: Avg Queue Size of Client

JMSMyBayeuxService

Platinum

GoldSilver

Bronze

LEDGEND

Platinum = 100 updates / minuteGold = 50 updates / minuteSilver = 25 updates / minuteBronze = 10 updates / minute

Page 22: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Broadcast in CometD, not JMS

JMSMyBayeuxServiceBrowserBrowserBrowser

JMSMyBayeuxServiceBrowserBrowserBrowser

Page 23: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Channel Create & Remove Listener

JMSMyBayeuxService

channelAddedchannelRemoved

Page 24: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

ChannelBayeuxListener Code

bayeux.addListener(new ChannelBayeuxListener() {public void channelAdded(Channel channel) {

// Code Here}

public void channelRemoved(Channel channel) {// Code Here

}});

Page 25: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Adjust Tier Rate based on Avg Queue Size

JMSMyBayeuxService

Platinum

GoldSilver

Bronze

LEDGEND

Platinum = 100 updates / minuteGold = 50 updates / minuteSilver = 25 updates / minuteBronze = 10 updates / minute

Platinum = 50 updates / minuteGold = 25 updates / minuteSilver = 10 updates / minuteBronze = 5 updates / minute

Page 26: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Auto Throttle: Avg Message Delay

LEDGEND

Platnium = 100 updates Gold = 50 updatesSilver = 25 updatesBronze = 10 updates

Jetty

JMSBayeuxServiceBrowser

Queue

filter

Platnium = 50 updates Gold = 25 updatesSilver = 10 updatesBronze = 5 updates

Page 27: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Summary

CometD Intro

Basic Steps

Advanced Steps

. . .

Page 28: Scaling CometD by Kevin Nilson

ww

w.d

evo

xx.c

om

Thanks

[email protected]

Web2-book.com - Web2.0 Fundamentals