67
Erlang e Elixir Por uma web mais feliz

Erlang e Elixir por uma web mais feliz

Embed Size (px)

Citation preview

Page 1: Erlang e Elixir por uma web mais feliz

Erlang e Elixir

Por uma web mais feliz

Page 2: Erlang e Elixir por uma web mais feliz

Bruno Henrique - Garu

Page 5: Erlang e Elixir por uma web mais feliz

Motivação

Page 6: Erlang e Elixir por uma web mais feliz

Necessidade de aprender coisas novas

Page 7: Erlang e Elixir por uma web mais feliz

Estudar o paradigma funcional

Page 8: Erlang e Elixir por uma web mais feliz

Criar um sistema Realtime para atender milhares de usuários

Page 9: Erlang e Elixir por uma web mais feliz

Mas, entre todas as linguagens funcionais,

porque Erlang?

Page 10: Erlang e Elixir por uma web mais feliz

Um pouco de história...

Page 11: Erlang e Elixir por uma web mais feliz

Por que uma nova linguagem?

Page 12: Erlang e Elixir por uma web mais feliz

Contexto no qual Erlang foi criada

Page 13: Erlang e Elixir por uma web mais feliz

Switch

Page 14: Erlang e Elixir por uma web mais feliz

Nenhuma linguagem atendia a todos os

requisitos ...

Page 15: Erlang e Elixir por uma web mais feliz

... alta concorrência

Page 16: Erlang e Elixir por uma web mais feliz

... tolerância a falhas

Page 17: Erlang e Elixir por uma web mais feliz

... alta disponibilidade

Page 18: Erlang e Elixir por uma web mais feliz

Isso nos anos 80 ...

Page 19: Erlang e Elixir por uma web mais feliz

... então por que usar agora?

Page 20: Erlang e Elixir por uma web mais feliz

Nosso contexto

Page 21: Erlang e Elixir por uma web mais feliz

Server

Page 22: Erlang e Elixir por uma web mais feliz

Fazendo a coisa certa em um contexto diferente.

Page 23: Erlang e Elixir por uma web mais feliz

Entendendo suas features na prática

Page 24: Erlang e Elixir por uma web mais feliz

Como atender uma grande quantidade

usuários ?

Page 25: Erlang e Elixir por uma web mais feliz

Podemos escalar na horizontal ?

Page 26: Erlang e Elixir por uma web mais feliz

Podemos ...

Page 27: Erlang e Elixir por uma web mais feliz

... mas existe um limite tanto físico quanto

financeiro

Page 28: Erlang e Elixir por uma web mais feliz

Fazer isso nem sempre é uma coisa simples

Page 29: Erlang e Elixir por uma web mais feliz

Load balanceetc.

cacheSlave

MasterProxy

Page 30: Erlang e Elixir por uma web mais feliz

E dependendo da tecnologia escolhida

pode haver desperdício.

Page 31: Erlang e Elixir por uma web mais feliz

Exemplo

Page 33: Erlang e Elixir por uma web mais feliz

Erlang - Distributed

Page 35: Erlang e Elixir por uma web mais feliz

Como manter um número elevado de usuários

simultâneos?

Page 36: Erlang e Elixir por uma web mais feliz

Agora começa a concorrência.

Page 37: Erlang e Elixir por uma web mais feliz

Mas o que é concorrência?

Page 38: Erlang e Elixir por uma web mais feliz

Two queues and one coffee machine.

Joe Armstronghttp://joearms.github.io/2013/04/05/concurrent-and-parallel-programming.html

Page 39: Erlang e Elixir por uma web mais feliz

Ruby, Python, Java, PHP, C# - O que elas possuem

em comum?

Page 40: Erlang e Elixir por uma web mais feliz

Orientação a Objeto

Page 41: Erlang e Elixir por uma web mais feliz

E um forte conceito de estado mutável.

Page 42: Erlang e Elixir por uma web mais feliz

Estado e concorrência não funcionam muito bem

juntos.

Page 43: Erlang e Elixir por uma web mais feliz

Como lidamos com concorrência?

Page 44: Erlang e Elixir por uma web mais feliz

Podemos usar threads

Page 45: Erlang e Elixir por uma web mais feliz

O que é uma thread?

Page 46: Erlang e Elixir por uma web mais feliz

Temos algum problema com thread?

Page 47: Erlang e Elixir por uma web mais feliz

Sim, estado compartilhado é um

grande problema.

Page 48: Erlang e Elixir por uma web mais feliz

Soluções?

Page 49: Erlang e Elixir por uma web mais feliz

locks

Page 50: Erlang e Elixir por uma web mais feliz

transactional memory

Page 51: Erlang e Elixir por uma web mais feliz

message-passing

Page 52: Erlang e Elixir por uma web mais feliz

E é assim que Erlang funciona.

Page 53: Erlang e Elixir por uma web mais feliz

Quando não temos estado compartilhado fica mais

fácil

Page 54: Erlang e Elixir por uma web mais feliz

Exemplo

Page 56: Erlang e Elixir por uma web mais feliz

Elixir

Page 57: Erlang e Elixir por uma web mais feliz

O poder da Erlang VM com uma bela sintaxe.

Page 58: Erlang e Elixir por uma web mais feliz

Sintaxe

Page 59: Erlang e Elixir por uma web mais feliz

Erlang

https://speakerdeck.com/plataformatec/elixir

Page 60: Erlang e Elixir por uma web mais feliz

Elixir

https://speakerdeck.com/plataformatec/elixir

Page 61: Erlang e Elixir por uma web mais feliz

Protocol

Page 63: Erlang e Elixir por uma web mais feliz

Macros

Page 65: Erlang e Elixir por uma web mais feliz

Referências

Asynchronous to Real-time Web Programming - http://www.infoq.com/presentations/Asynchronous-Web-Programming

Erlang - software for a concurrent world - http://www.infoq.com/presentations/erlang-software-for-a-concurrent-world

A True Conversational Web - http://www.infoq.com/presentations/A-True-Conversational-Web

1000 Year-old Design Patterns - http://www.infoq.com/presentations/1000-Year-old-Design-Patterns

Erlang, the Language from the Future? - http://www.infoq.com/presentations/Erlang-Pros-Cons

Elixir: Modern Programming for the Erlang VM - http://www.infoq.com/presentations/Elixir-Erlang-VM

Let It Crash ... Except When You Shouldn't - http://www.infoq.com/presentations/Let-It-Crash

Message Passing Concurrency in Erlang - http://www.infoq.com/presentations/Message-Passing-Concurrency

Page 66: Erlang e Elixir por uma web mais feliz

Referências

Death by Accidental Complexity - http://www.infoq.com/presentations/Death-by-Accidental-Complexity

Systems that Never Stop (and Erlang) - http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong

Multicore Programming in Erlang - http://www.infoq.com/presentations/wiger-multicore-erlang

Concurrency: Past and Present - http://www.infoq.com/presentations/goetz-concurrency-past-present

Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages - http://pragprog.com/book/btlang/seven-languages-in-seven-weeks

Programming Erlang: Software for a Concurrent World - http://pragprog.com/book/jaerlang/programming-erlang

Elixir language - http://elixir-lang.org/getting_started/1.html

Page 67: Erlang e Elixir por uma web mais feliz

[email protected]/brunohenrique

@GaruHenr

Obrigado!