django and nginx reverse proxy cache

31
Boosting Django Performance with the Nginx Reverse Proxy Cache (I need to find better titles…)

Upload: anton-pirker

Post on 07-Jul-2015

359 views

Category:

Internet


2 download

DESCRIPTION

Use Nginx's reverse proxy cache feature to boot your websites performance

TRANSCRIPT

Page 1: Django and Nginx reverse proxy cache

Boosting Django Performance with the Nginx Reverse Proxy

Cache(I need to find better titles…)

Page 2: Django and Nginx reverse proxy cache

Your site is lame!

Page 3: Django and Nginx reverse proxy cache

Why?

Page 4: Django and Nginx reverse proxy cache

Nginx

Page 5: Django and Nginx reverse proxy cache

NginxGunicorn

Page 6: Django and Nginx reverse proxy cache

NginxGunicorn

DB

Page 7: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 8: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 9: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 10: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 11: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 12: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 13: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 14: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 15: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 16: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 17: Django and Nginx reverse proxy cache

“The key to making programs fast is to make them

do practically nothing”

-- Mike Haertel (Author of GNU grep)

Page 18: Django and Nginx reverse proxy cache

The Solution:

Page 19: Django and Nginx reverse proxy cache

NginxGunicorn

DB FS

Page 20: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

Nginx Reverse Proxy Cache Config

Page 21: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

Nginx Reverse Proxy Cache Config

Page 22: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

Nginx Reverse Proxy Cache Config

Page 23: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

proxy_cache_key "$scheme://$host$request_uri";

Nginx Reverse Proxy Cache Config

Page 24: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

proxy_cache_key "$scheme://$host$request_uri";

proxy_cache_valid 200 6M;

Nginx Reverse Proxy Cache Config

Page 25: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

proxy_cache_key "$scheme://$host$request_uri";

proxy_cache_valid 200 6M;

proxy_ignore_headers Cache-Control;proxy_ignore_headers Set-Cookie;proxy_hide_header Set-Cookie;

Nginx Reverse Proxy Cache Config

Page 26: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

proxy_cache_key "$scheme://$host$request_uri";

proxy_cache_valid 200 6M;

proxy_ignore_headers Cache-Control;proxy_ignore_headers Set-Cookie;proxy_hide_header Set-Cookie;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;

Nginx Reverse Proxy Cache Config

Page 27: Django and Nginx reverse proxy cache

proxy_cache nginx_cache;

proxy_cache_path /data/nginx-cache levels=1:2 max_size=10g inactive=1y keys_zone=nginx_cache:40m;

proxy_temp_path /data/nginx-cache-temp 1 2;

proxy_cache_key "$scheme://$host$request_uri";

proxy_cache_valid 200 6M;

proxy_ignore_headers Cache-Control;proxy_ignore_headers Set-Cookie;proxy_hide_header Set-Cookie;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;

add_header X-Cached $upstream_cache_status;

Nginx Reverse Proxy Cache Config

Page 28: Django and Nginx reverse proxy cache

The result:

Page 29: Django and Nginx reverse proxy cache

-62%Response time

Page 30: Django and Nginx reverse proxy cache

Your site is fast!