Created
April 23, 2018 19:12
-
-
Save spacious/d8d90ce630904f04a61d84d120508298 to your computer and use it in GitHub Desktop.
Optimising NginX, Node.JS and networking for heavy workloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://engineering.gosquared.com/optimising-nginx-node-js-and-networking-for-heavy-workloads | |
# sysctl | |
https://github.com/spheromak/sysctl-cookbook | |
/etc/sysctl.conf | |
net.ipv4.ip_local_port_range='1024 65000' | |
net.ipv4.tcp_tw_reuse='1' | |
net.ipv4.tcp_fin_timeout='15' | |
net.core.netdev_max_backlog='4096' | |
net.core.rmem_max='16777216' | |
net.core.somaxconn='4096' | |
net.core.wmem_max='16777216' | |
net.ipv4.tcp_max_syn_backlog='20480' | |
net.ipv4.tcp_max_tw_buckets='400000' | |
net.ipv4.tcp_no_metrics_save='1' | |
net.ipv4.tcp_rmem='4096 87380 16777216' | |
net.ipv4.tcp_syn_retries='2' | |
net.ipv4.tcp_synack_retries='2' | |
net.ipv4.tcp_wmem='4096 65536 16777216' | |
vm.min_free_kbytes='65536' | |
# How to check connection status | |
https://gist.github.com/4547269 | |
netstat -tan | awk '{print $6}' | sort | uniq -c | |
ss -s | |
NGINX - proxy | |
upstream backend_nodejs { | |
server nodejs-3:5016 max_fails=0 fail_timeout=10s; | |
server nodejs-4:5016 max_fails=0 fail_timeout=10s; | |
server nodejs-5:5016 max_fails=0 fail_timeout=10s; | |
server nodejs-6:5016 max_fails=0 fail_timeout=10s; | |
keepalive 512; | |
} | |
server { | |
listen 80; | |
server_name fast.gosquared.com; | |
client_max_body_size 16M; | |
keepalive_timeout 10; | |
location / { | |
proxy_next_upstream error timeout http_500 http_502 http_503 http_504; | |
proxy_set_header Connection ""; | |
proxy_http_version 1.1; | |
proxy_pass http://backend_nodejs; | |
} | |
access_log off; | |
error_log /dev/null crit; | |
} | |
http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/ | |
https://engineering.gosquared.com/10-vital-aspects-of-building-a-node-js-application/ | |
http://www.speedguide.net/articles/linux-tweaking-121 | |
http://russ.garrett.co.uk/2009/01/01/linux-kernel-tuning/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment