Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Zizaco
October 08, 2016

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

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

Vídeo da Apresentação (2016/10/08): https://youtu.be/jPbghDn0HLE?t=335

Luiz Fernando / Zizaco

- Software Developer
- Product Owner
- Leroy Merlin (Laravel)
- Keep learning

http://zizaco.net

"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

1. Medição

Teste de carga
smartmeter.io

2. Cache

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

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.

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

autoload:

APC & Zend OpCache (OpCode Cache)
Até 3x mais rápido

Routes:

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
Até 3x mais rápido

- Middleware (action caching)
- View
- Model / Services:

Reverse Proxy:

Reverse Proxy (ou CDN)
"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)."

- Varnish Cache
- Akamai
- Nginx

Standard HTTP Caching:

3. Concorrência

The Twelve-Factor App: https://12factor.net/

The twelve-factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).

"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."

Storing files (Object Storage / S3 / NAS)
Storing logs (Monolog Handlers)

"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.""

Centralizing sessions

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

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

Preventing singleton

"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

Redis: rápido, transacional e consistente

4. Topologia

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

5. Indivíduos e interações

"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."

"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

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

Trabalhe conosco (:

Zizaco

October 08, 2016
Tweet

More Decks by Zizaco

Other Decks in Technology

Transcript

  1. Who am I? • Software Developer • Product Owner •

    Leroy Merlin (Laravel) • Keep learning http://zizaco.net Luiz Fernando / Zizaco
  2. "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
  3. 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.
  4. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

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

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

    Routes Controller External Services File System Databases Models / Services Cache View Cache
  7. 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
  8. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

    Routes Controller External Services File System Databases Models / Services Cache View Cache Cache
  9. Caching Middleware (actionCaching) HTTP Kernel Middlewares Routes Controller Database View

    HTTP Kernel Middlewares Routes Controller Database View Hard work
  10. 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
  11. 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 ...
  12. 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
  13. 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
  14. 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
  15. 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)."
  16. 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
  17. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

    Routes Controller External Services File System Databases Models / Services View
  18. 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
  19. "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."
  20. 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.
  21. Store config in environment variables (often shortened to env vars

    or env). Env vars are easy to change between deploys without changing any code
  22. "Build your application to be as generic and stateless as

    possible. If you must use a singleton, enable a voting protocol [...]" - Kyle Brown
  23. "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
  24. DevOps: Developers partner with system administrators and operations staff to

    assure that software runs with a minimum of problems. - Neil Garnichaud
  25. 5410 requests / minuto 90 requests / segundo 324 mil

    req. / hora 7.7 milhões req. / dia 233 milhões req. / mês
  26. 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.
  27. 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