Karaf
  1. Karaf
  2. KARAF-1019

Set java memory options only when required

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.4
    • Fix Version/s: 2.2.5, 3.0.0
    • Component/s: karaf-core
    • Labels:
    • Environment:

      Windows 2003 @ amd64
      ubuntu-11.10-desktop-amd64
      jdk1.6.0_29 x64

      Description

      Related to https://issues.apache.org/jira/browse/KARAF-818
      Using my x64 environment I got PermGen space error.
      Sure - I can change JAVA_MAX_MEM, JAVA_PERM_MEM, JAVA_MIN_MEM, JAVA_MAX_PERM_MEM variables.
      But I found that without memory settings [1] my scenario works fine.
      Is it possible to set java memory options only if variables are present?

      1. set DEFAULT_JAVA_OPTS=-server -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote

      1. karaf.bat
        9 kB
        Alexey Markevich
      2. karaf
        10 kB
        Alexey Markevich
      3. karaf
        10 kB
        Alexey Markevich
      4. karaf.bat
        9 kB
        Alexey Markevich
      5. patch.txt
        20 kB
        Alexey Markevich

        Activity

        Jamie goodyear made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Jean-Baptiste Onofré made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Jean-Baptiste Onofré added a comment -

        Fixed on karaf-2.2.x: revision 1213215.

        Show
        Jean-Baptiste Onofré added a comment - Fixed on karaf-2.2.x: revision 1213215.
        Hide
        Jean-Baptiste Onofré added a comment -

        Yup, I know Alexey, I saw that

        I gonna fix it now.

        Show
        Jean-Baptiste Onofré added a comment - Yup, I know Alexey, I saw that I gonna fix it now.
        Hide
        Alexey Markevich added a comment -

        In revision #1210651 difference from #1210345: missing
        -set DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -XX:PermSize=%JAVA_PERM_MEM% -XX:MaxPermSize=%JAVA_MAX_PERM_MEM% -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote
        +set DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote

        Show
        Alexey Markevich added a comment - In revision #1210651 difference from #1210345: missing -set DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -XX:PermSize=%JAVA_PERM_MEM% -XX:MaxPermSize=%JAVA_MAX_PERM_MEM% -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote +set DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote
        Jean-Baptiste Onofré made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Hide
        Jean-Baptiste Onofré added a comment -

        karaf.bat doesn't work correctly on Windows.

        Show
        Jean-Baptiste Onofré added a comment - karaf.bat doesn't work correctly on Windows.
        Jean-Baptiste Onofré made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Jean-Baptiste Onofré added a comment -

        Fixed on karaf-2.2.x: revision 1210651.

        Show
        Jean-Baptiste Onofré added a comment - Fixed on karaf-2.2.x: revision 1210651.
        Hide
        Jean-Baptiste Onofré added a comment -

        Fixed on trunk: revision 1210345.

        Show
        Jean-Baptiste Onofré added a comment - Fixed on trunk: revision 1210345.
        Jean-Baptiste Onofré made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Jean-Baptiste Onofré added a comment -

        The latest patch looks good to min. It doesn't cover the admin script, so I use the same behavior in the admin script.

        Show
        Jean-Baptiste Onofré added a comment - The latest patch looks good to min. It doesn't cover the admin script, so I use the same behavior in the admin script.
        Alexey Markevich made changes -
        Labels patch
        Alexey Markevich made changes -
        Attachment patch.txt [ 12504746 ]
        Alexey Markevich made changes -
        Environment Windows 2003 @ amd64
        jdk1.6.0_29 x64
        Windows 2003 @ amd64
        ubuntu-11.10-desktop-amd64
        jdk1.6.0_29 x64
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504722 ]
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504721 ]
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504039 ]
        Alexey Markevich made changes -
        Attachment set_java memory_options_only_when_required_unix.patch [ 12504056 ]
        Alexey Markevich made changes -
        Attachment set_java memory_options_only_when_required.patch [ 12504041 ]
        Hide
        Alexey Markevich added a comment -

        Compromise solution: keep general memory options as is; set PermSize params only if specified.

        Show
        Alexey Markevich added a comment - Compromise solution: keep general memory options as is; set PermSize params only if specified.
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504721 ]
        Alexey Markevich made changes -
        Attachment karaf [ 12504720 ]
        Hide
        Andreas Pieber added a comment -

        I'm against removing those options. Tbh Karaf is different from Tomcat. The possibility to create custom distributions add complete different requirements to Karaf than Tomcat; and those vars, in combination with the setevn files allow a very neat option to configure your app as you like. IF we only remove the default option but still allow the easy configuration via the setenv I'm +/-0; otherwise -1

        Show
        Andreas Pieber added a comment - I'm against removing those options. Tbh Karaf is different from Tomcat. The possibility to create custom distributions add complete different requirements to Karaf than Tomcat; and those vars, in combination with the setevn files allow a very neat option to configure your app as you like. IF we only remove the default option but still allow the easy configuration via the setenv I'm +/-0; otherwise -1
        Hide
        Jean-Baptiste Onofré added a comment -

        Tomcat and Karaf are not the same at all, especially because Tomcat is not OSGi powered, and so don't use an OSGi framework.

        In Tomcat, the memory options are exactly done in the same way as Karaf. Using CATALINA_OPTS is not a good practice, the JAVA_OPTS should be used.

        As in Karaf, it doesn't affect the others Java programs as the JAVA_OPTS is a local variable in the catalina.sh, as in the karaf.sh.

        I'm agree to remove the MaxPermSize (and let the user eventually override it), but not the Xms/Xmx.

        Show
        Jean-Baptiste Onofré added a comment - Tomcat and Karaf are not the same at all, especially because Tomcat is not OSGi powered, and so don't use an OSGi framework. In Tomcat, the memory options are exactly done in the same way as Karaf. Using CATALINA_OPTS is not a good practice, the JAVA_OPTS should be used. As in Karaf, it doesn't affect the others Java programs as the JAVA_OPTS is a local variable in the catalina.sh, as in the karaf.sh. I'm agree to remove the MaxPermSize (and let the user eventually override it), but not the Xms/Xmx.
        Hide
        Glen Mazza added a comment -

        The business case for explicitly setting these memory options in startup scripts is probably very similar for both Karaf and Tomcat, so perhaps the latter's much longer experience might be instructive. From what I can see Tomcat doesn't explicitly set these options, instead the user optionally declares an OS environment variable like so:

        export CATALINA_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m"

        and Tomcat automatically reads those in on startup. (Perhaps most users don't bother making settings such as these until they have a perm gen or other memory error, and then they configure it.) What's also nice with Tomcat is that the memory settings aren't at the JVM-level but just the Tomcat-level instead, i.e., you can start other Java programs and the above settings would be ignored.

        I don't have a strong position on this either way, but should we go with Alexey's preference of not explicitly making these settings it probably wouldn't be that horrifying to the user community, as Tomcat's heavy user base has been accustomed to this for years.

        Show
        Glen Mazza added a comment - The business case for explicitly setting these memory options in startup scripts is probably very similar for both Karaf and Tomcat, so perhaps the latter's much longer experience might be instructive. From what I can see Tomcat doesn't explicitly set these options, instead the user optionally declares an OS environment variable like so: export CATALINA_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m" and Tomcat automatically reads those in on startup. (Perhaps most users don't bother making settings such as these until they have a perm gen or other memory error, and then they configure it.) What's also nice with Tomcat is that the memory settings aren't at the JVM-level but just the Tomcat-level instead, i.e., you can start other Java programs and the above settings would be ignored. I don't have a strong position on this either way, but should we go with Alexey's preference of not explicitly making these settings it probably wouldn't be that horrifying to the user community, as Tomcat's heavy user base has been accustomed to this for years.
        Show
        Alexey Markevich added a comment - One more useful link: http://java.sun.com/performance/reference/whitepapers/tuning.html#section4.1.1
        Hide
        Alexey Markevich added a comment -

        http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

        -XX:MaxPermSize=64m Size of the Permanent Generation. [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.]

        I see two ways:
        1. Detect arch like at https://github.com/Talend/tesb-rt-se/tree/master/talend-esb/src/main/bin
        2. Keep JVM to take care about optimal values.

        Show
        Alexey Markevich added a comment - http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html -XX:MaxPermSize=64m Size of the Permanent Generation. [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.] I see two ways: 1. Detect arch like at https://github.com/Talend/tesb-rt-se/tree/master/talend-esb/src/main/bin 2. Keep JVM to take care about optimal values.
        Hide
        Andreas Pieber added a comment -

        I second JB on that one; IMHO increasing the default values is ways better than removing them (even optionally) and hope that the external setup is correctly to handle the requirements...

        Show
        Andreas Pieber added a comment - I second JB on that one; IMHO increasing the default values is ways better than removing them (even optionally) and hope that the external setup is correctly to handle the requirements...
        Hide
        Jean-Baptiste Onofré added a comment -

        More than removing the default memory options, I would prefer to increase the default MaxPermSize value. Without memory options, it could be really risky with Karaf.

        Show
        Jean-Baptiste Onofré added a comment - More than removing the default memory options, I would prefer to increase the default MaxPermSize value. Without memory options, it could be really risky with Karaf.
        Hide
        Jean-Baptiste Onofré added a comment -

        Thanks for the update Alexey.

        Let me review it and reproduce your issue.

        Show
        Jean-Baptiste Onofré added a comment - Thanks for the update Alexey. Let me review it and reproduce your issue.
        Alexey Markevich made changes -
        Attachment set_java memory_options_only_when_required_unix.patch [ 12504056 ]
        Alexey Markevich made changes -
        Attachment karaf [ 12504055 ]
        Alexey Markevich made changes -
        Attachment set_java memory_options_only_when_required.patch [ 12504041 ]
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504040 ]
        Alexey Markevich made changes -
        Attachment karaf.bat [ 12504039 ]
        Hide
        Alexey Markevich added a comment - - edited

        Some implementation was done using OS detection:
        https://github.com/Talend/tesb-rt-se/tree/master/talend-esb/src/main/bin

        But I prefer to stay without any additional args if they don't specified - Java RT works fine with defaults (at least for me)

        Show
        Alexey Markevich added a comment - - edited Some implementation was done using OS detection: https://github.com/Talend/tesb-rt-se/tree/master/talend-esb/src/main/bin But I prefer to stay without any additional args if they don't specified - Java RT works fine with defaults (at least for me)
        Jean-Baptiste Onofré made changes -
        Fix Version/s 2.2.5 [ 12317857 ]
        Fix Version/s 3.0.0 [ 12316040 ]
        Component/s karaf-core [ 12313724 ]
        Component/s karaf-os-integration [ 12313731 ]
        Hide
        Jean-Baptiste Onofré added a comment -

        I'm gonna try to reproduce your issue (I don't have the problem on Unix).

        More than vanishing the Java memory options, I would prefer to enhance "OS detection" in the karaf script to define the Java options depending of the OS and JVM.

        Show
        Jean-Baptiste Onofré added a comment - I'm gonna try to reproduce your issue (I don't have the problem on Unix). More than vanishing the Java memory options, I would prefer to enhance "OS detection" in the karaf script to define the Java options depending of the OS and JVM.
        Jean-Baptiste Onofré made changes -
        Field Original Value New Value
        Assignee Jean-Baptiste Onofré [ jbonofre ]
        Alexey Markevich created issue -

          People

          • Assignee:
            Jean-Baptiste Onofré
            Reporter:
            Alexey Markevich
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development