Microservice, Microservice. Wherefore Art Thou, Microservice.
FreeSWITCH as a Microservice
-
Upload
evan-mcgee -
Category
Technology
-
view
555 -
download
11
Transcript of FreeSWITCH as a Microservice
![Page 1: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/1.jpg)
FreeSWITCH as a Microservice
vs.
![Page 2: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/2.jpg)
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.
![Page 3: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/3.jpg)
Quickly: What is a microservices architecture?
![Page 4: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/4.jpg)
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?
![Page 5: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/5.jpg)
That Brings Us To…
![Page 6: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/6.jpg)
Doesn’t Live in A Bubble
![Page 7: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/7.jpg)
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
![Page 8: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/8.jpg)
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
![Page 9: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/9.jpg)
How About Something More Fun
![Page 10: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/10.jpg)
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.
![Page 11: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/11.jpg)
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?
![Page 12: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/12.jpg)
This Sounds Complex. Can we make this easier?
Let’s Talk About One Way To Go
![Page 13: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/13.jpg)
• 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
![Page 14: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/14.jpg)
DOCKER NETWORKING….
IT’S GOTTEN BETTER!
![Page 15: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/15.jpg)
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
![Page 16: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/16.jpg)
Practical Use Case
![Page 17: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/17.jpg)
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.
![Page 18: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/18.jpg)
CPU BOUNDSave money on the weekends ya’ll!
![Page 19: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/19.jpg)
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
![Page 20: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/20.jpg)
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.
![Page 21: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/21.jpg)
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
![Page 22: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/22.jpg)
NO MAGIC PILL YET.
STILL REQUIRES DEV, OPS, DEVOPS, MANAGEMENT
COMPLEXITY
![Page 23: FreeSWITCH as a Microservice](https://reader033.fdocuments.us/reader033/viewer/2022050706/58a1c7f31a28ab9d338b5b3f/html5/thumbnails/23.jpg)
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?