apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.49k stars 2.52k forks source link

help request: send Put method admin request frequently costs apisix cpu high(about 100%) when more than 15 thousand routes exist in apisix #9140

Open ranxuxin001 opened 1 year ago

ranxuxin001 commented 1 year ago

Description

Hello everyone, My apisix 2.9 has more than 15 thousand routes currently. And when I use the script to update large amount of routes frequently(sleep 0.5 to 5 seconds), my apisix costs cpu near 100%(user). It leads to request apisix slowly.

I've read some source code of apisix. When update a route, the apisix firstly search relevant node in radix tree. And secondly insert node in radix tree. But most of my routes has the same uri "/*" . The radix tree should has a few nodes, but it has an array with many routes which has the same uri. After that it updates the configuration of the matched route according to host, uri, header etc. So I doubt finding matched route in a long array causes much more cpu time than updating the node in the radix tree. By the way, it there any cpu performance tool suggusted? How about openresty xray?

Is there any strategy to improve the apisx's performance for updating or creating routes frequently while large amount of routes already exist in the apisix, please? Any suggest is appreciated.

apisixCpu

Best Regards, Ranxuxin

Environment

ranxuxin001 commented 1 year ago

@membphis @soulbird hi membphis, soulbird, Could you help me to suggest this issue to any adminstrator who is responsible for solving performance problem of apisix? #9157

soulbird commented 1 year ago

Creating a new route does trigger a rebuild of the route radix tree, which involves a lot of table creation and gc, which usually consume CPU, which is currently unavoidable. Can you consider reducing the frequency of routing updates to reduce CPU consumption? In addition, you can observe CPU performance problems through flame graphs. For APISIX, you can refer to the script here: https://github.com/apache/apisix/blob/master/ci/performance_test.

ranxuxin001 commented 1 year ago

Thank to your suggestion.