-
-
Save alfredochuc/bf09e6921bf7df0b71d9172495773251 to your computer and use it in GitHub Desktop.
Node.js Load Balancers Benchmark: HAProxy vs Nginx vs PM2
This file contains hidden or 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
| ubuntu@benchmark-machine:~/benchmark-v1/haproxy$ cat /proc/cpuinfo | |
| processor : 0 | |
| vendor_id : GenuineIntel | |
| cpu family : 6 | |
| model : 86 | |
| model name : Intel(R) Xeon(R) CPU D-1531 @ 2.20GHz | |
| stepping : 3 | |
| microcode : 0x700000a | |
| cpu MHz : 801.195 | |
| cache size : 9216 KB | |
| physical id : 0 | |
| siblings : 12 | |
| core id : 0 | |
| cpu cores : 6 | |
| apicid : 0 | |
| initial apicid : 0 | |
| fpu : yes | |
| fpu_exception : yes | |
| cpuid level : 20 | |
| wp : yes | |
| flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts | |
| bugs : | |
| bogomips : 4399.54 | |
| clflush size : 64 | |
| cache_alignment : 64 | |
| address sizes : 46 bits physical, 48 bits virtual | |
| power management: |
This file contains hidden or 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
| * soft nofile 999999 | |
| * hard nofile 999999 |
This file contains hidden or 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
| global | |
| maxconn 20000 | |
| frontend tcp-frontend | |
| mode tcp | |
| bind *:6001 | |
| default_backend http-backend | |
| backend tcp-backend | |
| mode tcp | |
| balance roundrobin | |
| server http-instance-0 benchmark.keymetrics.io:8001 maxconn 20000 | |
| server http-instance-1 benchmark.keymetrics.io:8002 maxconn 20000 | |
| server http-instance-2 benchmark.keymetrics.io:8003 maxconn 20000 | |
| server http-instance-3 benchmark.keymetrics.io:8004 maxconn 20000 | |
| frontend http-frontend | |
| mode http | |
| bind *:6001 | |
| default_backend http-backend | |
| backend http-backend | |
| mode http | |
| balance roundrobin | |
| server http-instance-0 benchmark.keymetrics.io:8001 maxconn 20000 | |
| server http-instance-1 benchmark.keymetrics.io:8002 maxconn 20000 | |
| server http-instance-2 benchmark.keymetrics.io:8003 maxconn 20000 | |
| server http-instance-3 benchmark.keymetrics.io:8004 maxconn 20000 |
This file contains hidden or 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
| sudo apt-get install -qq build-essential libssl-dev libev-dev libpcre3-dev | |
| wget https://www.haproxy.org/download/1.7/src/haproxy-1.7.5.tar.gz | |
| tar xzvf haproxy-1.7.5.tar.gz | |
| cd haproxy-1.7.5 | |
| sudo make TARGET=generic USE_OPENSSL=1 USE_ZLIB=yes CPU=native USE_PCRE=1 |
This file contains hidden or 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
| daemon off; | |
| events { | |
| worker_connections 4096; | |
| worker_processes 12; | |
| } | |
| http { | |
| server { | |
| server_name _; | |
| listen 7001; | |
| location / { | |
| proxy_redirect off; | |
| proxy_pass http://apistream; | |
| } | |
| } | |
| upstream apistream { | |
| server benchmark.keymetrics.io:8001; | |
| server benchmark.keymetrics.io:8002; | |
| server benchmark.keymetrics.io:8003; | |
| server benchmark.keymetrics.io:8004; | |
| } | |
| } | |
| stream { | |
| server { | |
| listen 7002; | |
| proxy_pass apistream; | |
| } | |
| upstream apistream { | |
| server benchmark.keymetrics.io:8001; | |
| server benchmark.keymetrics.io:8002; | |
| server benchmark.keymetrics.io:8003; | |
| server benchmark.keymetrics.io:8004; | |
| } | |
| } |
This file contains hidden or 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
| apt-get update | |
| apt-get install libssl-dev gcc -y | |
| wget http://nginx.org/download/nginx-1.11.13.tar.gz | |
| tar zxvf nginx-1.11.13.tar.gz | |
| ./configure --without-http_rewrite_module --with-http_ssl_module --with-stream --with-http_stub_status_module --prefix=. --error-log-path=error.log --http-log-path=access.log --pid-path=nginx.pid --lock-path=nginx.lock --conf-path=nginx.conf | |
| make -j12 |
This file contains hidden or 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
| done = function(summary, latency, requests) | |
| -- open output file | |
| f = io.open("result.csv", "a+") | |
| -- write below results to file | |
| -- minimum latency | |
| -- max latency | |
| -- mean of latency | |
| -- standard deviation of latency | |
| -- 50percentile latency | |
| -- 90percentile latency | |
| -- 99percentile latency | |
| -- 99.999percentile latency | |
| -- duration of the benchmark | |
| -- total requests during the benchmark | |
| -- total received bytes during the benchmark | |
| f:write(string.format("%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d\n", | |
| latency.min, latency.max, latency.mean, latency.stdev, latency:percentile(50), | |
| latency:percentile(90), latency:percentile(99), latency:percentile(99.999), | |
| summary["duration"], summary["requests"], summary["bytes"])) | |
| f:close() | |
| end |
This file contains hidden or 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
| # Increase number of incoming connections that can queue up | |
| # before dropping | |
| net.core.somaxconn = 50000 | |
| # Increase the length of the network device input queue | |
| net.core.netdev_max_backlog = 5000 | |
| # Widen the port range used for outgoing connections | |
| net.ipv4.ip_local_port_range = 10000 65000 | |
| # Disable source routing and redirects | |
| net.ipv4.conf.all.send_redirects = 0 | |
| net.ipv4.conf.all.accept_redirects = 0 | |
| net.ipv4.conf.all.accept_source_route = 0 | |
| # Disable TCP slow start on idle connections | |
| net.ipv4.tcp_slow_start_after_idle = 0 | |
| # Disconnect dead TCP connections after 1 minute | |
| net.ipv4.tcp_keepalive_time = 60 | |
| # Let the networking stack reuse TIME_WAIT connections when it thinks it's safe to do so | |
| net.ipv4.tcp_tw_reuse = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment