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

799efab30a6db8436e6941dfd372c66f?s=47 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 (:

799efab30a6db8436e6941dfd372c66f?s=128

Zizaco

October 08, 2016
Tweet

Transcript

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

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

    Leroy Merlin (Laravel) • Keep learning http://zizaco.net Luiz Fernando / Zizaco
  3. "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
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. Medição 1.

  11. Medição

  12. None
  13. Teste de carga smartmeter.io

  14. None
  15. None
  16. None
  17. Cache 2.

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

  19. 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.
  20. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

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

    Routes Controller External Services File System Databases Models / Services Cache View
  22. APC & Zend OpCache (OpCode Cache)

  23. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

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

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

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

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

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

  30. Caching Middleware (actionCaching)

  31. 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
  32. View Caching (fragment Caching) View Object View Object Render Render

    View Object Render ... @include @include
  33. 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 ...
  34. 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
  35. View Caching (fragment Caching)

  36. View Caching (fragment Caching)

  37. 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
  38. General Caching

  39. General Caching

  40. 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
  41. Internet Server(s) Application Database Reverse Proxy Internet Server(s) Proxy Application

    Database
  42. 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)."
  43. Reverse Proxy (ou CDN) Varnish Cache

  44. 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
  45. Standard HTTP Caching

  46. Laravel Request Lifecycle HTTP:// WebServer HTTP Kernel Middlewares index.php autoload

    Routes Controller External Services File System Databases Models / Services View
  47. 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
  48. None
  49. None
  50. None
  51. Concorrência 3.

  52. None
  53. None
  54. None
  55. None
  56. "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."
  57. None
  58. Storing files (Object Storage / S3 / NAS)

  59. None
  60. Storing logs (Monolog Handlers)

  61. None
  62. None
  63. 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.
  64. Centralizing sessions SESSION_DRIVER=redis

  65. Store config in environment variables (often shortened to env vars

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

    possible. If you must use a singleton, enable a voting protocol [...]" - Kyle Brown
  68. None
  69. Preventing singleton

  70. Preventing singleton

  71. Preventing singleton

  72. "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
  73. "Lock" distribuído rápido, transacional e consistente

  74. Preventing singleton

  75. None
  76. None
  77. None
  78. Topologia 4.

  79. None
  80. None
  81. None
  82. None
  83. None
  84. DevOps: Developers partner with system administrators and operations staff to

    assure that software runs with a minimum of problems. - Neil Garnichaud
  85. None
  86. Uma tarde "boa" Uma semana

  87. 5410 requests / minuto ...

  88. 5410 requests / minuto 90 requests / segundo 324 mil

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

    req. / hora 7.7 milhões req. / dia 233 milhões req. / mês
  90. Indivíduos e interações 5.

  91. 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.
  92. 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
  93. Trabalhe conosco (: Back-end Front-end UX rscafi@leroymerlin.com.br assunto: [vaga]