Skip to content

Instantly share code, notes, and snippets.

@alfredochuc
Forked from Unitech/app-koa.js
Created April 8, 2019 21:21
Show Gist options
  • Save alfredochuc/bf09e6921bf7df0b71d9172495773251 to your computer and use it in GitHub Desktop.
Save alfredochuc/bf09e6921bf7df0b71d9172495773251 to your computer and use it in GitHub Desktop.

Revisions

  1. @Unitech Unitech revised this gist May 16, 2017. 1 changed file with 0 additions and 23 deletions.
    23 changes: 0 additions & 23 deletions app-express.js
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    var express = require('express')
    var app = express()

    app.get('/', function (req, res) {
    res.send({ port : listener.address().port });
    })

    app.get('/large_chunk', function (req, res) {
    var b = new Buffer(5000);
    b.fill("X");
    res.send(b);
    })

    app.get('/uber_chunk', function (req, res) {
    var b = new Buffer(500000);
    b.fill("X");
    res.send(b);
    })

    var listener = app.listen(process.env.PORT || 3000, function () {
    console.log(`Listening on port ${listener.address().port}`);
    })

  2. @Unitech Unitech revised this gist May 15, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,14 @@
    daemon off;
    worker_processes 12;

    events {
    worker_connections 4096;
    worker_processes 12;
    }

    http {
    server {
    server_name _;
    listen 7001;

    listen 7002;
    location / {
    proxy_redirect off;
    proxy_pass http://apistream;
    @@ -26,7 +25,7 @@ http {

    stream {
    server {
    listen 7002;
    listen 7001;
    proxy_pass apistream;
    }

    @@ -36,4 +35,5 @@ stream {
    server localhost:8003;
    server localhost:8004;
    }
    }
    }

  3. @Unitech Unitech revised this gist May 15, 2017. 1 changed file with 10 additions and 17 deletions.
    27 changes: 10 additions & 17 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,30 @@
    global
    maxconn 20000

    defaults
    log global
    mode http
    option httplog
    option dontlognull
    timeout connect 5000
    timeout client 50000
    timeout server 50000

    frontend tcp-frontend
    mode tcp
    bind *:6001
    default_backend http-backend
    default_backend tcp-backend

    backend tcp-backend
    mode tcp
    balance roundrobin
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
    server http-instance-0 localhost:8001
    server http-instance-1 localhost:8002
    server http-instance-2 localhost:8003
    server http-instance-3 localhost:8004

    frontend http-frontend
    mode http
    bind *:6001
    bind *:6002
    default_backend http-backend

    backend http-backend
    mode http
    balance roundrobin
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
    server http-instance-0 localhost:8001
    server http-instance-1 localhost:8002
    server http-instance-2 localhost:8003
    server http-instance-3 localhost:8004
  4. @Unitech Unitech revised this gist May 11, 2017. 3 changed files with 44 additions and 29 deletions.
    23 changes: 23 additions & 0 deletions app-express.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    var express = require('express')
    var app = express()

    app.get('/', function (req, res) {
    res.send({ port : listener.address().port });
    })

    app.get('/large_chunk', function (req, res) {
    var b = new Buffer(5000);
    b.fill("X");
    res.send(b);
    })

    app.get('/uber_chunk', function (req, res) {
    var b = new Buffer(500000);
    b.fill("X");
    res.send(b);
    })

    var listener = app.listen(process.env.PORT || 3000, function () {
    console.log(`Listening on port ${listener.address().port}`);
    })

    8 changes: 0 additions & 8 deletions raw-http.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    var http = require('http');

    var server = http.createServer(function(req, res) {
    res.writeHead(200);
    res.end('hey ' + server.address().port);
    }).listen(process.env.PORT || 8000, function() {
    console.log('Listening on %s', server.address().port);
    });
    42 changes: 21 additions & 21 deletions report.lua
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,24 @@
    f = io.open("result.csv", "a+"
    )
    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:write(string.format("%s:%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
    wrk.host,
    wrk.port,
    latency.min,
    latency.max,
    latency.mean,
    latency.stdev,
    latency:percentile(99),
    summary["duration"],
    summary["requests"],
    summary["bytes"],
    summary["errors"].connect,
    summary["errors"].read,
    summary["errors"].write,
    summary["errors"].status,
    summary["errors"].timeout
    ))

    f:close()
    end
  5. @Unitech Unitech revised this gist May 11, 2017. 2 changed files with 31 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions app-koa.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,10 @@
    const Koa = require('koa');
    const router = require('koa-router')();

    const app = new Koa();

    app.use(ctx => {
    ctx.body = 'Hello World';
    });

    router
    .get('/', function *(next) {
    this.body = 'Hello World!';
    })

    var listener = app.listen(process.env.PORT || 3000, () => {
    console.log(`Listening on port ${listener.address().port}`);
    });
    31 changes: 31 additions & 0 deletions pstree
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    systemd─┬─PM2 v2.4.6: God─┬─haproxy
    │ ├─nginx───12*[nginx]
    │ ├─5*[node /home/ubun─┬─4*[{V8 WorkerThread}]]
    │ │ └─5*[{node}]]
    │ ├─4*[node /home/ubun─┬─4*[{V8 WorkerThread}]]
    │ │ ├─4*[{node /home/ubun}]]
    │ │ └─{node}]
    │ ├─4*[{PM2 v2.4.6: God}]
    │ ├─4*[{V8 WorkerThread}]
    │ └─{node}
    ├─accounts-daemon─┬─{gdbus}
    │ └─{gmain}
    ├─agetty
    ├─cron
    ├─dbus-daemon
    ├─dhclient
    ├─irqbalance
    ├─mdadm
    ├─named───14*[{named}]
    ├─ntpd───ntpd───ntpd
    ├─polkitd─┬─{gdbus}
    │ └─{gmain}
    ├─rsyslogd─┬─{in:imklog}
    │ ├─{in:imuxsock}
    │ └─{rs:main Q:Reg}
    ├─sshd─┬─sshd───sshd───bash───pstree
    │ └─sshd───sshd
    ├─systemd───(sd-pam)
    ├─systemd-journal
    ├─systemd-logind
    └─systemd-udevd
  6. @Unitech Unitech revised this gist May 10, 2017. 2 changed files with 27 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions app-koa.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    const Koa = require('koa');
    const router = require('koa-router')();

    const app = new Koa();

    app.use(ctx => {
    ctx.body = 'Hello World';
    });

    router
    .get('/', function *(next) {
    this.body = 'Hello World!';
    })

    var listener = app.listen(process.env.PORT || 3000, () => {
    console.log(`Listening on port ${listener.address().port}`);
    });


    8 changes: 8 additions & 0 deletions raw-http.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    var http = require('http');

    var server = http.createServer(function(req, res) {
    res.writeHead(200);
    res.end('hey ' + server.address().port);
    }).listen(process.env.PORT || 8000, function() {
    console.log('Listening on %s', server.address().port);
    });
  7. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,15 @@
    global
    maxconn 20000

    defaults
    log global
    mode http
    option httplog
    option dontlognull
    timeout connect 5000
    timeout client 50000
    timeout server 50000

    frontend tcp-frontend
    mode tcp
    bind *:6001
  8. @Unitech Unitech revised this gist May 10, 2017. 2 changed files with 16 additions and 16 deletions.
    16 changes: 8 additions & 8 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,10 @@ frontend tcp-frontend
    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
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000

    frontend http-frontend
    mode http
    @@ -22,7 +22,7 @@ frontend http-frontend
    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
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
    16 changes: 8 additions & 8 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ http {
    }

    upstream apistream {
    server benchmark.keymetrics.io:8001;
    server benchmark.keymetrics.io:8002;
    server benchmark.keymetrics.io:8003;
    server benchmark.keymetrics.io:8004;
    server localhost:8001;
    server localhost:8002;
    server localhost:8003;
    server localhost:8004;
    }
    }

    @@ -31,9 +31,9 @@ stream {
    }

    upstream apistream {
    server benchmark.keymetrics.io:8001;
    server benchmark.keymetrics.io:8002;
    server benchmark.keymetrics.io:8003;
    server benchmark.keymetrics.io:8004;
    server localhost:8001;
    server localhost:8002;
    server localhost:8003;
    server localhost:8004;
    }
    }
  9. @Unitech Unitech revised this gist May 10, 2017. 2 changed files with 16 additions and 16 deletions.
    16 changes: 8 additions & 8 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,10 @@ frontend tcp-frontend
    backend tcp-backend
    mode tcp
    balance roundrobin
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
    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
    @@ -22,7 +22,7 @@ frontend http-frontend
    backend http-backend
    mode http
    balance roundrobin
    server http-instance-0 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
    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
    16 changes: 8 additions & 8 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ http {
    }

    upstream apistream {
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
    server 127.0.0.1:8004;
    server benchmark.keymetrics.io:8001;
    server benchmark.keymetrics.io:8002;
    server benchmark.keymetrics.io:8003;
    server benchmark.keymetrics.io:8004;
    }
    }

    @@ -31,9 +31,9 @@ stream {
    }

    upstream apistream {
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
    server 127.0.0.1:8004;
    server benchmark.keymetrics.io:8001;
    server benchmark.keymetrics.io:8002;
    server benchmark.keymetrics.io:8003;
    server benchmark.keymetrics.io:8004;
    }
    }
  10. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions haproxy.cfg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost: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 localhost:8001 maxconn 20000
    server http-instance-1 localhost:8002 maxconn 20000
    server http-instance-2 localhost:8003 maxconn 20000
    server http-instance-3 localhost:8004 maxconn 20000
  11. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 39 additions and 0 deletions.
    39 changes: 39 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
    server 127.0.0.1:8004;
    }
    }

    stream {
    server {
    listen 7002;
    proxy_pass apistream;
    }

    upstream apistream {
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
    server 127.0.0.1:8004;
    }
    }
  12. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions sysctl.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # 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
  13. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions etc - security - limits.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    * soft nofile 999999
    * hard nofile 999999
  14. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions cat proc - cpuinfo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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:
  15. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions report.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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
  16. @Unitech Unitech revised this gist May 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion haproxy.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    sudo apt-get install -qq build-essential libssl-dev libev-dev
    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
  17. @Unitech Unitech created this gist May 10, 2017.
    5 changes: 5 additions & 0 deletions haproxy.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    sudo apt-get install -qq build-essential libssl-dev libev-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
    6 changes: 6 additions & 0 deletions nginx.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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