astricon 2016 - scaling ari and production

137
ARI Scaling & Production Dan Jenkins @dan_jenkins

Upload: dan-jenkins

Post on 14-Jan-2017

148 views

Category:

Technology


8 download

TRANSCRIPT

Page 1: Astricon 2016 - Scaling ARI and Production

ARI Scaling & Production

Dan Jenkins

@dan_jenkins

Page 2: Astricon 2016 - Scaling ARI and Production

Dan Jenkins

@dan_jenkins

5th Astricon!

Author of node-asterisk-ami package on github/npm

Lego

[email protected]

Page 3: Astricon 2016 - Scaling ARI and Production

Google Developer Expert

Web Technologies GDE

@dan_jenkins

Page 4: Astricon 2016 - Scaling ARI and Production

Real Time Communications Consultancy

@nimbleapeltd

Page 5: Astricon 2016 - Scaling ARI and Production

I've become fairly well known to use lego images

in my slide decks...

@dan_jenkins

Page 6: Astricon 2016 - Scaling ARI and Production

They're interesting

@dan_jenkins

Page 7: Astricon 2016 - Scaling ARI and Production

And I ♥ Lego.

@dan_jenkins

Page 8: Astricon 2016 - Scaling ARI and Production

So its Lego time!

@dan_jenkins

Page 9: Astricon 2016 - Scaling ARI and Production

A tale of two parts

Page 10: Astricon 2016 - Scaling ARI and Production

Scaling ARI

@dan_jenkins

Page 11: Astricon 2016 - Scaling ARI and Production

Scaling is how we handle traffic to and from Asterisk via the ARI interface in a way

that we can support load

@dan_jenkins

Page 12: Astricon 2016 - Scaling ARI and Production

Production

@dan_jenkins

Page 13: Astricon 2016 - Scaling ARI and Production

How to architect your ARI app for running in

production, failing over, monitoring and reporting

@dan_jenkins

Page 14: Astricon 2016 - Scaling ARI and Production

Who knows of the ARI?

@dan_jenkins

Page 15: Astricon 2016 - Scaling ARI and Production

Who's built something with the ARI?

@dan_jenkins

Page 16: Astricon 2016 - Scaling ARI and Production

Who's deployed an ARI app to production?

@dan_jenkins

Page 17: Astricon 2016 - Scaling ARI and Production

Lets deconstruct how things work with the other Asterisk interfaces...

@dan_jenkins

Page 18: Astricon 2016 - Scaling ARI and Production

Built in Dialplan Applications

app_queue app_dial

app_*

@dan_jenkins

Page 19: Astricon 2016 - Scaling ARI and Production

Built in, no thought needed. Contributors have sorted

everything...right?

@dan_jenkins

Page 20: Astricon 2016 - Scaling ARI and Production

AMIAsterisk Manager Interface

@dan_jenkins

Page 21: Astricon 2016 - Scaling ARI and Production

TCP connection to Asterisk

@dan_jenkins

Page 22: Astricon 2016 - Scaling ARI and Production

Build something to scale AMI yourself

@dan_jenkins

Page 23: Astricon 2016 - Scaling ARI and Production

Asterisk

@dan_jenkins

Page 24: Astricon 2016 - Scaling ARI and Production

Asterisk

@dan_jenkins

Page 25: Astricon 2016 - Scaling ARI and Production

AMI Proxy

https://github.com/davetroy/astmanproxy

@dan_jenkins

Page 26: Astricon 2016 - Scaling ARI and Production

AstMan Proxy

Asterisk Asterisk Asterisk

@dan_jenkins

Page 27: Astricon 2016 - Scaling ARI and Production

(Fast)AGI

Asterisk Gateway Interface

@dan_jenkins

Page 28: Astricon 2016 - Scaling ARI and Production

AGI adds processes to our Asterisk

instance

Making our Asterisk instance busier

@dan_jenkins

Page 29: Astricon 2016 - Scaling ARI and Production

Asterisk Asterisk Asterisk

@dan_jenkins

Page 30: Astricon 2016 - Scaling ARI and Production

FastAGI allowed a TCP call out to something,

somewhere else

@dan_jenkins

Page 31: Astricon 2016 - Scaling ARI and Production

You can load balance these calls out using a

TCP Proxy

@dan_jenkins

Page 32: Astricon 2016 - Scaling ARI and Production

TCP Load Balancer

Asterisk Asterisk Asterisk

@dan_jenkins

Page 33: Astricon 2016 - Scaling ARI and Production

But there are reasons I love the ARI compared to AMI and AGI

@dan_jenkins

Page 34: Astricon 2016 - Scaling ARI and Production

It does greatthings with minimal

fuss and issue@dan_jenkins

Page 35: Astricon 2016 - Scaling ARI and Production

It does things "the Web" way

@dan_jenkins

Page 36: Astricon 2016 - Scaling ARI and Production

Thank you Asterisk Team!

@dan_jenkins

Page 37: Astricon 2016 - Scaling ARI and Production

Before we look at how to scale the ARI, we need to understand

what it is

@dan_jenkins

Page 38: Astricon 2016 - Scaling ARI and Production

What makes up the ARI?

@dan_jenkins

Page 39: Astricon 2016 - Scaling ARI and Production

Dialplan

Its beautiful isn't it? 4 lines. That's it!

(It would be better without the Dialplan)

[Astricon] exten = 100,1,Verbose(1, "Astricon call, woot") same = n,Stasis(dangerous-demos) same = n,Hangup()

@dan_jenkins

Page 40: Astricon 2016 - Scaling ARI and Production

HTTP Interface and a Websocket for Events

@dan_jenkins

Page 41: Astricon 2016 - Scaling ARI and Production

HTTP

curl -v -u asterisk:asterisk -X POST "http://localhost:8088/ari/channels/1400609726.3/

play?media=sound:hello-world"

@dan_jenkins

Page 42: Astricon 2016 - Scaling ARI and Production

Websocket{ "application":"hello-world", "type":"StasisStart", "timestamp":"2014-05-20T13:15:27.131-0500", "args":[], "channel":{ "id":"1400609726.3", "state":"Up", "name":"PJSIP/1000-00000001", "caller":{ "name":"", "number":""}, "connected":{ "name":"", "number":""}, "accountcode":"", "dialplan":{ "context":"default", "exten":"1000", "priority":3}, "creationtime":"2014-05-20T13:15:26.628-0500"} }

@dan_jenkins

Page 43: Astricon 2016 - Scaling ARI and Production

Call sessions from Asterisk are tied to a Websocket session

@dan_jenkins

Page 44: Astricon 2016 - Scaling ARI and Production

Writing your ARI app for Production

@dan_jenkins

Page 45: Astricon 2016 - Scaling ARI and Production

With Dialplan Applications we don't

need to care about latency or load

@dan_jenkins

Page 46: Astricon 2016 - Scaling ARI and Production

If Asterisk couldn't cope, then you've got bigger

issues.

@dan_jenkins

Page 47: Astricon 2016 - Scaling ARI and Production

In attempt to fix that, you'd put Asterisk on a bigger

box

@dan_jenkins

Page 48: Astricon 2016 - Scaling ARI and Production

Or spin up another and put it behind a SIP proxy or

something

@dan_jenkins

Page 49: Astricon 2016 - Scaling ARI and Production

Its kinda an already solved problem

@dan_jenkins

Page 50: Astricon 2016 - Scaling ARI and Production

But writing external applications to Asterisk is

a different ball game.

@dan_jenkins

Page 51: Astricon 2016 - Scaling ARI and Production

More moving parts.

@dan_jenkins

Page 52: Astricon 2016 - Scaling ARI and Production

More connected services.

@dan_jenkins

Page 53: Astricon 2016 - Scaling ARI and Production

More to monitor.

@dan_jenkins

Page 54: Astricon 2016 - Scaling ARI and Production

VoIP infrastructure grows into a Service Oriented

Architecture

@dan_jenkins

Page 55: Astricon 2016 - Scaling ARI and Production

Where Asterisk is just a small part of it.

@dan_jenkins

Page 56: Astricon 2016 - Scaling ARI and Production

So what do we need to care about when building

& deploying your ARI app?

@dan_jenkins

Page 57: Astricon 2016 - Scaling ARI and Production

Latency

@dan_jenkins

Page 58: Astricon 2016 - Scaling ARI and Production

Don't put your ARI app too far away

@dan_jenkins

Page 59: Astricon 2016 - Scaling ARI and Production

Its not like a normal API being consumed.

@dan_jenkins

Page 60: Astricon 2016 - Scaling ARI and Production

Making decisions and informing Asterisk of them shouldn't be hundreds of

milliseconds away

@dan_jenkins

Page 61: Astricon 2016 - Scaling ARI and Production

Make your app do your thing

@dan_jenkins

Page 62: Astricon 2016 - Scaling ARI and Production

Conference engine with your feature set

@dan_jenkins

Page 63: Astricon 2016 - Scaling ARI and Production

Outbound Dialer via your Customer API/

CRM

@dan_jenkins

Page 64: Astricon 2016 - Scaling ARI and Production

Your specific idea.

@dan_jenkins

Page 65: Astricon 2016 - Scaling ARI and Production

Your specific issue.

@dan_jenkins

Page 66: Astricon 2016 - Scaling ARI and Production

Don't aim to replace app_dial / app_queue /

app_voicemail / *

@dan_jenkins

Page 67: Astricon 2016 - Scaling ARI and Production

Do your thang!

@dan_jenkins

Page 68: Astricon 2016 - Scaling ARI and Production

Logging

@dan_jenkins

Page 69: Astricon 2016 - Scaling ARI and Production

Log out data that is useful.

@dan_jenkins

Page 70: Astricon 2016 - Scaling ARI and Production

Pipe that data to a centralised place

The ELK Stack for example

(Elasticserch | Logstash | Kibana)

@dan_jenkins

Page 71: Astricon 2016 - Scaling ARI and Production

Think of future you reading the logs.

Are they useful?

@dan_jenkins

Page 72: Astricon 2016 - Scaling ARI and Production

Metrics

@dan_jenkins

Page 73: Astricon 2016 - Scaling ARI and Production

Send stats out of your application

StatsD - data points specific to your application

@dan_jenkins

Page 74: Astricon 2016 - Scaling ARI and Production

And then graph and utilise them

(Telegraf | InfluxDB | Grafana)

@dan_jenkins

Page 75: Astricon 2016 - Scaling ARI and Production

Inter process communication

@dan_jenkins

Page 76: Astricon 2016 - Scaling ARI and Production

Does your app need to talk to other apps serving the

same ARI app name?

@dan_jenkins

Page 77: Astricon 2016 - Scaling ARI and Production

Got a call on another Asterisk/ARI app and need

to terminate it?

@dan_jenkins

Page 78: Astricon 2016 - Scaling ARI and Production

How do you tell that other App to terminate the call?

@dan_jenkins

Page 79: Astricon 2016 - Scaling ARI and Production

Scaling

@dan_jenkins

Page 80: Astricon 2016 - Scaling ARI and Production

Lets take a step away from Asterisk

@dan_jenkins

Page 81: Astricon 2016 - Scaling ARI and Production

Deploying and scaling a HTTP Service in

Production

@dan_jenkins

Page 82: Astricon 2016 - Scaling ARI and Production

HTTP Proxy/Load Balancer

HTTP Service

HTTP Service

HTTP Service

@dan_jenkins

Page 83: Astricon 2016 - Scaling ARI and Production

Deploying a service that communicates

with an API

@dan_jenkins

Page 84: Astricon 2016 - Scaling ARI and Production

Consuming HTTP Based API

@dan_jenkins

Page 85: Astricon 2016 - Scaling ARI and Production

HTTP Proxy/Load Balancer

External API

External API

External API

@dan_jenkins

Page 86: Astricon 2016 - Scaling ARI and Production

Consuming Websocket Event API

@dan_jenkins

Page 87: Astricon 2016 - Scaling ARI and Production

HTTP/TCP Proxy/Load Balancer

External API

External API

External API

@dan_jenkins

Page 88: Astricon 2016 - Scaling ARI and Production

They all have a load balancer

@dan_jenkins

Page 89: Astricon 2016 - Scaling ARI and Production

If there is state involved then the application deals

with that

@dan_jenkins

Page 90: Astricon 2016 - Scaling ARI and Production

Back to Asterisk

@dan_jenkins

Page 91: Astricon 2016 - Scaling ARI and Production

The ARI Websocket is tied to one or many

Stasis/ARI Apps

@dan_jenkins

Page 92: Astricon 2016 - Scaling ARI and Production

You can't have multiple Websockets tied to one Asterisk using the same

App name

@dan_jenkins

Page 93: Astricon 2016 - Scaling ARI and Production

Asterisk

Stasis App Name "hello-world"

@dan_jenkins

Page 94: Astricon 2016 - Scaling ARI and Production

Asterisk

Stasis App Name "hello-world"

@dan_jenkins

Page 95: Astricon 2016 - Scaling ARI and Production

Each Asterisk can only handle 1

Websocket per App Name

@dan_jenkins

Page 96: Astricon 2016 - Scaling ARI and Production

You can have one web socket handle

multiple app names

@dan_jenkins

Page 97: Astricon 2016 - Scaling ARI and Production

For example, a conferencing ARI App

@dan_jenkins

Page 98: Astricon 2016 - Scaling ARI and Production

Simple 1 Asterisk and 1 ARI App

@dan_jenkins

Page 99: Astricon 2016 - Scaling ARI and Production

Asterisk

Stasis App Name "conferencing"

@dan_jenkins

Page 100: Astricon 2016 - Scaling ARI and Production

Pros and Cons

Pros Cons

• Simple • Doesn't scale• You lose all your calls when

your app fails

@dan_jenkins

Page 101: Astricon 2016 - Scaling ARI and Production

Not so simple 2 Asterisk and 1 ARI App

@dan_jenkins

Page 102: Astricon 2016 - Scaling ARI and Production

AsteriskAsterisk

Stasis App Name "conferencing"

@dan_jenkins

Page 103: Astricon 2016 - Scaling ARI and Production

Pros and Cons

Pros Cons

• Can potentially handle more calls than a single Asterisk

• Doesn't scale• You lose all your calls when

your app fails• There will eventually be a

bottleneck in your application

@dan_jenkins

Page 104: Astricon 2016 - Scaling ARI and Production

ComplexMultiple Asterisk &

Multiple Process (1:1)

@dan_jenkins

Page 105: Astricon 2016 - Scaling ARI and Production

AsteriskAsteriskAsteriskAsterisk

Stasis App Name "conferencing"

@dan_jenkins

Page 106: Astricon 2016 - Scaling ARI and Production

Pros and Cons

Pros Cons

• Fairly simple • You lose all calls on that Asterisk when your app fails

• Nightmare configuring it• Not flexible

@dan_jenkins

Page 107: Astricon 2016 - Scaling ARI and Production

Really Complex1 Asterisk & Multiple Processes(through some dial plan magic)

@dan_jenkins

Page 108: Astricon 2016 - Scaling ARI and Production

Asterisk

Stasis App Names

"conferencingA" "conferencingB" "conferencingC" "conferencingD"

@dan_jenkins

Page 109: Astricon 2016 - Scaling ARI and Production

Pros and Cons

Pros Cons

• There are none • Complicated to maintain in your Dialpan

• If Asterisk dies, you lose all your calls

@dan_jenkins

Page 110: Astricon 2016 - Scaling ARI and Production

Add in Automated infrastructure and you've got a mess

@dan_jenkins

Page 111: Astricon 2016 - Scaling ARI and Production

AsteriskAsteriskAsteriskAsterisk

Stasis App Names

"conferencingA" ...

"conferencingZ"

Asterisk

@dan_jenkins

Page 112: Astricon 2016 - Scaling ARI and Production

AsteriskAsteriskAsteriskAsterisk

Stasis App Names

"conferencingA" ...

"conferencingZ"

Asterisk

@dan_jenkins

Page 113: Astricon 2016 - Scaling ARI and Production

Pros and Cons

Pros Cons

• There are none • Complicated to maintain in your Dialpan

• If Asterisk dies, you lose all your calls

• A huge mess

@dan_jenkins

Page 114: Astricon 2016 - Scaling ARI and Production

So how do we scale?

@dan_jenkins

Page 115: Astricon 2016 - Scaling ARI and Production

So how do we scale easily?

@dan_jenkins

Page 116: Astricon 2016 - Scaling ARI and Production

Quite simply, today, there is only one way.

@dan_jenkins

Page 117: Astricon 2016 - Scaling ARI and Production

ARI Proxy & Message Bus

@dan_jenkins

Page 118: Astricon 2016 - Scaling ARI and Production

2 ARI Proxies Available

Both support the same Message Bus Message format (https://github.com/nvisibleinc/go-ari-library/wiki/Message-Format)

@dan_jenkins

Page 119: Astricon 2016 - Scaling ARI and Production

Message Bus

RabbitMQ

NATS (Go Proxy only)

@dan_jenkins

Page 120: Astricon 2016 - Scaling ARI and Production

AsteriskAsteriskAsteriskAsterisk

Stasis App Name "conferencing"Message Bus

Proxy Proxy Proxy Proxy

*n

*n

@dan_jenkins

Page 121: Astricon 2016 - Scaling ARI and Production

Libraries that support it

Go

.Net

Soon Node.js

@dan_jenkins

Page 122: Astricon 2016 - Scaling ARI and Production

Libraries that support itGo

.Net

Soon Node.js

What library do you use? PHPARI? ari4java?

@dan_jenkins

Page 123: Astricon 2016 - Scaling ARI and Production

We need better library support

@dan_jenkins

Page 124: Astricon 2016 - Scaling ARI and Production

None of this is perfect

@dan_jenkins

Page 125: Astricon 2016 - Scaling ARI and Production

I wish Asterisk gave us a way of easily scaling with ARI

@dan_jenkins

Page 126: Astricon 2016 - Scaling ARI and Production

We talked about it at AstriDevCon this year

@dan_jenkins

Page 127: Astricon 2016 - Scaling ARI and Production

Should Asterisk do this or should an external

Proxy do it?

@dan_jenkins

Page 128: Astricon 2016 - Scaling ARI and Production

I'm not sure.

(And I was the one who brought it up)

@dan_jenkins

Page 129: Astricon 2016 - Scaling ARI and Production

Building with ARI is more complicated

than "Using Asterisk"@dan_jenkins

Page 130: Astricon 2016 - Scaling ARI and Production

But that's no different to learning how to ride your bikewithout stabilisers

@dan_jenkins

Page 131: Astricon 2016 - Scaling ARI and Production

And you don't ride your bike with stabilisers any more do you?

@dan_jenkins

Page 132: Astricon 2016 - Scaling ARI and Production

Its time to get on the bike and start peddling

@dan_jenkins

Page 133: Astricon 2016 - Scaling ARI and Production

And hope you don't fall off

@dan_jenkins

Page 134: Astricon 2016 - Scaling ARI and Production

But if you do, just get back up and try again

@dan_jenkins

Page 135: Astricon 2016 - Scaling ARI and Production

Thanks!

@dan_jenkins

[email protected]

Page 136: Astricon 2016 - Scaling ARI and Production

Come see Dangerous Demos Later!

Page 137: Astricon 2016 - Scaling ARI and Production

https://upload.wikimedia.org/wikipedia/commons/2/21/250_365_-_Bricks_(4247555680).jpg

https://www.flickr.com/photos/clement127/ (Huge thank you to clement127 for all their pictures over the years)

https://en.wikipedia.org/wiki/Lego#/media/File:LEGO_Building_At_KSC.jpg

https://www.flickr.com/photos/kalexanderson/8145886918

https://c2.staticflickr.com/8/7482/15936739285_460b008ec5_b.jpg

https://www.flickr.com/photos/arul72/23816127556

https://www.flickr.com/photos/kalexanderson/6101914287