freeswitch as a microservice

Post on 13-Apr-2017

569 Views

Category:

Technology

11 Downloads

Preview:

Click to see full reader

TRANSCRIPT

FreeSWITCH as a Microservice

vs.

What we are: an MVNO/MVNE running on the Sprint Network

What we do: rapid development cycles and constant iteration to be a different kind of consumer cellular company.

Quickly: What is a microservices architecture?

Quickly: What is a microservices architecture?

• Monolithic• Simpler architecture• Generally confined to a single language

or framework • Scaling Inefficient• Depth of Knowledge Required (DOKR)

can lead to substantially increased technical debt

• Microservices• More complex• Decoupled services allow for more rapid

development • Increased scalability and fault tolerance• Knowledge need not span multiple services • Deployment is more complex but… simpler?

That Brings Us To…

Doesn’t Live in A Bubble

Doesn’t Live in A Bubble• Billing • Fraud Management • Call Tracking & Analytics • Performance Monitoring • Call Quality Analysis • Failover • Realtime Multimodal Interaction (PSTN->WebRTC…)

Very different domains requiring very different processing backends, language requirements, and service architectures

Simple ExampleUser Registration: mod_xml_curl

• Queries a remote API for registration information • API uses business logic to decide which registrations

permissions to bestow

<binding name="directory"><param name="gateway-url" value="https://dev.ringplus.net/endpoints" bindings="directory"/><param name="gateway-credentials" value="journey:foreigner" /><param name="auth-scheme" value="basic"/>

</binding>

Works for dialplan, configuration, and phrases Decouples SIP endpoint information

Easy migration to a mid-registrar like Kamailio

Registration Microservice

DataStore

HTTP HTTP (XML)

??? ???

if create_sip_endpointrender :registration, status: :ok, formats: [:xml]

elserender xml: @sip_endpoint.errors, status: :unprocessable_entity

end

XML

RUBY

How About Something More Fun

Here’s a little something.Setting Preprocessor values: exec-set

<X-PRE-PROCESS cmd="exec-set" data="local_ip_v4 = ip addr show eth0 | awk '/inet /{print $2}' | head -n 1 | cut -d '/' -f 1"/>

Scenario: You’re starting a container and don’t know the IP

<X-PRE-PROCESS cmd="exec-set" data="internal_sip_port = echo $INTERNAL_SIP_PORT"/>

Scenario: You’re big into 12-Factor and are using lots of ENV variables

<X-PRE-PROCESS cmd="exec-set" data="rtp_start_port = /etc/freeswitch/rtp_ports_based_on_env

Scenario: It’s complicated, man. I need some real logic processing.

Go routine that queries a service to retrieve the public RTP ports for this container. That service also opens/maps firewall and NAT ports correctly, or can really do anything.

Talking To FreeSWITCH Is Easy

Many choices of built-in modules and 3rd party libraries

• Ruby: Adhearsion (https://github.com/adhearsion/adhearsion) • JavaScript: https://github.com/shimaore/esl • Go: https://github.com/0x19/goesl • Python: Python ESL • mod_xml_rpc • mod_verto • etc…

What About Push?

This Sounds Complex. Can we make this easier?

Let’s Talk About One Way To Go

• You may have heard me talk about this last year. I’m still talking about it.• Containers should be single-process, no durable storage, ephemeral little

creatures• Lightweight and distributable containers• Scalability due to built in resilience and orchestration layers• Higher packing density than virtual machines due to shared libs

Docker

DOCKER NETWORKING….

IT’S GOTTEN BETTER!

Docker Networking

• Docker 1.12 (June) allows for easy, multi-host VXLAN routing• Easily scale containers across nodes • Built in state reconciliation for resilient deployments• Orchestration is built into Docker Engine

• Includes auto-load balancing of inbound requests to multiple containers utilizing in-kernel Linux IPVS, automatic TLS generation, and a free basket of kittens

Note: Docker is still a moving target.

• Documentation• Best Practices• Service Integration/Discovery

Practical Use Case

Scaling The Business LogicUsing Adhearsion for your dialplan.

- We use it for ease and rapidity of development - Can leverage the Ruby ecosystem for gems

Problem: Ruby MRI is locked to a single CPU, so can become CPU bound Solution: JRuby(?)

Problem Redux: Call volume on a particular node is exceeding CPU capacity due to amazingly wonderful consumer adoption (Pokémon Go Syndrome) Solution: Scale nodes

• FreeSWITCH is rarely the blocker but can consume enough CPU to max out • Adhearsion communicates with mod_rayo via XMPP - many clients, one server.

CPU BOUNDSave money on the weekends ya’ll!

Scaling The Business LogicUsing Adhearsion for your dialplan.

- We use it for ease and rapidity of development - Can leverage the Ruby ecosystem for gems

Problem: Ruby MRI is locked to a single CPU, so can become CPU bound Solution: JRuby

Problem Redux: Call volume on a particular node is exceeding CPU capacity due to amazingly wonderful consumer adoption (Pokémon Go Syndrome) Solution: Scale nodes

• FreeSWITCH is rarely the blocker but can consume enough CPU to max out • Adhearsion communicates with mod_rayo via XMPP - many clients, one server.

root@adhearsion-swarm-01:~# docker service lsID            NAME   REPLICAS  IMAGE                      COMMANDec23ck911hgc  adhearsion    20/20   ringplus/adhearsion:latest28ght39gvfce  freeswitch   1/1       ringplus/freeswitch_v1.6:latest

root@adhearsion-swarm-01:~# docker service scale adhearsion=20adhesion scaled to 20

FreeSWITCH

Adhearsion

NYC Datacenter

Adhearsion + FreeSWITCH

Spike Condition with DockerAdhearsion

DigitalOcean NYC-1

NYC Datacenter

Kamailio

• Host monitoring detects low-CPU condition on Node 1 • collectd container • Active call monitoring

• Calls Ansible to spin up a new DO container • Adhearsion images pulled from Docker repo • Start containers with overlay network and information on parent

FS container

• Quiesce Adhearsion on affected system • Gracefully shutdown

• Update Kamailio MySQL DB with new dispatcher information if FreeSWITCH scaling is necessary.

FreeSWITCH Joins A Bunch of Microservices

FreeSWITCH

Static Assets Voicemails

IVR

AdhearsionKafkaELK

S3 / Gluster

Fraud API Kafka Consumer

Billing API

Redis

Logs WAL-E Backups

Postgres

HTTP/S, HTTPS, XMPP, XML, Go, Ruby, Elixer

RBT Selection API

User API

NO MAGIC PILL YET.

STILL REQUIRES DEV, OPS, DEVOPS, MANAGEMENT

COMPLEXITY

Finals Thoughts & Bon Mots

• If you can help it, don’t start with microservices unless you have a team willing and able. • Do build your monolithic app with an eye toward breaking it apart.

• Consider that you’ll eventually need to scale one part, but not others.• Follow a Services or Operations pattern to development - make them as independent

as possible to facilitate eventual decoupling.

• Do think of your FreeSWITCH and VoIP infrastructure as smaller services.• Consider your business case: Instead of running one 10k channel FreeSWITCH, why not

run 100 100-channel FreeSWITCH instances?

Evan McGee

@startledmarmot

evan@ringplus.net

top related