0

I have a Tomcat 8 server that frequently runs out of memory. My guess as to what is occurring is that Tomcat does not limit the number of http sessions in memory, so if you get enough users, then the server will eventually run out of memory.

I know you can set a session timeout in your web.xml like so,

<session-config>
        <session-timeout>30</session-timeout>
</session-config>

But that does not help if you get a lot of users in 30 minutes. I searched a lot for some way to limit the number of sessions, but surprisingly did not find much info. Seems like it would be a common issue, as Tomcat by default is guaranteed to run out of memory on high load.

So, how can you set a limit to the number of http sessions, such that Tomcat will expire the oldest when it reaches that limit? That seems like the only logical way to not run out of memory.

James
  • 17,965
  • 11
  • 91
  • 146
  • https://tomcat.apache.org/tomcat-8.0-doc/config/manager.html references a maxActiveSessions parameter... – JP Moresmau Jul 08 '15 at 15:34
  • How many active sessions you have? – Davide Lorenzo MARINO Jul 08 '15 at 15:40
  • 2
    Tip: instead of guessing: Create a heap dump (java_home/bin/jmap) and use a tool such as eclipse MAT to analyze the heap... because... I don't think it's the sessions, as long as there aren't like thousands of sessions and/or the sessions store a really large amount of information... – slowy Jul 08 '15 at 15:43
  • There are thousands on sessions, it only runs out of memory at high load – James Jul 08 '15 at 17:23
  • The question is more "how can tomcat not run out of memory given it has no http sessions limit", if there is no limit, if you get enough users it will run out of memory – James Jul 08 '15 at 17:24
  • any idea how the config maxActiveSessions, like in web.xml or server.xml – James Jul 08 '15 at 17:25
  • also, I don't want it to throw an error, just expire the oldest sessions – James Jul 08 '15 at 17:26
  • surely tomcat must have a way to scale – James Jul 08 '15 at 17:26
  • Did you try @JPMoresmau's suggestion? I'm not sure it will help, since you say that thousands of sessions are *not* the problem. What does a heap dump tell you? – Christopher Schultz Jul 08 '15 at 20:22

1 Answers1

0

Whenever there is an OOM, in my experience its because of poor server configuration, GC issues. A heap dump would reveal more as suggested above, otherwise, it would help to give details of the server (Memory), JAVA_OPTS settings.