Top Banner
Using Elixir to scale Video User Profile Service Emerson Macedo @emerleite
84

How Elixir helped us scale our Video User Profile Service for the Olympics

Feb 16, 2017

Download

Technology

Emerson Macedo
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: How Elixir helped us scale our Video User Profile Service for the Olympics

Using Elixir to scale Video User Profile

Service

Emerson Macedo @emerleite

Page 2: How Elixir helped us scale our Video User Profile Service for the Olympics
Page 3: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

User Profile API was developed in 2012.

It’s a well written Ruby on Rails

application , responsible for track

logged user actions

Page 4: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

User Profile API was developed in 2012.

It’s a well written Ruby on Rails

application , responsible for track

logged user actions

Page 5: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 seconds

Page 6: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 secondsx

x

Page 7: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Globo is making Binge Watching experiments combined

with Online First for new TV Shows

TV Shows

Page 8: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Prepare all Video Applications for the

Olympics

Page 9: How Elixir helped us scale our Video User Profile Service for the Olympics

Online First Binge Watching

Page 10: How Elixir helped us scale our Video User Profile Service for the Olympics

THE PROBLEM

2013

10k

The throughput increased

between 2013 and 2016

Page 11: How Elixir helped us scale our Video User Profile Service for the Olympics

2013 2016

10k

60kTHE PROBLEM

The throughput increased

between 2013 and 2016

Page 12: How Elixir helped us scale our Video User Profile Service for the Olympics

2013 2016

10k

60kTHE PROBLEM

The throughput increased

between 2013 and 2016 ~600%

Page 13: How Elixir helped us scale our Video User Profile Service for the Olympics

2013 2016

10k

60kTHE PROBLEM

It was hard to predict the new

Appication Throughput

2016 / 2

?

Page 14: How Elixir helped us scale our Video User Profile Service for the Olympics

INFRASTRUCTURE

2 bare metals, each one with 24 CPUs and 64GB of RAM

Page 15: How Elixir helped us scale our Video User Profile Service for the Olympics

THE PROBLEM

The average response time

was good, but percentiles were hurting the application

Avg

70ms

Page 16: How Elixir helped us scale our Video User Profile Service for the Olympics

70ms

THE PROBLEM

The average response time

was good, but percentiles were hurting the application

99

2.5s

95

1s

Avg

Page 17: How Elixir helped us scale our Video User Profile Service for the Olympics

FIRST CHANGE

We increased the computational resources

from 2 to 4 bare metals

Page 18: How Elixir helped us scale our Video User Profile Service for the Olympics

FIRST CHANGE

We increased the

computational resources

from 2 to 4 bare metals

Page 19: How Elixir helped us scale our Video User Profile Service for the Olympics

FIRST CHANGE

We increased the

computational resources

from 2 to 4 bare metals Each one with 24 CPUs and 64GB of RAM

Page 20: How Elixir helped us scale our Video User Profile Service for the Olympics

70ms

99

2.5s

95

1s

Avg

FIRST CHANGE

This change improved

metrics by ~32%

Page 21: How Elixir helped us scale our Video User Profile Service for the Olympics

FIRST CHANGE

This change improved

metrics by ~32%

9995

1.7s

0.7s

Avg

47ms

Page 22: How Elixir helped us scale our Video User Profile Service for the Olympics

FIRST CHANGE

This change improved

metrics by ~32%

9995

1.7s

0.7s

Avg

47ms

~32% better

Page 23: How Elixir helped us scale our Video User Profile Service for the Olympics

SECOND CHANGE

We decided to try a deployment with Tsuru containers with auto scaling, each one with 1-4 vCPU and 2GB of RAM

Page 24: How Elixir helped us scale our Video User Profile Service for the Olympics

SECOND CHANGE

We decided to try a deployment with Tsuru containers with auto scaling, each one with 1-4 vCPU and 2GB of RAM

93 containers

Page 25: How Elixir helped us scale our Video User Profile Service for the Olympics

SECOND CHANGE

9995

1.7s

0.7s

Avg

47ms

Migrate to containers improved

metrics by ~12%

Page 26: How Elixir helped us scale our Video User Profile Service for the Olympics

SECOND CHANGE

9995

1.5s

0.5s

Avg

41ms

Migrate to containers improved

metrics by ~12%

Page 27: How Elixir helped us scale our Video User Profile Service for the Olympics

SECOND CHANGE

9995

1.5s

0.5s

Avg

41ms

Migrate to containers improved

metrics by ~12%

~12% better

Page 28: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 seconds

Page 29: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 secondsx

x

Page 30: How Elixir helped us scale our Video User Profile Service for the Olympics

Online First Binge Watching

Page 31: How Elixir helped us scale our Video User Profile Service for the Olympics

ARCHITECTURAL OVERVIEW

User Profile API is a

classical Ruby on Rails

application, which also

uses Resque for

background jobs

Page 32: How Elixir helped us scale our Video User Profile Service for the Olympics

ARCHITECTURAL OVERVIEW

User Profile API is a

classical Ruby on Rails

application, which also

uses Resque for

background jobs

Page 33: How Elixir helped us scale our Video User Profile Service for the Olympics

ARCHITECTURAL OVERVIEW

User Profile API is a

classical Ruby on Rails

application, which also

uses Resque for

background jobs

BLOCK

BLOCK

BLOCK

Page 34: How Elixir helped us scale our Video User Profile Service for the Olympics

ARCHITECTURAL OVERVIEW

User Profile API is a

classical Ruby on Rails

application, which also

uses Resque for

background jobs

Page 35: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTAINER DISTRIBUTION

Our containers was distributed for the Rails App, Resque Workers and Resque Scheduler

93 containers

Page 36: How Elixir helped us scale our Video User Profile Service for the Olympics

30 containers63 containers

Page 37: How Elixir helped us scale our Video User Profile Service for the Olympics

30 containers63 containers

ResqueRails

Page 38: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We saw that just ONE

endpoint was responsible for

80%, of application

throughput

Page 39: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We saw that just ONE

endpoint was responsible for

80%, of application

throughput

Page 40: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

x

x

We saw that just ONE

endpoint was responsible for

80%, of application

throughput

Page 41: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 seconds

Page 42: How Elixir helped us scale our Video User Profile Service for the Olympics

CONTEXT

Our Video Player POST Watched

Percentage to our Endpoint so we can

provide Keep Watching Percentage

to our Logged Users. It does it

every 10 secondsx

x

Page 43: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We saw that just ONE endpoint was

responsible for 80%, of application throughput

Page 44: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We saw that just ONE endpoint was

responsible for 80%, of application throughput

Pareto

Page 45: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We saw that just ONE endpoint was responsible for 80%, of application throughput

Pareto

20% of effort will solve 80% of the problem

Page 46: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 47: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 48: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 49: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

Page 50: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

Page 51: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

x

Page 52: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

Page 53: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

x

Page 54: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

Page 55: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is being the

cutting-edge for the

Ruby community

x

Page 56: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is the language Java programmers were looking when they choose Ruby

Page 57: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir is the language Java programmers were looking when they choose Ruby

x

x

x

Page 58: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir generates Erlang byte code and runs

on BEAM VM which has 30 years of development

Page 59: How Elixir helped us scale our Video User Profile Service for the Olympics

WHY ELIXIR

Elixir generates Erlang byte code and runs

on BEAM VM which has 30 years of development

x

Page 60: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 61: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 62: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

Page 63: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

SAME APPLICATION

Page 64: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

We rewrote the Ruby POST

endpoint from scratch to an

Elixir version

SAME APPLICATION

ERL PROCESS

ERL PROCESS

Page 65: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

The result was a starting

point to change the app to

CQRS Architecture

Page 66: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

The result was a starting

point to change the app to

CQRS Architecture

COMMAND

QUERY

Page 67: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

9995

1.5s

0.5s

Avg

41ms

Migrate to Elixir improved

metrics by ~95%

Page 68: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

9995

30ms15ms

Avg

4ms

Migrate to Elixir improved

metrics by ~95%

Page 69: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

9995

30ms15ms

Avg

4ms

Migrate to Elixir improved

metrics by ~95%

~95% better

Page 70: How Elixir helped us scale our Video User Profile Service for the Olympics

30 containers63 containers

ResqueRails

Page 71: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

Migrate to Elixir reduced

containers by ~35%

3 containers30 containers

ElixirRuby

Page 72: How Elixir helped us scale our Video User Profile Service for the Olympics

THIRD CHANGE

Migrate to Elixir reduced

containers by ~35%

33 containers

Page 73: How Elixir helped us scale our Video User Profile Service for the Olympics

TOOLS

We chosse phoenix

framework to create

our Elixir API and

we’re using many other

community libs

Page 74: How Elixir helped us scale our Video User Profile Service for the Olympics

TOOLS

We chosse phoenix

framework to create

our Elixir API and

we’re using many other

community libs

Ecto HTTPoison

Exrm CacheX

GenRetry FakeServer

Corsica

Page 75: How Elixir helped us scale our Video User Profile Service for the Olympics

PROBLEMS

MongoDB Driver did not has

Replica Sets support. We had

to implement it

Page 76: How Elixir helped us scale our Video User Profile Service for the Olympics

PROBLEMS

MongoDB Driver did not has

Replica Sets support. We had

to implement it

http//github.com/emerleite/mongox

http//github.com/emerleite/mongox_ecto

Page 77: How Elixir helped us scale our Video User Profile Service for the Olympics

PROBLEMS

Elixir did not has NewRelic support.

We need to create an ad-hoc implementation using Exometer

Page 78: How Elixir helped us scale our Video User Profile Service for the Olympics

PROBLEMS

Elixir did not has NewRelic support.

We need to create an ad-hoc implementation using Exometer

https://github.com/Feuerlabs/exometer_core

Page 79: How Elixir helped us scale our Video User Profile Service for the Olympics

2013 2016

10k

60kFINAL RESULT

After the Olympics and with

Binge Watching, the

throughput increased ~50%

Page 80: How Elixir helped us scale our Video User Profile Service for the Olympics

2013 2016

10k

60kFINAL RESULT

After the Olympics and with

Binge Watching, the

throughput increased ~50%

2016 / 2

90k

Page 81: How Elixir helped us scale our Video User Profile Service for the Olympics

70ms

99

2.5s

95

1s

Avg

FINAL RESULT

Migrate to Elixir improved

metrics by ~95%

Page 82: How Elixir helped us scale our Video User Profile Service for the Olympics

FINAL RESULT

9995

30ms15ms

Avg

4ms

Migrate to Elixir improved

metrics by ~95%

Page 83: How Elixir helped us scale our Video User Profile Service for the Olympics

FINAL RESULT

9995

30ms15ms

Avg

4ms

Migrate to Elixir improved

metrics by ~95%

~95% better

Page 84: How Elixir helped us scale our Video User Profile Service for the Olympics

Perguntas?

Emerson Macedo@emerleite

https://blog.emerleite.com