简体   繁体   English

Java Web应用程序的内存消耗(300MB太高了吗?)

[英]Memory consumption for java web app (300MB too high?)

Can I pick your brains about a memory issue? 我可以就记忆问题打动您的大脑吗?

My java app, which isn't huge (like 14000 LOC) is using about 300MB of memory. 我的Java应用程序并不大(例如14000 LOC),使用的内存约为300MB。 It's running on Tomcat with a MySQL database. 它在带有MySQL数据库的Tomcat上运行。 I'm using Hibernate, Spring and Velocity. 我正在使用Hibernate,Spring和Velocity。

It doesn't seem to have any leaks, cause it stabilizes and 300MB, without growing further. 它似乎没有任何泄漏,导致它稳定了300MB,并且没有进一步增长。 (Also, I done some profiling.) There's been some concern from my team, however, about the amount of space it's using. (此外,我进行了一些分析。)但是,我的团队对它使用的空间量有些担心。 Does this seem high. 这看起来很高吗? Do you have any suggestions for ways to shrink it? 您对缩小方法有任何建议吗?

Any thoughts are appreciated. 任何想法表示赞赏。

Joe

The number of LOC is not an indicator of how much heap a Java app is going to use; LOC的数量并不表示Java应用程序将使用多少堆内存; there is no correlation from one to the other. 彼此之间没有关联。

300MB is not particularly large for a server application that is caching data, but it is somewhat large for an application that is not holding any type of cached or session data (but since this includes the webserver itself, 300MB is generally reasonable). 对于正在缓存数据的服务器应用程序,300MB并不是特别大,但是对于不保存任何类型的缓存或会话数据的应用程序,300MB可能会很大(但是由于其中包括Web服务器本身,所以300MB通常是合理的)。

The amount of code (LOCs) rarely has much impact on the memory usage of your application, after all, it's the variables and objects stored that take most of the memory. 代码量(LOC)很少会对应用程序的内存使用产生很大影响,毕竟,存储的变量和对象占用了大部分内存。 To me, 300 megabytes doesn't sound much, but of course it depends on your specific usage scenario: 对我来说,300兆字节听起来并不多,但是当然这取决于您的特定使用情况:

  • How much memory does the production server have? 生产服务器有多少内存?
  • How many users are there with this amount of memory used? 使用的内存量有多少个用户?
  • How much does the memory usage grow per user session? 每个用户会话的内存使用量会增长多少?
  • How many users are you expecting to be concurrently accessing the application in production use? 您预计有多少用户在生产环境中同时访问该应用程序?

Based on these, you can do some calculations, eg. 基于这些,您可以进行一些计算,例如。 is your production environment ready to handle the amount of users you expect, do you need more hardware, do you perhaps need to serialize some data to disk/db etc. 您的生产环境是否已准备好处理您期望的用户数量,是否需要更多硬件,是否可能需要将一些数据序列化到磁盘/数据库等?

I can't make any promises, but i don't think you need to worry. 我无法做出任何承诺,但我认为您不必担心。 We run a couple of web app's at work through Glassfish, using hibernate as well, and each uses about 800-900MB in dev, will often have 2 domain's running each of that size. 我们通过Glassfish运行了几个Web应用程序,同时也使用了休眠模式,每个应用程序都使用约800-900MB的开发资源,并且通常每个大小都有2个域在运行。

If you do need to reduce your footprint, at least make sure you are using Velocity 1.6 or higher. 如果确实需要减少占用空间,则至少要确保使用的是Velocity 1.6或更高版本。 1.5 wasted a fair bit of memory. 1.5浪费了很多内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM