Practical Tips: Quickly locate the performance bottleneck of Zuul

Practical Tips: Quickly locate the performance bottleneck of Zuul

Zuul's performance is not particularly good, especially when some projects have extended Zuul and the code is not so elegant.

How to quickly locate the performance bottleneck of Zuul? We know that the core of Zuul is a filter, and Zuul's many functions are implemented based on filters.

A request will pass through several filters. How to check the time taken for each filter to execute? Just turn on Zuul's Debug ability.

Note This article is based on Spring Cloud Finchley and is also applicable to Spring Cloud Greenwich. Edgware and earlier versions, configure management.security.enabled=false, and the paper /actuator/httptracewas changed /trace.

Turn on Debug parameters

zuul: include-debug-header: truemanagement: endpoints: web: exposure: include:'*'

In this way, only when accessing Zuul, add a ?debug=truecan of Zuul were Debug. Such as monitoring the path ZUUL_HOST:ZUUL_PORT/SOME_PATHthrough which the filter performance bottlenecks which appear in the filter, simply constructed ZUUL_HOST:ZUUL_PORT/SOME_PATH?debug=truecan be.

After requesting and visiting ZUUL_HOST:ZUUL_PORT/actuator/httptrace, you can see results similar to the following:

"X-Zuul-Debug-Header": ["[[[Filter pre 5 PreDecorationFilter]]][[[Filter {PreDecorationFilter TYPE:pre ORDER:5} Execution time = 1ms]]][[[{PreDecorationFilter} added retryable =false]]][[[{PreDecorationFilter} added ignoredHeaders=[authorization, set-cookie, cookie]]]][[[{PreDecorationFilter} added originResponseHeaders=[com.netflix.util.Pair@d68cf7e9]]]][ [[{PreDecorationFilter} added zuulRequestHeaders={x-forwarded-host=localhost:8040, x-forwarded-proto=http, x-forwarded-prefix=/microservice-provider-user, x-forwarded-port=8040, x- forwarded-for=0:0:0:0:0:0:0:1}]][[[{PreDecorationFilter} added requestURI=/users/1]]][[[{PreDecorationFilter} added proxy=microservice- provider-user]]][[[{PreDecorationFilter} changed executedFilters=ServletDetectionFilter[SUCCESS][0ms], Servlet30WrapperFilter[SUCCESS][0ms], DebugFilter[SUCCESS][0ms],PreDecorationFilter[SUCCESS][1ms]]]][[[{PreDecorationFilter} added serviceId=microservice-provider-user]]][[[Invoking {route} type filters]]][[[Filter route 10 RibbonRoutingFilter]]][ [[Filter {RibbonRoutingFilter TYPE:route ORDER:10} Execution time = 9ms]]][[[{RibbonRoutingFilter} changed originResponseHeaders=[com.netflix.util.Pair@d68cf7e9, com.netflix.util.Pair@694b84a6, com .netflix.util.Pair@a4baea16, com.netflix.util.Pair@99438774]]]][[[{RibbonRoutingFilter} added responseDataStream=org.apache.http.conn.EofSensorInputStream@1145027a]]][[[{RibbonRoutingFilter] } added zuulResponseHeaders=[com.netflix.util.Pair@694b84a6, com.netflix.util.Pair@99438774]]]][[[{RibbonRoutingFilter} added responseStatusCode=200]]][[[{RibbonRoutingFilter} added responseGZipped= false]]][[[{RibbonRoutingFilter} added ribbonResponse=org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponse@5e2ce130]]][[[{RibbonRoutingFilter} changed executedFilters=ServletDetectionFilter[SUCCESS][0ms], Servlet30WrapperFilter[SUCCESS][0ms], DebugFilter[SUCCESS][0ms], PreDecorationFilter[SUCCESS][1ms] , RibbonRoutingFilter[SUCCESS][9ms]]]][[[{RibbonRoutingFilter} added zuulResponse=org.springframework.cloud.netflix.ribbon.RibbonHttpResponse@1e0eabde]]][[[Filter route 100 SimpleHostRoutingFilter]]][[[Filter route 500 SendForwardFilter]]][[[Invoking {post} type filters]]][[[Filter post 1000 SendResponseFilter]]]"],RibbonRoutingFilter[SUCCESS][9ms]]]][[[{RibbonRoutingFilter} added zuulResponse=org.springframework.cloud.netflix.ribbon.RibbonHttpResponse@1e0eabde]]][[[Filter route 100 SimpleHostRoutingFilter]]][[[Filter route 500 SendForwardFilter]]][[[Invoking {post} type filters]]][[[Filter post 1000 SendResponseFilter]]]"],RibbonRoutingFilter[SUCCESS][9ms]]]][[[{RibbonRoutingFilter} added zuulResponse=org.springframework.cloud.netflix.ribbon.RibbonHttpResponse@1e0eabde]]][[[Filter route 100 SimpleHostRoutingFilter]]][[[Filter route 500 SendForwardFilter]]][[[Invoking {post} type filters]]][[[Filter post 1000 SendResponseFilter]]]"],

It can be seen from the results that the endpoint sequentially printed which filters the request passed through and the time consumption of each filter. With a simple analysis, you can understand the performance bottleneck of Zuul.

Enable default Debug

After the above configuration, Debug on Zuul has been achieved, but every time add a debug=truelittle tail, is annoying, and you do not want to add, and want Zuul default on the request to open Debug, how to do it?

It is also very simple, just add the following configuration on the basis of the above:

zuul: debug: request: true

In this way, debug=trueZuul will debug even if it is not added .

Related source code

The relevant source code is actually relatively simple, just one category:, org.springframework.cloud.netflix.zuul.filters.pre.DebugFilterchildren who are interested can learn about it.

Reference: https://cloud.tencent.com/developer/article/1460871 Practical Tips: Quickly locate Zuul’s performance bottlenecks-Cloud + Community-Tencent Cloud