Slide 1

Slide 1 text

Escalando sua aplicação para milhões de visitas.

Slide 2

Slide 2 text

Who am I? ● Software Developer ● Product Owner ● Leroy Merlin (Laravel) ● Keep learning http://zizaco.net Luiz Fernando / Zizaco

Slide 3

Slide 3 text

"Investing in scaling before it is needed is generally not a smart business proposition; however, some forethought into the design can save substantial time and resources in the future." - Kate Matsudaira

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Medição 1.

Slide 11

Slide 11 text

Medição

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Teste de carga smartmeter.io

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Cache 2.

Slide 18

Slide 18 text

O que é Cache? Guardar algo temporáriamente para uso posterior.

Slide 19

Slide 19 text

Por que usar Cache? Encurtar o tempo de acesso, reduzir a latência e melhorar o input/output. Caching é usado para melhorar a performance de uma aplicação.

Slide 20

Slide 20 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services View

Slide 21

Slide 21 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View

Slide 22

Slide 22 text

APC & Zend OpCache (OpCode Cache)

Slide 23

Slide 23 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache

Slide 24

Slide 24 text

Laravel's Route Caching "Using the route cache will drastically decrease the amount of time it takes to register all of your application's routes. In some cases, your route registration may even be up to 100x faster" php artisan route:cache

Slide 25

Slide 25 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache Cache

Slide 26

Slide 26 text

Caching Middleware (actionCaching) HTTP Kernel Middlewares Routes Controller Database View

Slide 27

Slide 27 text

Caching Middleware (actionCaching) HTTP Kernel Middlewares Routes Controller Database View HTTP Kernel Middlewares Routes Controller Database View

Slide 28

Slide 28 text

Caching Middleware (actionCaching) HTTP Kernel Middlewares Routes Controller Database View HTTP Kernel Middlewares Routes Controller Database View Hard work

Slide 29

Slide 29 text

Caching Middleware (actionCaching)

Slide 30

Slide 30 text

Caching Middleware (actionCaching)

Slide 31

Slide 31 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache Cache Cache

Slide 32

Slide 32 text

View Caching (fragment Caching) View Object View Object Render Render View Object Render ... @include @include

Slide 33

Slide 33 text

View Caching (fragment Caching) View Object View Object Render Render View Object Render ... @include @include View Object View Object Render Render View Object @cached_include @include Render ...

Slide 34

Slide 34 text

View Caching (fragment Caching) View Object View Object Render Render View Object Render ... @include @include View Object View Object Render Render View Object @include Render ... @cached_include

Slide 35

Slide 35 text

View Caching (fragment Caching)

Slide 36

Slide 36 text

View Caching (fragment Caching)

Slide 37

Slide 37 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache Cache Cache Cache

Slide 38

Slide 38 text

General Caching

Slide 39

Slide 39 text

General Caching

Slide 40

Slide 40 text

HTTP:// WebServer Cache Laravel Request Lifecycle HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache Cache Cache Cache

Slide 41

Slide 41 text

Internet Server(s) Application Database Reverse Proxy Internet Server(s) Proxy Application Database

Slide 42

Slide 42 text

Reverse Proxy "A reverse proxy can reduce load on its origin servers by caching content [...] also known as web acceleration. Proxy caches of this sort can often satisfy a considerable number of website requests, greatly reducing the load on the origin server(s)."

Slide 43

Slide 43 text

Reverse Proxy (ou CDN) Varnish Cache

Slide 44

Slide 44 text

HTTP:// WebServer Cache Laravel Request Lifecycle HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache View Cache Cache Cache Cache Cache

Slide 45

Slide 45 text

Standard HTTP Caching

Slide 46

Slide 46 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services View

Slide 47

Slide 47 text

Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload Routes Controller External Services File System Databases Models / Services Cache Cache Cache Cache View Cache Cache Cache

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Concorrência 3.

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

"Twelve-factor processes are stateless and share-nothing. Never assume that anything on disk or cached in memory will be available on a future request or job."

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Storing files (Object Storage / S3 / NAS)

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Storing logs (Monolog Handlers)

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Sticky sessions should never be used or relied upon. Session state data is a good candidate for a datastore that offers time-expiration, such as Memcached or Redis.

Slide 64

Slide 64 text

Centralizing sessions SESSION_DRIVER=redis

Slide 65

Slide 65 text

Store config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

"Build your application to be as generic and stateless as possible. If you must use a singleton, enable a voting protocol [...]" - Kyle Brown

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Preventing singleton

Slide 70

Slide 70 text

Preventing singleton

Slide 71

Slide 71 text

Preventing singleton

Slide 72

Slide 72 text

"Lock" distribuído "In computer science, a lock is a synchronization mechanism [...] A lock is designed to enforce a mutual exclusion concurrency control policy." - Wikipedia

Slide 73

Slide 73 text

"Lock" distribuído rápido, transacional e consistente

Slide 74

Slide 74 text

Preventing singleton

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

Topologia 4.

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

DevOps: Developers partner with system administrators and operations staff to assure that software runs with a minimum of problems. - Neil Garnichaud

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Uma tarde "boa" Uma semana

Slide 87

Slide 87 text

5410 requests / minuto ...

Slide 88

Slide 88 text

5410 requests / minuto 90 requests / segundo 324 mil req. / hora ...

Slide 89

Slide 89 text

5410 requests / minuto 90 requests / segundo 324 mil req. / hora 7.7 milhões req. / dia 233 milhões req. / mês

Slide 90

Slide 90 text

Indivíduos e interações 5.

Slide 91

Slide 91 text

Conway’s Law: The architecture of the system will reflect the organization that produced it. Parts of the organization that don’t talk together will likely produce software that doesn’t talk together.

Slide 92

Slide 92 text

Fontes Scalable Web Architecture and Distributed Systems - Kate Matsudaira http://www.aosabook.org/en/distsys.html Top 9 rules for cloud applications - Kyle Brown and Mike Capern http://www.ibm.com/developerworks/websphere/techjournal/1404_brown/1404_brown.html The Twelve Factors App - Adam Wiggins https://12factor.net/ 5 Common Server Setups For Your Web Application - Mitchell Anicas https://www.digitalocean.com/community/tutorials/5-common-server-setups-for-your-web-application Estratégias de Caching - Zizaco https://www.youtube.com/watch?v=z8qkUITz5rU Scaling Your Web App 101: Lessons in Architecture Under Load - Hartley Brody https://blog.hartleybrody.com/scale-load/ Distributed locks with Redis - Redis.io http://redis.io/topics/distlock What Exactly is DevOps? - Neil Garnichaud http://www.drdobbs.com/architecture-and-design/what-exactly-is-devops/240009147

Slide 93

Slide 93 text

Trabalhe conosco (: Back-end Front-end UX [email protected] assunto: [vaga]