[英]GAE using much more memory than my Java application
I have a Java app (Spring Boot) running on Google App Engine;我有一个在 Google App Engine 上运行的 Java 应用程序(Spring Boot); however, I see weird differences between my Java app memory consumption and the dashboard shown by GAE.
但是,我发现我的 Java 应用程序 memory 消费与 GAE 显示的仪表板之间存在奇怪的差异。
In my local machine using a VisualVM I can see it doesn't consume over 100MB even at peak times, and I added a servlet to return the amount of memory used:在我使用 VisualVM 的本地计算机中,我可以看到即使在高峰时段它也不会消耗超过 100MB,并且我添加了一个 servlet 来返回使用的 memory 的数量:
@GetMapping("/")
public String index() {
Runtime rt = Runtime.getRuntime();
long total = rt.totalMemory();
long free = rt.freeMemory();
long used = total - free;
return "Total: " + total / 1024 / 1024 + "MB<br>Used: " + used / 1024 / 1024 + "MB<br>Free: " + free / 1024 / 1024 + "MB";
}
my deployed app in GAE right now returns:我在 GAE 中部署的应用程序现在返回:
Total: 91MB
Used: 69MB
Free: 21MB
at this same time, the GAE dashboard shows it's consuming around 350MB memory dashboard IMG url同时,GAE 仪表板显示它消耗了大约 350MB memory 仪表板 IMG url
Why did that happen?为什么会这样? It forces me to use an F2 instance;
它迫使我使用 F2 实例; if I downgrade to an F1, it keeps failing and restarting.
如果我降级到 F1,它会一直失败并重新启动。
I noticed that once I changed my cronjob from every 30 min to run every 2 min, they started charging me for 40 hours per day in Frontend instances, it was around 16 hours before this change, and I have only 1 instance running.我注意到,一旦我将我的 cronjob 从每 30 分钟更改为每 2 分钟运行一次,他们开始在前端实例中每天向我收取 40 小时的费用,此更改前大约 16 小时,我只有 1 个实例在运行。 How is that possible?
这怎么可能? instance count img url
实例计数 img url
Thank you谢谢
The reason you see these differences is due to the Cloud Console displaying the actual size of the JVM process(which includes stack frames, perm gen space, direct buffers, machine code, etc.) where the memory limit that applies for instances refers to the JVM heap.您看到这些差异的原因是云控制台显示了 JVM 进程的实际大小(包括堆栈帧、perm gen 空间、直接缓冲区、机器代码等),其中适用于实例的 memory 限制是指JVM 堆。 The runtime uses some heap memory which counted against the total heap usage by the app.
运行时使用一些堆 memory,它计入应用程序的总堆使用量。
Now, it is important to understand what do these methods do and how to calculate the available memory to allocate:现在,重要的是要了解这些方法的作用以及如何计算可用的 memory 来分配:
totalMemory() :总内存() :
All memory currently used by JVM. It's usually lower than maxMemory because JVM allocates memory lazily, "lazily" meaning that some memory is allocated initially and used, and, if a new chunk of memory is needed, another allocation is done, up to all available memory (
maxMemory()
).JVM 当前使用的所有 memory。它通常低于 maxMemory,因为 JVM 延迟分配 memory,“延迟”意味着最初分配了一些 memory 并使用,并且,如果需要另一个 85333388 的新块,则全部完成可用 memory (
maxMemory()
)。
maxMemory():最大内存():
Maximum available heap memory (instance size is limited to this value).
最大可用堆 memory(实例大小限于此值)。
freeMemory():免费内存():
Portion of memory currently both allocated by JVM and not used.
memory 的一部分目前由 JVM 分配但未使用。
The "real total memory" that can be allocated is:可分配的“实际总内存”为:
rt.freeMemory() + (rt.maxMemory() - rt.totalMemory())
So there can be more memory available than the output of rt.freeMemory()
.所以可用的 memory 比
rt.freeMemory()
的 output 多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.