PlayFramework memory setting options are not respected - java

I have a Play Framework application that I want to run on production mode but whenever I run activator start -mem 512 or activator start -J-Xms512m -J-Xmx512m I get errors about JVM not being able to allocate enough memory. The odd thing is that error logs indicate that arguments passed on to jvm was:
-Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m -Duser.dir=/home/oguz/dev/rhymo-server/target/universal/s$
but when I print the command information from the activator bash script I get:
java -Dactivator.home=/home/oguz/frameworks/activator-1.2.12 -Xms512m -Xmx512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -jar /home/oguz/frameworks/activator-1.2.12/activator-launch-1.2.12.jar start
It seems that play is running the right command but somewhere along the lines the arguments get discarded. What is wrong here? Am I forgetting something?

I think that you are facing a bug in Activator. You can work around it using JAVA_OPTS:
$ JAVA_OPTS="-Xms512m -Xmx512m -XX:MetaspaceSize=64m" ./activator start
or add an alias to this to your .bashrc/.zshrc. Also you can run activator stage and then start your app using
$ target/universal/stage/bin/YOUR-APP-NAME -mem 512

Related

How to set the -Xmx for JRE when start running JMeter

When running JMeter, java server has the -Xmx value of only 512 MB. I tried to change it via following code in the jmeter.bat.sh file.
set HEAP=-server -Xms512m -Xmx6144m
set NEW=-XX:NewSize=512m -XX:MaxNewSize=6144m
also tried this:
set HEAP= -Xms512m -Xmx6144m
set NEW=-XX:NewSize=512m -XX:MaxNewSize=6144m
By checking the process after while JMeter is running I can see that java -sever doesn't recognize this setting.
If you are running jmeter startup script on Linux the syntax will be different, i.e:
HEAP="-Xms512m -Xmx6G"
as SET command is something Windows-specific
Alternatively you can define JVM_ARGS environment variable value like:
JVM_ARGS="-server -Xms512m -Xmx6G" && export JVM_ARGS
this way you won't need to edit files and/or restart JMeter.
Finally, you can launch JMeter jar directly like:
java -server -Xms512m -Xmx6G -jar ApacheJMeter.jar
See the following reference material:
Tuning Java Virtual Machines (JVMs)
JMeter Best Practices
9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure

How to increase jvm memory

I want to alter (increase) java memory limit (JRE on windows pc).
I fount following commands everywhere:
-Xms set initial Java heap size
-Xmx set maximum Java heap size
for example -Xmx1024m.
But my Question is where! do I have to enter this command. Sorry for this beginner question. Normally I do not have any contact to java.
If you are using eclipse and try to run standalone java then use vm argument section in run configuration tab .For tomcat or app server in setenv script file put
set JAVA_OPTS=-Xms1024m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=384m
for executable jar
java -Xms1024m -Xmx1024m -jar FILENAME.jar
Those are Arguments for the Virtual Machine that you pass in the command line when you start the app
example:
in the console doing:
java -Xms256m -Xmx1024m HelloWorld
or if you are in eclipse (or any other ide)

Running multiple Java Applications on startup

I currently run these java applications with the following command via root:
java -Xms1G -Xmx1G -jar /var/www/tekkit.socialnetwk.com/tekkit.jar nogui
Although if I close the terminal window those applications close/stop.
Is there anyway to stop this from happening? Either creating it as a service or to start it on boot.
I've tried rc.local but no luck.
I'm running on Ubuntu - Newest.
In the past I have done two things to make a process run after the terminal shuts down... use ampersand to run it in the background and nohup so that it does not get killed by the terminal closing.
nohup java -Xms1G -Xmx1G -jar /var/www/tekkit.socialnetwk.com/tekkit.jar nogui &
EDIT: Here is a great answer that goes into detail. Upvote that answer instead since it is way more complete.

playframework 2.3.x heap size

Is there a way to set -Xmx when i start the application with "./activator start"
I tried (not working):
./activator start -J-Xmx2g
./activator -mem 2048 start
_JAVA_OPTIONS="-Xmx2g" ./activator start
It says
"Picked up _JAVA_OPTIONS: -Xmx2g"
but still not working.
Also tried various values in build.sbt and application.conf - no luck
The only way i could make it work was to use
"stage" and pass -Xmx2g to the generated shell script, which is fine, but it doesn't detach the console.
I think I tried all I found on google but still no luck.
I would like to pass -Xmx to the activator start somehow.
First define an environment variable with your JVM parameters named _JAVA_OPTIONS
export _JAVA_OPTIONS="-Xmx2048m"
and then try the play start or use the activator.
I have found solution. There is some bug in activator shell script, so passing -J-Xmx argument does not remove default mem options. To change mem parameter have a look at your activator script (/usr/local/bin/activator) and have a look how mem parameters are added. Also notice that passing -v argument will print final command to lunch java. Working solution on linux for me is this:
export JAVA_OPTS="-Xmx2700m";activator -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
Examples of not working solution:
_JAVA_OPTIONS="-Xmx2048m";activator -J-Xmx2700m -J-Xms1024m -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-Xmx2700m
-Xms1024m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
Also not working:
activator -J-Xmx2700m -J-Xms1024m -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-Xmx2700m
-Xms1024m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
I think you need to specify both, min and max heap size, try this:
activator -J-Xmx2048m -J-Xms2048m start

Add JBoss 7 server in domain mode to Eclipse

I can add JBoss 7 to eclipse in standalone mode but when i try to add a JBoss 7 server in domain mode the path to the config file is always resolved by Eclipse relative to standalone folder. So if I put in full path to domain.xml it doesn;t like it and if i just put in the file name it tires to resolve it standalone.
Any ideas?
Thanks
w
Not Supported Currently.
Sources: JBoss Community Post & JBoss Issue JBIDE-12161
Not formally supported indeed... but there's a way to start and stop it from Eclipse so that you can enjoy all server logs in the Eclipse console and the start/stop icons. However, You won't be able to benefit from "run as -> run on server" because Eclipse won't identify which server you target among the process server, host controller, and main server instances. Yet, there's a remedy to that too because EAP7 supports a "unmanaged deployment mode" on exploded archives that can target your Eclipse/Maven build directories, allowing you to "refresh" deployed archives with enable/disable commands from JBoss-cli or the JBoss admin console (JBoss won't detect .class changes and trigger class loader reloads... you have to enforce it). Cherry on the cake, if you happen to work with GWT web front end technologies, you can enjoy hot redeployment of your GWT artifacts via the CodeServer in SuperDevMode within a Domain mode server instance...
Here is how to proceed:
I assume you have the JBoss Tools plug in installed in Eclipse
Create a "new server" into the 'Servers' view alike for standalone mode, and create a JBoss that takes the domain as server base dir and domain.xml as configuration file. Fill the rest and save it. As such, this server won't start properly.
select the just created server and right-click 'open'. In the Overview panel that fills the main Eclipse Window, click on the underlined "open launch configuration" link
You need to adjust the launch configuration to match the actual launch made by the domain.bat / domain.sh. So you'll need to update the long Program and VM arguments as explained below. Please, edit all paths strings illustrated below to match that of YOUR environment, e.g. "/jBOSS/EAP70/domain" may become "/projects/jb/as7/domain" in your context... and so forth
DO NOT forget to check OUT the option 'Always update arguments related to the runtime'
Program arguments:
-mp "C:/jBOSS/EAP70/modules" org.jboss.as.process-controller -jboss-home "C:\jBOSS\EAP70" -jvm "C:\java\JDK8U66\jre\bin\java" -mp "C:/jBOSS/EAP70/modules" -- "-Dorg.jboss.boot.log.file=C:/jBOSS/EAP70/domain/log/boot.log" "-Dlogging.configuration=file:/C:/jBOSS/EAP70/domain/configuration/logging.properties" -Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server -- -default-jvm "C:\java\JDK8U66\jre\bin\java"
VM arguments:
-Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server "-Dorg.jboss.boot.log.file=C:/jBOSS/EAP70/domain/log/boot.log" "-Dlogging.configuration=file:/C:/jBOSS/EAP70/domain/configuration/logging.properties" -cp "C:\jBOSS\EAP70\jboss-modules.jar" -Djboss.home.dir=C:/jBOSS/EAP70 -Djboss.bind.address.management=localhost
Working Directory: C:/jBOSS/EAP70/bin (of course you adapt values to equivalent paths in your context)
Main class: org.jboss.modules.Main
Classpath: (bootstrap) JRE system Library + (user entries) jboss-modules.jar
And you have done. Note that for stopping the server, the Servers' view red stop button will not work and you must instead use the similar-looking red button in the Console view (that kills the live java process launched in the console, here the JBoss process controller that in turn stops everything).
If you are curious to understand where the trick is...(continue reading)
In the long java command line, there is a separation around the main java class to launch, where "VM arguments" stand on the right of it, and "program arguments" on the left of it. You may capture the actual complete java command line that launches your server in domain mode with a tool like Microsoft sysinternals' process-explorer on Windows, or the "ps -eaf" or "pargs" shell command in LINUX/UNIX, after you have started jBOSS with domain.bat or domain.sh.
But you will observe here that the java command takes a "-jar module.jar" argument whereas Eclipse launch requires a conventional "-cp module.jar main-class" argument form. the '-jar' argument is indeed a variant spec where the main class is specified by the manifest file inside the jar.
In my case, the (very long) command line I captured from a classical domain.sh or domain.bat launch was:
C:\jBOSS\EAP70\bin>"C:\Program Files\Java\jre1.8.0_66\bin\java" -Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server "-Dorg.jboss.boot.log.file=C:\jBOSS\EAP70\domain\log\process-controller.log" "-Dlogging.configuration=file:C:\jBOSS\EAP70\domain\configuration/logging.properties" -jar "C:\jBOSS\EAP70\jboss-modules.jar" -mp "C:\jBOSS\EAP70\modules" org.jboss.as.process-controller -jboss-home "C:\jBOSS\EAP70" -jvm "C:\Program Files\Java\jre1.8.0_66\bin\java" -mp "C:\jBOSS\EAP70\modules" -- "-Dorg.jboss.boot.log.file=C:\jBOSS\EAP70\domain\log\host-controller.log" "-Dlogging.configuration=file:C:\jBOSS\EAP70\domain\configuration/logging.properties" -Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server -- -default-jvm "C:\Program Files\Java\jre1.8.0_66\bin\java"
which breaks as follows:
JAVA_COMMAND>> "C:\Program Files\Java\jre1.8.0_66\bin\java"
followed by
VM_ARGS_____>> -Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server "-Dorg.jboss.boot.log.file=C:\jBOSS\EAP70\domain\log\process-controller.log" "-Dlogging.configuration=file:C:\jBOSS\EAP70\domain\configuration/logging.properties"
followed by:
MAIN_CLASS__>> -jar "C:\jBOSS\EAP70\jboss-modules.jar"
whose equivalent is rewritten (peeking into the manifest of jboss-modules.jar):
MAIN_CLASS__>> -cp "C:\jBOSS\EAP70\jboss-modules.jar" org.jboss.modules.Main
followed by final chunk:
PROGRAM-ARGS>> -mp "C:\jBOSS\EAP70\modules" org.jboss.as.process-controller -jboss-home "C:\jBOSS\EAP70" -jvm "C:\Program Files\Java\jre1.8.0_66\bin\java" -mp "C:\jBOSS\EAP70\modules" -- "-Dorg.jboss.boot.log.file=C:\jBOSS\EAP70\domain\log\host-controller.log" "-Dlogging.configuration=file:C:\jBOSS\EAP70\domain\configuration/logging.properties" -Xms64M -Xmx512M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -server -- -default-jvm "C:\Program Files\Java\jre1.8.0_66\bin\java"
From the point you understand this quite surprising program argument section that replicates many of the VM aguments (because the launched process controller has to invoke the server JVM with these args...), you can then map the pieces in Eclipse server launch configuration.

Categories

Resources