SlideShare une entreprise Scribd logo
1  sur  40
Delivery high performance
applications with Efficient
Cache Layer
Bruno Paiuca => ‘KaBuM! SA’
Twitter =>
‘https://twitter.com/BPaiuca’
whoami
> whoami
Bruno Paiuca, 28 anos, Palmeirense, Sysadmin coder.
Redes de computadores - FIAP
MBA Sistemas corporativos de alto desempenho - FIAP
Certificações:
- LPI
- CCNA
- RHCE
- AWS Solution Architect Associate
Tecnologias:
- Linux
- NGINX
- Perl
- Python
- SaltStack
- Docker
- AWS
- redis
- terraform
Twitter => https://twitter.com/BPaiuca
LinkedIn => https://www.linkedin.com/in/brunopaiuca/
sumário
Por que? Como?
- expectativa do usuário
- baixíssima latência
- altamente escaláveis
- altamente disponiveis
- redução de custos
por que?
study done by Amazon almost 10 years
ago proved that, even then, a
100-millisecond decrease in page-loading
time translated to a 1% increase in its
revenue.
According to surveys done by Akamai and
Gomez.com, nearly half of web users
expect a site to load in 2 seconds or less,
and they tend to abandon a site that isn’t
loaded within 3 seconds. 79% of web
shoppers who have trouble with web site
performance say they won’t return to the
site to buy again and around 44% of
them would tell a friend if they had a poor
experience shopping online.
Como?
NGINX
Web Server Load Balancer
NGINX
High Availability Content Cache
NGINX+
Kubernetes
Ingress
Controller
Programmability
MonitoringSecurity Control
NGINX CACHE
NGINX CACHE
How long?
What is your app? Pattern?
- Monolithic - REST
- Microservice - SOAP
NGINX CACHE
Advantages
- Reduce Server load - Better user experience
- Delivery more with less resources
proxy_cache_path
proxy_cache_path path [levels=levels] [use_temp_path=on|off]
keys_zone=name:size [inactive=time] [max_size=size]
Determina o diretório de armazenamento, level de subdiretórios,
size e nome da key_zone.
E.g. proxy_cache_path /dev/shm/nginx levels=1:2 use_temp_path=on
keys_zone=APPCACHE:1m inactive=300s max_size=1m;
proxy_cache_key
Syntax: Proxy_cache_key string;
Default: proxy_cache_key $scheme$proxy_host$request_uri;
Determina a key para armazenamento e busca de Match nos
objetos do Cache.
proxy_cache_key $scheme$proxy_host$uri$cookie_userid;
proxy_cache
Syntax: proxy_cache [cache zone];
Define em qual Cached Zone o objeto será buscado ou
armazenado.
proxy_cache APPCACHE;
proxy_cache_valid
Syntax: Proxy_cache_valid [http code] time;
Define a condição para um cache ser armazenado na cached
zone e o tempo em que o objeto será considerado Fresh.
proxy_cache_valid 200 301 302 304 1h;
proxy_cache_valid 404 1m;
proxy_cache_valid any 30s;
proxy_cache_lock
Syntax: proxy_cache_lock [off|on];
Default: proxy_cache_lock off;
Configura para apenas 1 request simultanea seja autorizado a
popular um novo cache object , enviando para o Upstream server.
proxy_cache_lock on;
Proxy_cache_purge
Syntax: Proxy_cache_purge [$variable];
Define uma condição para que a request seja considerado uma Purge
Request. Essa requisição limpa o objeto da cached zone, baseado na
cache_key. O resultado é retornado como HTTP 204 (No Content).
Essa é uma feature comercial.
map $request_method $purge_method {
PURGE 1;
default 0;
}
server {
proxy_cache_lock $purge_method;
}
Proxy_cache_bypass
Syntax: Proxy_cache_bypass [$variable];
Define uma condição para que a request ignore os objetos do
Cache Zone e a request seja enviada para o Upstream. O retorno
atualiza o objeto já armazenado na Cache Zone.
proxy_cache_lock $arg_skipcache;
Proxy_cache_use_stale
Syntax: Proxy_cache_use_stale [$variable];
Define casos em que uma STALE Cached response pode ser
utilizada.
E.g. proxy_cache_use_stale error timeout invalid_header http_500
http_502 http_503 http_504 http_404 updating;
Proxy_cache_background_update
Syntax: proxy_cache_background_update [off|on];
Default: proxy_cache_background_update off;
Permite que uma subrequest em background seja acionada
para atualização do objecto expirado, enquanto o objeto STALE
é retornado ao cliente.
proxy_cache_background_update on;
Proxy_pass
Syntax: proxy_pass url;
Configura qual o servidor Upstream vai responder a request.
proxy_pass http://backend;
upstream
Configura os servidores de backend, healthy checks intervals,
load balance algorithm.
resolver 10.0.0.1;
upstream dynamic {
zone upstream_dynamic 64k;
least_conn;
server backend1.example.com weight=5 max_fails=3 slow_start=30s timeout=5s resolve;
server backup1.example.com backup;
}
server {
location / {
proxy_pass http://dynamic;
health_check;
}
}
Cache status
● MISS – The response was not found in the cache and so was fetched from an
origin server. The response might then have been cached.
● BYPASS – The response was fetched from the origin server instead of served from
the cache because the request matched a proxy_cache_bypass directive (see Can
I Punch a Hole Through My Cache? below.) The response might then have been
cached.
● EXPIRED – The entry in the cache has expired. The response contains fresh
content from the origin server.
● STALE – The content is stale because the origin server is not responding correctly,
and proxy_cache_use_stale was configured.
● UPDATING – The content is stale because the entry is currently being updated in
response to a previous request, and proxy_cache_use_stale updating is
configured.
● REVALIDATED – The proxy_cache_revalidate directive was enabled and NGINX
verified that the current cached content was still valid (If-Modified-Since or If-
None-Match).
● HIT – The response contains valid, fresh content direct from the cache.
NGINX SHARDING
nginx
- High Capacity - Replication
nginx
Quanto maior for o Cache Tier - Maior a capacidade de
armazenamento e menos custoso o incidente de failover.
nginx
nginx
Sharding with hash consistent
upstream backend {
zone lb 32k;
server ngx_cache.service.consul:8081 resolve backup;
server 10.0.0.6:8081;
hash $scheme$proxy_host$uri consistent;
keepalive 32;
}
$uri -> ignora os query param.
MICROCACHING
Benchmarked - AB
1. Apache+WordPress
2. Reverse Proxy Only
3. Short-term Caching
4. Microcaching optimizations
Apache + WordPress
root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/
Requests per second: 5.53 [#/sec] (mean)
Time per request: 1809.260 [ms] (mean)
Time per request: 180.926 [ms] (mean, across all
concurrent requests)
Transfer rate: 319.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 3
Processing: 1430 1735 259.4 1580 2228
Waiting: 537 683 119.7 624 980
Total: 1430 1735 259.4 1580 2228
root@nginx-server:/var/www/html# vmstat 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
10 0 0 136076 44944 585920 0 0 0 0 476 1665 96 4 0 0 0
10 0 0 140112 44952 585924 0 0 0 4 506 1773 98 2 0 0 0
10 0 0 136208 44952 585924 0 0 0 0 576 2057 97 3 0 0 0
reverse proxy only
root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/
Requests per second: 5.63 [#/sec] (mean)
Time per request: 1774.708 [ms] (mean)
Time per request: 177.471 [ms] (mean, across all concurrent requests)
Transfer rate: 324.44 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing:1423 1709 341.3 1532 2794
Waiting: 554 703 165.0 608 1165
Total: 1423 1709 341.4 1532 2794
short-term caching
root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/
Complete requests: 18022
Requests per second: 600.73 [#/sec] (mean)
Time per request: 16.646 [ms] (mean)
Time per request: 1.665 [ms] (mean, across all concurrent requests)
Transfer rate: 33374.96 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.5 1 10
Processing: 0 16 141.5 3 2119
Waiting: 0 6 54.6 1 818
Total: 1 17 141.5 4 2121
microcaching optimizations
root@nginx-client:~# ab -c 10 -t 30 -n 100000 -k http://nginx-server/
Concurrency Level: 10
Time taken for tests: 30.001 seconds
Complete requests: 65553
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 3728905623 bytes
HTML transferred: 3712974057 bytes
Requests per second: 2185.03 [#/sec] (mean)
Time per request: 4.577 [ms] (mean)
Time per request: 0.458 [ms] (mean, across all concurrent requests)
Transfer rate: 121379.72 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.3 1 5
Processing: 1 4 8.1 3 661
Waiting: 0 1 2.6 1 250
Total: 1 5 8.1 4 661 root@nginx-server:/var/www/html# vmstat 3
procs -----------memory---------- ---swap-- -----io---- -system--- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 106512 53192 641116 0 0 0 37 11016 3727 19 45 36 0 0
1 0 0 105832 53192 641808 0 0 0 68 17116 3521 13 56 31 0 0
1 0 0 104624 53192 643132 0 0 0 64 14120 4487 15 51 33 0 0
microcaching - why?
Microcaching
server {
proxy_cache one;
proxy_cache_lock on;
proxy_cache_valid 200 1s;
proxy_cache_background_update on;
proxy_cache_use_stale updating;
proxy_http_version 1.1; # Always upgrade to HTTP/1.1
proxy_set_header Connection ""; # Enable keepalives
# ...
}
upstream one {
zone wordpress 128k;
keepalive 32;
server backend:80 resolve;
}
Dúvidas?????
referências
https://www.nginx.com/blog/nginx-caching-guide/
https://www.nginx.com/blog/benefits-of-microcaching-nginx/
https://github.com/hashicorp/consul-template
https://nginx.org/en/docs/http/ngx_http_proxy_module.html
https://www.nginx.com/blog/10-tips-for-10x-application-performance/
https://blog.kissmetrics.com/speed-is-a-killer/
https://www.nginx.com/blog/shared-caches-nginx-plus-cache-clusters-part-1/
Obrigado!!!!!

Contenu connexe

Tendances

Using Server-Timing for App and CDN Monitoring
Using Server-Timing for App and CDN MonitoringUsing Server-Timing for App and CDN Monitoring
Using Server-Timing for App and CDN MonitoringAkamai Developers & Admins
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisationgrooverdan
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2Fastly
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksAdam Wiggins
 
Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2SergeyChernyshev
 
HTTP Acceleration with Varnish
HTTP Acceleration with VarnishHTTP Acceleration with Varnish
HTTP Acceleration with VarnishHarlow Ward
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & LuaKit Chan
 
Web Performance Optimization with HTTP/3
Web Performance Optimization with HTTP/3Web Performance Optimization with HTTP/3
Web Performance Optimization with HTTP/3SangJin Kang
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXKevin Jones
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsGavin Roy
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative InfrastuctureMarc Seeger
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skypeelliando dias
 
HTTP Caching in Web Application
HTTP Caching in Web ApplicationHTTP Caching in Web Application
HTTP Caching in Web ApplicationMartins Sipenko
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusNGINX, Inc.
 
Reverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishReverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishEl Mahdi Benzekri
 
Covert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache HeadersCovert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache HeadersDenis Kolegov
 

Tendances (20)

Using Server-Timing for App and CDN Monitoring
Using Server-Timing for App and CDN MonitoringUsing Server-Timing for App and CDN Monitoring
Using Server-Timing for App and CDN Monitoring
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP Tricks
 
Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2
 
HTTP Acceleration with Varnish
HTTP Acceleration with VarnishHTTP Acceleration with Varnish
HTTP Acceleration with Varnish
 
Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & Lua
 
Web Performance Optimization with HTTP/3
Web Performance Optimization with HTTP/3Web Performance Optimization with HTTP/3
Web Performance Optimization with HTTP/3
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with Skytools
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative Infrastucture
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skype
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
HTTP Caching in Web Application
HTTP Caching in Web ApplicationHTTP Caching in Web Application
HTTP Caching in Web Application
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX Plus
 
04 web optimization
04 web optimization04 web optimization
04 web optimization
 
Reverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishReverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and Varnish
 
Covert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache HeadersCovert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache Headers
 

Similaire à Nginx Scalable Stack

Mobile App Performance: Getting the Most from APIs (MBL203) | AWS re:Invent ...
Mobile App Performance:  Getting the Most from APIs (MBL203) | AWS re:Invent ...Mobile App Performance:  Getting the Most from APIs (MBL203) | AWS re:Invent ...
Mobile App Performance: Getting the Most from APIs (MBL203) | AWS re:Invent ...Amazon Web Services
 
ITB2017 - Nginx Effective High Availability Content Caching
ITB2017 - Nginx Effective High Availability Content CachingITB2017 - Nginx Effective High Availability Content Caching
ITB2017 - Nginx Effective High Availability Content CachingOrtus Solutions, Corp
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc Cortinas Val
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...Amazon Web Services
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheKevin Jones
 
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...Amazon Web Services
 
Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Xavier Lucas
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocolAviran Mordo
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceSpark::red
 
Nginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixNginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixHarald Zeitlhofer
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014bryan_call
 
5 steps to faster web sites & HTML5 games - updated for DDDscot
5 steps to faster web sites & HTML5 games - updated for DDDscot5 steps to faster web sites & HTML5 games - updated for DDDscot
5 steps to faster web sites & HTML5 games - updated for DDDscotMichael Ewins
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 

Similaire à Nginx Scalable Stack (20)

Mobile App Performance: Getting the Most from APIs (MBL203) | AWS re:Invent ...
Mobile App Performance:  Getting the Most from APIs (MBL203) | AWS re:Invent ...Mobile App Performance:  Getting the Most from APIs (MBL203) | AWS re:Invent ...
Mobile App Performance: Getting the Most from APIs (MBL203) | AWS re:Invent ...
 
ITB2017 - Nginx Effective High Availability Content Caching
ITB2017 - Nginx Effective High Availability Content CachingITB2017 - Nginx Effective High Availability Content Caching
ITB2017 - Nginx Effective High Availability Content Caching
 
Caching on the web
Caching on the webCaching on the web
Caching on the web
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...
Dynamic Content Acceleration: Lightning Fast Web Apps with Amazon CloudFront ...
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content Cache
 
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...
Dynamic Content Acceleration: Amazon CloudFront and Amazon Route 53 (ARC309) ...
 
Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocol
 
Cache is King
Cache is KingCache is King
Cache is King
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web Perormance
 
Caching
CachingCaching
Caching
 
Nginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixNginx, PHP, Apache and Spelix
Nginx, PHP, Apache and Spelix
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014
 
5 steps to faster web sites & HTML5 games - updated for DDDscot
5 steps to faster web sites & HTML5 games - updated for DDDscot5 steps to faster web sites & HTML5 games - updated for DDDscot
5 steps to faster web sites & HTML5 games - updated for DDDscot
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
The SPDY Protocol
The SPDY ProtocolThe SPDY Protocol
The SPDY Protocol
 

Dernier

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Nginx Scalable Stack

  • 1. Delivery high performance applications with Efficient Cache Layer Bruno Paiuca => ‘KaBuM! SA’ Twitter => ‘https://twitter.com/BPaiuca’
  • 2. whoami > whoami Bruno Paiuca, 28 anos, Palmeirense, Sysadmin coder. Redes de computadores - FIAP MBA Sistemas corporativos de alto desempenho - FIAP Certificações: - LPI - CCNA - RHCE - AWS Solution Architect Associate Tecnologias: - Linux - NGINX - Perl - Python - SaltStack - Docker - AWS - redis - terraform Twitter => https://twitter.com/BPaiuca LinkedIn => https://www.linkedin.com/in/brunopaiuca/
  • 3. sumário Por que? Como? - expectativa do usuário - baixíssima latência - altamente escaláveis - altamente disponiveis - redução de custos
  • 4. por que? study done by Amazon almost 10 years ago proved that, even then, a 100-millisecond decrease in page-loading time translated to a 1% increase in its revenue. According to surveys done by Akamai and Gomez.com, nearly half of web users expect a site to load in 2 seconds or less, and they tend to abandon a site that isn’t loaded within 3 seconds. 79% of web shoppers who have trouble with web site performance say they won’t return to the site to buy again and around 44% of them would tell a friend if they had a poor experience shopping online.
  • 10. NGINX CACHE How long? What is your app? Pattern? - Monolithic - REST - Microservice - SOAP
  • 11. NGINX CACHE Advantages - Reduce Server load - Better user experience - Delivery more with less resources
  • 12. proxy_cache_path proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] Determina o diretório de armazenamento, level de subdiretórios, size e nome da key_zone. E.g. proxy_cache_path /dev/shm/nginx levels=1:2 use_temp_path=on keys_zone=APPCACHE:1m inactive=300s max_size=1m;
  • 13. proxy_cache_key Syntax: Proxy_cache_key string; Default: proxy_cache_key $scheme$proxy_host$request_uri; Determina a key para armazenamento e busca de Match nos objetos do Cache. proxy_cache_key $scheme$proxy_host$uri$cookie_userid;
  • 14. proxy_cache Syntax: proxy_cache [cache zone]; Define em qual Cached Zone o objeto será buscado ou armazenado. proxy_cache APPCACHE;
  • 15. proxy_cache_valid Syntax: Proxy_cache_valid [http code] time; Define a condição para um cache ser armazenado na cached zone e o tempo em que o objeto será considerado Fresh. proxy_cache_valid 200 301 302 304 1h; proxy_cache_valid 404 1m; proxy_cache_valid any 30s;
  • 16. proxy_cache_lock Syntax: proxy_cache_lock [off|on]; Default: proxy_cache_lock off; Configura para apenas 1 request simultanea seja autorizado a popular um novo cache object , enviando para o Upstream server. proxy_cache_lock on;
  • 17. Proxy_cache_purge Syntax: Proxy_cache_purge [$variable]; Define uma condição para que a request seja considerado uma Purge Request. Essa requisição limpa o objeto da cached zone, baseado na cache_key. O resultado é retornado como HTTP 204 (No Content). Essa é uma feature comercial. map $request_method $purge_method { PURGE 1; default 0; } server { proxy_cache_lock $purge_method; }
  • 18. Proxy_cache_bypass Syntax: Proxy_cache_bypass [$variable]; Define uma condição para que a request ignore os objetos do Cache Zone e a request seja enviada para o Upstream. O retorno atualiza o objeto já armazenado na Cache Zone. proxy_cache_lock $arg_skipcache;
  • 19. Proxy_cache_use_stale Syntax: Proxy_cache_use_stale [$variable]; Define casos em que uma STALE Cached response pode ser utilizada. E.g. proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503 http_504 http_404 updating;
  • 20. Proxy_cache_background_update Syntax: proxy_cache_background_update [off|on]; Default: proxy_cache_background_update off; Permite que uma subrequest em background seja acionada para atualização do objecto expirado, enquanto o objeto STALE é retornado ao cliente. proxy_cache_background_update on;
  • 21. Proxy_pass Syntax: proxy_pass url; Configura qual o servidor Upstream vai responder a request. proxy_pass http://backend;
  • 22. upstream Configura os servidores de backend, healthy checks intervals, load balance algorithm. resolver 10.0.0.1; upstream dynamic { zone upstream_dynamic 64k; least_conn; server backend1.example.com weight=5 max_fails=3 slow_start=30s timeout=5s resolve; server backup1.example.com backup; } server { location / { proxy_pass http://dynamic; health_check; } }
  • 23. Cache status ● MISS – The response was not found in the cache and so was fetched from an origin server. The response might then have been cached. ● BYPASS – The response was fetched from the origin server instead of served from the cache because the request matched a proxy_cache_bypass directive (see Can I Punch a Hole Through My Cache? below.) The response might then have been cached. ● EXPIRED – The entry in the cache has expired. The response contains fresh content from the origin server. ● STALE – The content is stale because the origin server is not responding correctly, and proxy_cache_use_stale was configured. ● UPDATING – The content is stale because the entry is currently being updated in response to a previous request, and proxy_cache_use_stale updating is configured. ● REVALIDATED – The proxy_cache_revalidate directive was enabled and NGINX verified that the current cached content was still valid (If-Modified-Since or If- None-Match). ● HIT – The response contains valid, fresh content direct from the cache.
  • 25. nginx - High Capacity - Replication
  • 26. nginx Quanto maior for o Cache Tier - Maior a capacidade de armazenamento e menos custoso o incidente de failover.
  • 27. nginx
  • 28. nginx
  • 29. Sharding with hash consistent upstream backend { zone lb 32k; server ngx_cache.service.consul:8081 resolve backup; server 10.0.0.6:8081; hash $scheme$proxy_host$uri consistent; keepalive 32; } $uri -> ignora os query param.
  • 31. Benchmarked - AB 1. Apache+WordPress 2. Reverse Proxy Only 3. Short-term Caching 4. Microcaching optimizations
  • 32. Apache + WordPress root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/ Requests per second: 5.53 [#/sec] (mean) Time per request: 1809.260 [ms] (mean) Time per request: 180.926 [ms] (mean, across all concurrent requests) Transfer rate: 319.74 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 1430 1735 259.4 1580 2228 Waiting: 537 683 119.7 624 980 Total: 1430 1735 259.4 1580 2228 root@nginx-server:/var/www/html# vmstat 3 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 10 0 0 136076 44944 585920 0 0 0 0 476 1665 96 4 0 0 0 10 0 0 140112 44952 585924 0 0 0 4 506 1773 98 2 0 0 0 10 0 0 136208 44952 585924 0 0 0 0 576 2057 97 3 0 0 0
  • 33. reverse proxy only root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/ Requests per second: 5.63 [#/sec] (mean) Time per request: 1774.708 [ms] (mean) Time per request: 177.471 [ms] (mean, across all concurrent requests) Transfer rate: 324.44 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 1 Processing:1423 1709 341.3 1532 2794 Waiting: 554 703 165.0 608 1165 Total: 1423 1709 341.4 1532 2794
  • 34. short-term caching root@nginx-client:~# ab -c 10 -t 30 -k http://nginx-server/ Complete requests: 18022 Requests per second: 600.73 [#/sec] (mean) Time per request: 16.646 [ms] (mean) Time per request: 1.665 [ms] (mean, across all concurrent requests) Transfer rate: 33374.96 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 0.5 1 10 Processing: 0 16 141.5 3 2119 Waiting: 0 6 54.6 1 818 Total: 1 17 141.5 4 2121
  • 35. microcaching optimizations root@nginx-client:~# ab -c 10 -t 30 -n 100000 -k http://nginx-server/ Concurrency Level: 10 Time taken for tests: 30.001 seconds Complete requests: 65553 Failed requests: 0 Keep-Alive requests: 0 Total transferred: 3728905623 bytes HTML transferred: 3712974057 bytes Requests per second: 2185.03 [#/sec] (mean) Time per request: 4.577 [ms] (mean) Time per request: 0.458 [ms] (mean, across all concurrent requests) Transfer rate: 121379.72 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 0.3 1 5 Processing: 1 4 8.1 3 661 Waiting: 0 1 2.6 1 250 Total: 1 5 8.1 4 661 root@nginx-server:/var/www/html# vmstat 3 procs -----------memory---------- ---swap-- -----io---- -system--- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 106512 53192 641116 0 0 0 37 11016 3727 19 45 36 0 0 1 0 0 105832 53192 641808 0 0 0 68 17116 3521 13 56 31 0 0 1 0 0 104624 53192 643132 0 0 0 64 14120 4487 15 51 33 0 0
  • 37. Microcaching server { proxy_cache one; proxy_cache_lock on; proxy_cache_valid 200 1s; proxy_cache_background_update on; proxy_cache_use_stale updating; proxy_http_version 1.1; # Always upgrade to HTTP/1.1 proxy_set_header Connection ""; # Enable keepalives # ... } upstream one { zone wordpress 128k; keepalive 32; server backend:80 resolve; }