Spring-boot: Use Tomcat APR connector for performance improvements

Created on 13 Nov 2016  ·  12Comments  ·  Source: spring-projects/spring-boot

In apache tomcat uses apache portable runtime(APR) to provide better performance and scalability with native execution. APR uses system resources and execute natively. If we compare the execution performance BIO , NIO and APR connectors APR provides superior performance.

I have experience the same in my development phase. I created two sets of artifacts which is standalone Jar with spring boot embedded tomcat and spring boot war file and deployed on "tomcat" both are same code base but APR configuration is only difference.

Spring boot by default all the threads execution based on “NIO”, so I have compiled APR libraries based on below link:-

https://tomcat.apache.org/tomcat-8.0-doc/apr.html

Executed Spring Boot Jar file with APR. Now I can see performance results are exactly same.

In our spring boot documentation does not have APR guide to add in embedded tomcat. If we add it will help other developers as well.

documentation

Most helpful comment

It doesn't look like using the APR connector is a good idea because:

However, enabling the use of tomcat-native/APR so the OpenSSL implementation is available to the non-APR connectors is a good idea (see the benchmarks in the aforementioned pdf). Notably, enabling APR also allows for the use of http/2.

All 12 comments

I think @bclozel may have been looking into this a little. It would be nice if we could somehow make this easier.

@philwebb Do you required any information from my side to continue further ?

This is also related to using native libs for TLS support, which is very handy for http/2 support.

Quick questions @PeterJerald:

  • how would you expect to enable those native bindings?
  • how are you adding those libraries to your JVM library path? Are you adding those in a well-known location in your operating system? Or are you using a JVM argument such as -Djava.library.path=/usr/local/lib/?
  • Are you using the native OpenSSL integration as well?

@bclozel Please find below for my answers

How would you expect to enable those native bindings?

If we enable under application common location that help us.

How are you adding those libraries to your JVM library path? Are you adding those in a well-known location in your operating system? Or are you using a JVM argument such as -Djava.library.path=/usr/local/lib/?

Currently I kept along with application and I have added -Djava.library.path path variable in JVM. If we kept under OS also fine.

Are you using the native OpenSSL integration as well?

Yes. By default tomcat native lib(8 +) requires; OpenSSL 0.9.7+, so i have installed in OS

I guess it should work similarly to how netty-transport-native-epoll is detected.

@PeterJerald are there some benchmark results comparing NIO and APR based applications?

https://gist.github.com/andreldm/7f89a3279438467a0bd41e6c1249d014

Please refer above sample program to enable APR in spring boot.

@iNikem we tested with business logic code and compared the results. let me try with sample code

It doesn't look like using the APR connector is a good idea because:

However, enabling the use of tomcat-native/APR so the OpenSSL implementation is available to the non-APR connectors is a good idea (see the benchmarks in the aforementioned pdf). Notably, enabling APR also allows for the use of http/2.

Closing this issue, see https://github.com/spring-projects/spring-boot/pull/10079#issuecomment-326970302.

We will consider tomcat-native for the TLS use case in #10043.

nice

https://gist.github.com/andreldm/7f89a3279438467a0bd41e6c1249d014 - This link seems to be broken. Are there other examples for enabling APR in spring boot

Was this page helpful?
0 / 5 - 0 ratings