apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: High cpu & network traffic triggered when batch processing router rules with large number of rules

Open souzens opened this issue 6 years ago • 11 comments

Issue description

We use apisix-gw as the traffic entrance of the development environment in k8s. APISIX-gw runs in containers. At present, apisix has more than 7000 router rules. In the past two days, it was discovered that the CPU and network traffic of apisix-gw will become high when the rules are batched. We suspect that apisix reads etcd data and generates a lot of network traffic when reloading etcd data, which leads to a rise in CPU. We are not sure if it is a problem with the v2 protocol.

Is there any good way to solve this problem?

image image image

Environment

  • apisix version (cmd: apisix version): 1.5
  • OS: apisix-gw pod in K8S

souzens avatar Nov 25 '20 09:11 souzens

https://github.com/apache/apisix/blob/master/apisix/http/router/radixtree_uri.lua#L83

we can cache the radixtree object by lrucache, for example 5 seconds.

membphis avatar Nov 25 '20 09:11 membphis

@souzens would like to submit a PR to fix this issue? if you need any help, please let us know

membphis avatar Nov 25 '20 09:11 membphis

@souzens

image

membphis avatar Nov 25 '20 10:11 membphis

800m -> 800 millicpu

moonming avatar Nov 25 '20 10:11 moonming

@souzens need you to provide more information, eg: The number of routes inserted in batches and examples of routes.

many thx

membphis avatar Nov 25 '20 11:11 membphis

@membphis The readdir (in terms of etcd v3, Range Request) is expensive and maybe we can limit the number of records in one call and roundtrip several times to reduce the bandwidth peak, just like pagination.

See https://github.com/etcd-io/etcd/issues/11001 and https://github.com/etcd-io/etcd/blob/master/api/etcdserverpb/rpc.proto#L426 for more details.

tokers avatar Nov 25 '20 12:11 tokers

I will try to observe these overheads in my own development environment and do some benchmarks.

tokers avatar Nov 25 '20 12:11 tokers

https://github.com/apache/apisix/blob/master/apisix/http/router/radixtree_uri.lua#L83

we can cache the radixtree object by lrucache, for example 5 seconds.

ignore this message, not this problem

membphis avatar Nov 25 '20 14:11 membphis

maybe we can limit the number of records in one call and roundtrip several times to reduce the bandwidth peak, just like pagination.

we need it, this is useful for us

membphis avatar Nov 25 '20 14:11 membphis

maybe we can limit the number of records in one call and roundtrip several times to reduce the bandwidth peak, just like pagination.

we need it, this is useful for us

I have submitted it in https://github.com/apache/apisix/issues/2853. It was registered into my TODO list, or if someone is interested in it, feel free to pick it!

tokers avatar Nov 26 '20 03:11 tokers

Maybe it's also a good idea to support range request for GET too, like kebernetes api @tokers @moonming

HelloBug0 avatar Feb 14 '22 07:02 HelloBug0