Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-406 Increase CN nginx worker procs #3883

Merged
merged 11 commits into from
Sep 21, 2022
21 changes: 15 additions & 6 deletions creator-node/nginx_conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#
# Notes:
# - any value below prefixed with $arg indicates a request query param, e.g. $arg_bypasscache will match query param `bypasscache=<value>`
# Nginx location regex examples: https://linuxhint.com/nginx-location-regex-examples/

worker_processes 1;
worker_processes 8;

events {
worker_connections 4096;
Expand Down Expand Up @@ -34,7 +35,7 @@ http {
# Match the paths /ipfs/<cid: string> and /content/<cid: string>.
# If present in cache, serve. Else, hit upstream server + update cache + serve.
# http://nginx.org/en/docs/http/ngx_http_core_module.html#location
location ~ (/ipfs/|/content/) {
location ~ (/ipfs/|/content/|/file_lookup/) {
proxy_cache cache;
proxy_pass http://127.0.0.1:3000;

Expand All @@ -46,10 +47,12 @@ http {
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;

# Cache only responses with status code = 200 for some duration before considered stale.
# Cache responses with certain status codes for some duration before considered stale.
# Stale implies content will be fetched from the upstream server. Stale content WILL NOT
# BE REMOVED from the cache.
proxy_cache_valid 200 12h;
proxy_cache_valid 403 1h;
SidSethi marked this conversation as resolved.
Show resolved Hide resolved
proxy_cache_valid any 1s;
SidSethi marked this conversation as resolved.
Show resolved Hide resolved

# When enabled, only one request at a time will be allowed to populate a new cache element
# Other requests of the same cache element will either wait for a response to appear in the cache
Expand All @@ -68,6 +71,8 @@ http {
add_header X-Cache-Status $upstream_cache_status always;
}

# Regex matches any path that begins with /health_check (case-sensitive)
# Note this will also include other health check routes /health_check/verbose, /health_check/sync, /health_check/duration, /health_check/duration/heartbeat, /health_check/fileupload
location ~ (/health_check) {
proxy_cache cache;

Expand All @@ -76,10 +81,14 @@ http {
# Set client IP as `X-Forwarded-For` response header
proxy_set_header X-Forwarded-For $remote_addr;

# Never serve a stale response
# proxy_cache_use_stale + proxy_cache_background_update -> deliver stale content when client requests
# an item that is expired or in the process of being updated from origin server
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;

# Cache responses with 200 status, for 1 second
proxy_cache_valid 200 1s;
# Cache responses for 5second on 200, 1 second otherwise
proxy_cache_valid 200 5s;
SidSethi marked this conversation as resolved.
Show resolved Hide resolved
proxy_cache_valid any 1s;

# Bypass cache with bypasscache=true query string and save new response to proxy cache
proxy_cache_bypass $arg_bypasscache;
Expand Down