Reputation: 41
I'm attempting to use a Java Servlet, but I end up using all of the system memory and tomcat gets killed by the kernel with the following error:
2018-06-18T17:55:49.238505+00:00 myserver kernel: Out of
memory: Kill process 26117 (java) score 247 or sacrifice child
2018-06-18T17:55:49.238937+00:00 myserver kernel: Killed
process 26117 (java) total-vm:6298824kB, anon-rss:710520kB, file-rss:0kB,
shmem-rss:0kB
2018-06-18T17:55:49.241307+00:00 myserver systemd:
tomcat.service: main process exited, code=killed, status=9/KILL
Sometimes the files that I have to serve to end users are large (~200 MB). If I demand multiple of them, or sometimes only one I get the above crash.
case "xml":
response.addHeader("Content-Disposition","attachment;filename=\"igrfgridData.xml\"");
response.setContentType("text/xml");
String line = "";
while ((line = cResponse.readLine()) != null) {
if(!line.startsWith("comment") && !line.isEmpty())
printWriter.print(line.toLowerCase() +"\n");
}
cResponse.close();
break;
cResponse is a buffered reader from another server. I'm not sure why this should use very much memory at all. The lines are only ever 10's of characters long.
Wrinkle: free -m gives:
total used free shared buff/cache available
Mem: 925 416 73 3 435 323
Swap: 4095 174 3921
Tomcat is running with these memory parameters: -Xmx4096M -Xms4096M -XX:MaxPermSize=1024M -XX:PermSize=1024M
Am I running tomcat with too much memory allocated?
Upvotes: 0
Views: 625
Reputation: 3174
Am I running tomcat with too much memory allocated?
Yes. Your free
command says your system has in all 1G of memory, and you want to run Tomcat with 5G. 4G of swap doesn't help, you just need to increase RAM significantly. Once done, you could reduce both Xmx and MaxPermSize of 50% if you just need to send some files from one buffer to another.
Upvotes: 1