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
"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 (: