1

I'm running Jenkins on Windows 2016 server with the following defenitions in jenkins.xml:

-Xrs -Xmx2G -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"

But the problem that we get an error:

exception while collecting data: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space  

and the server stuck.
After monitorung the master, we have seen that java heap is 512 and not 2G. How can it be? From the Master monitor screen:

OS: OS Windows NT (unknown), , x86/32 (4 cores)
Java:   Java(TM) SE Runtime Environment, 1.8.0_66-b18
JVM:    Java HotSpot(TM) Client VM, 25.66-b18, mixed mode   The server mode has much better performance than the client mode, you should consider using the server mode if your are not in development
PID of process: 7960
Server: Server jetty/9.2.z-SNAPSHOT
Webapp context: 
Start:  11/28/17 2:15 PM
JVM arguments:  -Xrs
-Xmx2G
-Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle
-Xmx512M
Mean age of http sessions (min):    6
Memory: Non heap memory = 83 Mb (Perm Gen, Code Cache),
Buffered memory = 0 Mb,
Loaded classes = 22,254,
Garbage collection time = 6,007 ms,
Process cpu time = 156,718 ms,
Committed virtual memory = 438 Mb,
Free physical memory = 13,245 Mb,
Total physical memory = 16,383 Mb,
Free swap space = 16,199 Mb,
Total swap space = 19,327 Mb
Dima Kreisserman
  • 663
  • 1
  • 13
  • 33

1 Answers1

3

Please note that you have 2 options -Xmx in the monitor screen.

Beside verifying what's in jenkins.xml file, have a look at environment variable(s) like:

JAVA_OPTS, MAVEN_OPTS or ANT_OPTS.

diginoise
  • 7,352
  • 2
  • 31
  • 39
  • Sorry but I cannot find -Xmx512M defined in my jenkins.xml. I edited this config to run installed x64 installed java and not the default in: c:\java\jdk1.8\bin\java.exe and added -d64 -server to the but still same result :( – Dima Kreisserman Nov 28 '17 at 13:30
  • @DimaKreisserman do you have **JAVA_OPTIONS** defined in your environment? – diginoise Nov 28 '17 at 14:27
  • you are the best! there it was :). Now the question is what is the correct way to define it? should I put the same value in jenkins.xml and JAVA_OPTIONS? what value to put? suppose the VM runs Jenkins only and has 16 G RAM memory. – Dima Kreisserman Nov 28 '17 at 14:36
  • @DimaKreisserman glad you got it sorted! About what to put where, please remember that the JAVA_OPTS took precedence. Was it because it was lower value, or because it got added later? ... and at the end of the day, do you run many other java applications on that box? – diginoise Nov 28 '17 at 15:04
  • This VM runs jenkins only. I've read that java doesn't use heap memory only, so it's wrong to put all RAM memory on -Xmx. What would you suggest? – Dima Kreisserman Nov 28 '17 at 15:14
  • If it's only Jenkins, then it doesn't matter much, which parameter dictates the final size. Regarding heap sizing, there is no simple answer - you have to monitor and see. Have a look at this stackoverflow answer: https://stackoverflow.com/questions/1651225/how-to-choose-the-jvm-heap-size – diginoise Nov 28 '17 at 15:19
  • 1
    I found great article explaining how to tune Jenkins gc: https://jenkins.io/blog/2016/11/21/gc-tuning/ – Dima Kreisserman Nov 28 '17 at 15:57