How to run spring boot fat jar with minimal memory?

Śhāhēēd

Here is our maven MediSpan project. Actually it's a REST web service. Its return JSON object for Drug Drug Interaction query through GPI code for a specified patient. Here is an sample of an rest query:

http://localhost:8017/mspn/query?pid=1000&
gpis=83-20-00-30-20-03-10&gpis=64-99-10-02-12-03-20

Here is the structure of our project:

/opt/java/spring/boot/fat/jar/project/chorke─mspn─server/
    ├─ MediSpan.Documents.Monograph.css                   [     1,697 Byte]
    ├─ MediSpan.Documents.Monograph.xslt                  [    35,167 Byte]
    ├─ bitronix-tx-mgr-log-001                            [ 2,097,173 Byte]
    ├─ bitronix-tx-mgr-log-002                            [ 2,097,173 Byte]
    └─ chorke─mspn─server.jar!                            [26,022,610 Byte]
        ├─ medispan/                                      [   443,756 Byte]
        ├─ META-INF/                                      [    33,702 Byte]
        ├─ org/springframework/boot/loader/               [   165,003 Byte]
        ├─ com/chorke/                                    [    27,633 Byte]
        ├─ application.properties                         [       501 Byte]
        ├─ application.yml                                [     2,234 Byte]
        ├─ MediSpan.Foundation.Config.xml                 [    14,939 Byte]
        ├─ MediSpan.Foundation.Text.xml                   [     9,003 Byte]
        ├─ log4j.xml                                      [     2,254 Byte]
        └─ lib/                                           [25,688,056 Byte]
            ├─ aopalliance-1.0.jar
            ├─ btm-2.1.4.jar
            ├─ c3p0-0.9.1.2.jar
            ├─ camel-core-2.15.2.jar
            ├─ camel-jasypt-2.15.2.jar
            ├─ camel-quartz2-2.15.2.jar
            ├─ camel-spring-2.15.2.jar
            ├─ camel-spring-javaconfig-2.15.2.jar
            ├─ chorke-comn-spring-2.0.00-SNAPSHOT.jar     [    11,698 Byte]
            ├─ chorke-mspn-entity-2.0.00-SNAPSHOT.jar     [    13,486 Byte]
            ├─ chorke-mspn-parser-2.0.00-SNAPSHOT.jar     [    15,921 Byte]
            ├─ chorke-mspn-persis-2.0.00-SNAPSHOT.jar     [    23,328 Byte]
            ├─ chorke-mspn-utlity-2.0.00-SNAPSHOT.jar     [    25,684 Byte]
            ├─ commons-lang3-3.3.2.jar
            ├─ commons-logging-1.1.1.jar
            ├─ ehcache-core-2.6.11.jar
            ├─ jackson-annotations-2.4.6.jar
            ├─ jackson-core-2.4.6.jar
            ├─ jackson-databind-2.4.6.jar
            ├─ jasypt-1.9.2.jar
            ├─ javax.transaction-api-1.2.jar
            ├─ jaxb-core-2.2.11.jar
            ├─ jaxb-impl-2.2.11.jar
            ├─ log4j-1.2.17.jar
            ├─ medispan-business-5.1.10.jar
            ├─ medispan-concepts-5.1.10.jar
            ├─ medispan-conditions-5.1.10.jar
            ├─ medispan-documents-5.1.10.jar
            ├─ medispan-interactions-5.1.10.jar
            ├─ medispan-screening-5.1.10.jar
            ├─ medispan-utility-5.1.10.jar
            ├─ mybatis-3.2.8.jar
            ├─ mybatis-ehcache-1.0.2.jar
            ├─ mybatis-spring-1.2.2.jar
            ├─ ojdbc6-11.2.0.3.jar
            ├─ org.apache.servicemix.bundles.cglib-2.1_3_7.jar
            ├─ quartz-2.2.1.jar
            ├─ slf4j-api-1.7.12.jar
            ├─ slf4j-log4j12-1.7.12.jar
            ├─ snakeyaml-1.14.jar
            ├─ spring-aop-4.1.6.RELEASE.jar
            ├─ spring-beans-4.1.6.RELEASE.jar
            ├─ spring-boot-1.2.4.RELEASE.jar
            ├─ spring-boot-actuator-1.2.4.RELEASE.jar
            ├─ spring-boot-autoconfigure-1.2.4.RELEASE.jar
            ├─ spring-boot-starter-1.2.4.RELEASE.jar
            ├─ spring-boot-starter-actuator-1.2.4.RELEASE.jar
            ├─ spring-boot-starter-tomcat-1.2.4.RELEASE.jar
            ├─ spring-context-4.1.6.RELEASE.jar
            ├─ spring-context-support-4.1.6.RELEASE.jar
            ├─ spring-core-4.1.6.RELEASE.jar
            ├─ spring-expression-4.1.6.RELEASE.jar
            ├─ spring-jdbc-4.1.6.RELEASE.jar
            ├─ spring-jms-4.1.6.RELEASE.jar
            ├─ spring-messaging-4.1.6.RELEASE.jar
            ├─ spring-tx-4.1.6.RELEASE.jar
            ├─ spring-web-4.1.6.RELEASE.jar
            ├─ spring-webmvc-4.1.6.RELEASE.jar
            ├─ tomcat-embed-core-8.0.23.jar
            ├─ tomcat-embed-el-8.0.23.jar
            ├─ tomcat-embed-logging-juli-8.0.23.jar
            └─ tomcat-embed-websocket-8.0.23.jar

Here is the command of running this fat jar project and their matrix:

# without setting java option
java -jar chorke-mspn-server.jar

Started BootstrapApplication in 41.824 seconds (JVM running for 42.807)

  • Memory Used: 532,858 kbytes
  • Committed: 751,616 kbytes
  • Max: 1,847,808 kbytes
  • 9502 classes loaded

Working fine.

# setting java option for 1024 MB
java -Xmx1024M -XX:MaxPermSize=768M -XX:+CMSClassUnloadingEnabled \
-jar chorke-mspn-server.jar

Started BootstrapApplication in 42.134 seconds (JVM running for 43.084)

  • Memory Used: 160,016 kbytes
  • Committed: 422,912 kbytes
  • Max: 932,352 kbytes
  • 9505 classes loaded

Working fine.

# setting java option for 512 MB
java -Xmx512M -XX:MaxPermSize=384M -XX:+CMSClassUnloadingEnabled \
-jar chorke-mspn-server.jar

Started BootstrapApplication in 42.385 seconds (JVM running for 43.358)

  • Memory Used: 244,280 kbytes
  • Committed: 463,360 kbytes
  • Max: 465,920 kbytes
  • 9503 classes loaded

Working fine.

# setting java option for 256 MB
java -Xmx256M -XX:MaxPermSize=192M -XX:+CMSClassUnloadingEnabled \
-jar chorke-mspn-server.jar

Started BootstrapApplication in 42.202 seconds (JVM running for 43.174)

  • Memory Used: 244,280 kbytes
  • Committed: 463,360 kbytes
  • Max: 465,920 kbytes
  • 9503 classes loaded

threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause

java.lang.OutOfMemoryError: GC overhead limit exceeded
        at java.lang.Integer.valueOf(Integer.java:642)
        at medispan.foundation.convert.ValueType.asValue(Unknown Source)
        at medispan.foundation.dataaccess.providers.sql.SQLProvider.executeForResults(Unknown Source)
        at medispan.foundation.dataaccess.providers.sql.SQLDataAccessProvider.innerExecuteForCollection(Unknown Source)
        at medispan.foundation.dataaccess.DataAccessProvider.executeForCollection(Unknown Source)
        at medispan.business.dataaccess.BusinessDataAccessManager.load(Unknown Source)
        at medispan.business.dataaccess.QueryPropertyValues.getPropertyValue(Unknown Source)
        at medispan.business.dataaccess.QueryPropertyValues.getInnerValue(Unknown Source)
        more..

This application consist with embedded tomcat server, spring boot, spring mvc, myBatis, apache-camel, bitronix transaction manager, medispan. we wish to run it on 32~128 MB memory. Could you please kind enough to suggest us for running this application with optimal/minimal of memory usage?

BrianC

You need to run a Profiler like JProfile or VisualVM to see what is cosuming memory.

I can tell you right off the bat you are never going to get down to 32MB with all those extra libs in there. Apache Camel alone will probably need at least 256MB to run reliably. And Apache Camel is not something that should be embedded inside a micro service. That is a service your service should call externally. Also using JPA or pretty much any caching will make it hard to get the memory use that low.

I do have some high volume micro services in Spring Boot that run with just 32MB - 64MB but they basically just do though put and some computation. All those extra libs and services will greatly expand your memory usage.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Deploying spring boot fat jar

From Dev

Gradle: Build 'fat jar' with Spring Boot Dependencies

From Dev

Spring boot application is not creating fat (uber) jar

From Dev

spring-boot-maven-plugin doesn't create fat jar

From Dev

Unable to package my Spring boot application as a runnable fat Jar

From Dev

Teamcity - How to run spring boot jar on server after Build and Deploy?

From Dev

Initial amount of memory to run a Spring Boot application

From Dev

Spring DevTools not included in the fat jar packaged with spring-boot-maven-plugin

From Dev

run spring boot with java -jar with tools.jar as dependency

From Dev

run spring boot with java -jar with tools.jar as dependency

From Dev

Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar?

From Dev

Why camel context unable to resolve route inside Spring boot fat jar?

From Dev

How do I run a executable jar file on cloudbees (eg spring-boot)

From Dev

How to run a spring-boot jar with external jars which compile with maven dependency system?

From Dev

How to deal with fat jar dependency

From Dev

spring-boot-starter-ws performance when run as jar

From Dev

I can't run a spring boot jar on windows

From Dev

Not able run Spring boot application as runnable jar from command prompt

From Dev

IntelliJ Spring Boot: How to create an executable jar

From Dev

how to understand spring boot about executable jar

From Dev

Spring Boot + Gradle: how to build executable jar

From Dev

How to modify Spring Boot bootRepackage jar file?

From Dev

how to understand spring boot about executable jar

From Dev

How to build DockerImage from Spring Boot jar

From Dev

How to increase Flink taskmanager.numberOfTaskSlots to run it without Flink server(in IDE or fat jar)

From Dev

How to run a gradle JUnit test job without source files but with a fat jar?

From Dev

how to reduce spring boot memory usage?

From Dev

Spring-boot application can only be launched with spring-boot:run when forking - java -jar fails

From Dev

Spring-boot application can only be launched with spring-boot:run when forking - java -jar fails

Related Related

  1. 1

    Deploying spring boot fat jar

  2. 2

    Gradle: Build 'fat jar' with Spring Boot Dependencies

  3. 3

    Spring boot application is not creating fat (uber) jar

  4. 4

    spring-boot-maven-plugin doesn't create fat jar

  5. 5

    Unable to package my Spring boot application as a runnable fat Jar

  6. 6

    Teamcity - How to run spring boot jar on server after Build and Deploy?

  7. 7

    Initial amount of memory to run a Spring Boot application

  8. 8

    Spring DevTools not included in the fat jar packaged with spring-boot-maven-plugin

  9. 9

    run spring boot with java -jar with tools.jar as dependency

  10. 10

    run spring boot with java -jar with tools.jar as dependency

  11. 11

    Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar?

  12. 12

    Why camel context unable to resolve route inside Spring boot fat jar?

  13. 13

    How do I run a executable jar file on cloudbees (eg spring-boot)

  14. 14

    How to run a spring-boot jar with external jars which compile with maven dependency system?

  15. 15

    How to deal with fat jar dependency

  16. 16

    spring-boot-starter-ws performance when run as jar

  17. 17

    I can't run a spring boot jar on windows

  18. 18

    Not able run Spring boot application as runnable jar from command prompt

  19. 19

    IntelliJ Spring Boot: How to create an executable jar

  20. 20

    how to understand spring boot about executable jar

  21. 21

    Spring Boot + Gradle: how to build executable jar

  22. 22

    How to modify Spring Boot bootRepackage jar file?

  23. 23

    how to understand spring boot about executable jar

  24. 24

    How to build DockerImage from Spring Boot jar

  25. 25

    How to increase Flink taskmanager.numberOfTaskSlots to run it without Flink server(in IDE or fat jar)

  26. 26

    How to run a gradle JUnit test job without source files but with a fat jar?

  27. 27

    how to reduce spring boot memory usage?

  28. 28

    Spring-boot application can only be launched with spring-boot:run when forking - java -jar fails

  29. 29

    Spring-boot application can only be launched with spring-boot:run when forking - java -jar fails

HotTag

Archive