Tomcat memory usage (PermGen)

我的未来我决定 提交于 2019-12-04 12:19:27

Permgen OOMEs in Tomcat are typically due a combination of two things:

  • Hot redeployment.

  • Memory leaks where some reference causes an old classloader and all of its dependent objects to remain reachable.

Consequently, there are a couple of ways to avoid this problem:

  • Don't do hot redeploys. Or restart every few hot redeploys.

  • Track down and fix the classloader-related storage leaks.

Increasing the permgen size won't prevent the problem, but it is likely to increase the interval between OOME problems. (Or allow you to do a full Tomcat shutdown / restart less often.)


Your question:

1) Is the whole memory used by Tomcat should be 256MB or Tomcat consumes other memory for other reasons ?

See above. It is not specifically Tomcat, though Tomcat is particularly prone to this. (Apparently, Hibernate can be too ... due, I believe, to its use of dynamic proxies.)

2) How can I monitor the memory used by Tomcat to avoid reaching PemGen max size ?

There are ways to monitor memory usage; e.g. attaching an agent. However, these won't prevent the problem. IMO, it would be simpler to change your management procedures for your production server(s) so that you don't need to do hot redeploys.

Tomcat needs to increase permgen not for its own needs but because it can run multiple webapps which all will load their own classes (permgen is mostly for storing classes). You can use jconsole util too see memory usage, go to memory -> chart -> Memory Pool Perm Gen. For my Tomcat 7 which I just started with no user webapps it shows 65M max 6M used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!