apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: APISIX Benchmark fails

Open NicolasBachs opened this issue 6 years ago • 14 comments

Issue description

I was performing stress test in order to check apisix performance but I got an unexpected status code response (Non-2xx or 3xx responses).

Direct to upstream (Golang API, limited to use only one core):

wrk -t4 -c32 -d60s http://localhost:3000/
Running 1m test @ http://localhost:3000/
  4 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   435.11us  268.43us  13.53ms   67.03%
    Req/Sec    18.64k   817.84    34.82k    78.23%
  4454134 requests in 1.00m, 318.58MB read
Requests/sec:  74112.13
Transfer/sec:      5.30MB

Using apisix:

wrk -t4 -c32 -d60s http://localhost:9080/status
Running 1m test @ http://localhost:9080/status
  4 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.31ms    9.76ms 196.69ms   93.31%
    Req/Sec    11.84k     4.70k   18.17k    86.62%
  2828917 requests in 1.00m, 322.05MB read
  Non-2xx or 3xx responses: 5817
Requests/sec:  47139.93
Transfer/sec:      5.37MB

Environment

  • apisix version (cmd: apisix version): 2.0 (cloned from last commit in repo)
  • OS: Manjaro Linux

Upstream configuration:

{
    "hash_on": "vars",
    "id": "1",
    "nodes": {
        "172.17.0.1:3000": 1
    },
    "type": "roundrobin",
    "pass_host": "pass"
}

Consumer configuration:

{
    "username": "1",
    "desc": "",
    "plugins": {}
}

Route configuration:

{
    "id": "test",
    "plugins": {
        "proxy-rewrite": {
            "uri": "/"
        }
    },
    "upstream_id": "1",
    "uri": "/status",
    "desc": "",
    "priority": 0,
    "methods": [
        "GET"
    ],
    "name": "status"
}

How I can solve this trouble?

NicolasBachs avatar Nov 06 '20 15:11 NicolasBachs

you can check the access log, it will show you the upstream status code.

I think it is useful for you to confirm: 3xx or 4xx are returned by APISIX or Glang software.

membphis avatar Nov 06 '20 15:11 membphis

I saw 499 and 502 status code responses in access log.

When we ran the benchmark straight to golang API we haven't received any status code different to 200.

Running 1m test @ http://localhost:3000/
  4 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   435.11us  268.43us  13.53ms   67.03%
    Req/Sec    18.64k   817.84    34.82k    78.23%
  4454134 requests in 1.00m, 318.58MB read
Requests/sec:  74112.13
Transfer/sec:      5.30MB

NicolasBachs avatar Nov 06 '20 16:11 NicolasBachs

I saw 499 and 502 status code responses in access log.

can you show us your golang API code? we'll make a try for this benchmark.

membphis avatar Nov 07 '20 04:11 membphis

This is the Dummy API that I am using:

package main

import (
	"net/http"
	"runtime"
)

func handler(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(200)
}
func main() {
	runtime.GOMAXPROCS(1)
	http.HandleFunc("/", handler)
	http.ListenAndServe(":3000", nil)
}

NicolasBachs avatar Nov 09 '20 17:11 NicolasBachs

Could you try to deploy APISIX, upstream, wrk on different servers? The results should be very different, I tested it, when everything is on the same machine, the test result is relatively low, I guess it is related to resource competition. I used your code as upstream, set the route like this:

curl http://127.0.0.1:9080/apisix/admin/routes/100 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
     "uri": "/test",
     "upstream": {
         "type": "roundrobin",
         "nodes": {
             "172.16.0.16:3000": 1
         }
     }
}'

And my result was: Upstream:

$ wrk -t8 -c32 -d60s http://localhost:3000/test
Running 1m test @ http://localhost:3000/test
  8 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.10ms    0.95ms  29.35ms   89.94%
    Req/Sec     3.87k   428.55     7.03k    81.42%
  1850057 requests in 1.00m, 132.33MB read
Requests/sec:  30798.58
Transfer/sec:      2.20MB

When everything is on the same machine, the APISIX's QPS:

$ wrk -t8 -c32 -d60s http://localhost:9080/test
Running 1m test @ http://localhost:9080/test
  8 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.90ms    1.80ms  39.15ms   92.60%
    Req/Sec     2.37k   400.28     3.66k    70.29%
  1134575 requests in 1.00m, 128.71MB read
Requests/sec:  18898.94
Transfer/sec:      2.14MB

When APISIX, upstream, wrk on separate machines, the APISIX's QPS:

$ wrk -t8 -c32 -d60s http://172.16.0.17:9080/test
Running 1m test @ http://172.16.0.17:9080/test
  8 threads and 32 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.24ms    1.21ms  41.76ms   95.03%
    Req/Sec     3.60k   496.53     5.68k    76.65%
  1720481 requests in 1.00m, 195.17MB read
Requests/sec:  29661.13
Transfer/sec:      3.25MB

idbeta avatar Nov 10 '20 10:11 idbeta

Great, thanks!. I'll try on different machines. However, your results are different to mine in requests/sec so maybe because of that, you don't have non-2xx or 3xx responses. I also don't understand why my results are lower than apisix official benchmarks considering that the computer where I performed the test was even better than the one where the official benchmark was done. I used an Intel core i5-9600k with 6 cores (Golang API was limited to run using only one core).

I would like to know if there is any configuration to take into consideration?.

Note: I setted up WORKER-PROCESSES = 4.

NicolasBachs avatar Nov 10 '20 15:11 NicolasBachs

I know there are several system settings that will affect performance testing, such as fs.file-max, ulimit -n. Performance testing is indeed a science, I think there may be other influence points.

idbeta avatar Nov 11 '20 02:11 idbeta

Thank's for all the help that you gave me. I have another question to ask you, how is the best way to scale horizontally APISIX in Kubernetes sharing the same etcd database? Should I replicate etcd too?

NicolasBachs avatar Nov 11 '20 18:11 NicolasBachs

Thank's for all the help that you gave me. I have another question to ask you, how is the best way to scale horizontally APISIX in Kubernetes sharing the same etcd database? Should I replicate etcd too?

cc @membphis @gxthrj Can you reply to this question?

idbeta avatar Nov 12 '20 02:11 idbeta

Thank's for all the help that you gave me. I have another question to ask you, how is the best way to scale horizontally APISIX in Kubernetes sharing the same etcd database? Should I replicate etcd too?

It's worth opening one issue for one question, so we could have a clear context.

I just opened an issue for this question, please refer to here https://github.com/apache/apisix/issues/2730

juzhiyuan avatar Nov 12 '20 15:11 juzhiyuan

I used an Intel core i5-9600k with 6 cores (Golang API was limited to run using only one core).

I think you can make a try to enable more CPU cores, Golang support this case

membphis avatar Nov 12 '20 16:11 membphis

In the production environment, it is recommended to deploy etcd in clusters.

We can scale horizontally apisix according to the traffic level of the data plane. Etcd does not need to be expanded. Etcd belongs to the control plane and is not affected by the traffic on the data plane.

We can discuss here @NicolasBachs

gxthrj avatar Nov 18 '20 17:11 gxthrj

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Nov 04 '21 10:11 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Nov 18 '21 10:11 github-actions[bot]