1
votes

I am using spring cloud gateway Hoxton.M1 release to implement API gateway. I can see logs in below format-

[2019-11-13 18:33:09,432] [448877242] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] Channel connected, now 1 active connections and 0 inactive connections
[2019-11-13 18:33:09,679] [448877489] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] onStateChange(POST{uri=/gateway/api/public/process, connection=PooledConnection{channel=[id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxxx4076.x.x.com/x.x.x.x:5001]}}, [request_sent])
[2019-11-13 18:33:09,880] [448877690] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] onStateChange(POST{uri=/gateway/api/public/process, connection=PooledConnection{channel=[id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:x.x.x.com/x.x.x.x:5001]}}, [response_received])

Also in the access logs I can see below -

x.x.x.x - - [13/Nov/2019:18:33:09 +0800] "POST /x/x/x HTTP/1.1" 200 14895 5556 455 ms

From this it seems -

  1. Downstream took ~ 200 ms
  2. Rest of time i.e. 455 - 200 ~ 255 ms was taken by spring cloud gateway

There are no global filters configured. Also the route is only using rewrite path and add request header filters. Below is the route. It also uses redis rate limiting feature.

      - id: xxxx
        uri: http://xxxxx.xxx.xxx.com:5001
        predicates:
        - Path=/x/x/x
        - Method=POST
        filters:
        - RewritePath=/x/x/x,/gateway/api/public/process
        - AddRequestHeader=xxxxx,yyyyy
        - AddRequestHeader=appid,zzzzz
        - SecureHeaders
        - name: RequestRateLimiter
          args:
            key-resolver: "#{@userRemoteAddressResolver}"
            redis-rate-limiter.replenishRate: 10
            redis-rate-limiter.burstCapacity: 20

When downstream takes only 200 ms, 255 ms taken by spring cloud gateway looks a bit high.

I have given adequate heap memory to the gateway application and in gc analysis I do not see any memory issues.

Any suggestions on how to optimize the gateway performance?

1
Some additional info - App is deployed on RHEL box - Jacob

1 Answers

0
votes

To be perfectly honest I am also having the same issue as you trying to improve the dire performance of the gateway out of the box. I would suggest the first thing to do would be to include Blockhound agent dependency in your pom or gradle file.

This is my gradle dependency compile group: 'io.projectreactor.tools', name: 'blockhound', version: '1.0.2.RELEASE'. Then in the main of the Spring Boot app you can just call Blockhound.install(). This monitors for blocking code anywhere in the gateway.

The next thing I would add is a jvm option -Dreactor.netty.ioWorkerCount=50. This forces netty to use more than the default number of event loop threads. Other options for idle time can be changed as well. In my opinion though, these changes won't work. I think that the Spring Gateway is putting to much of the filter workload on the event loop threads and this is why perf is and will always be bad.