简体   繁体   English

GAE 使用的 memory 比我的 Java 应用程序多得多

[英]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.

相关问题 Redshift 设计或配置问题? - 我的 Redshift 数据仓库似乎比我的 mysql 数据库慢得多 - Redshift design or configuration issue? - My Redshift datawarehouse seems much slower than my mysql database Azure 日志分析工作区 - 日志管理生成比预期多得多的数据 - Azure Log analytics workspace - log management generate much more data than expected AWS Lambda - AWS Lambda 为我的函数预配的 memory 分配了多少 CPU? - AWS Lambda - How much CPU does AWS Lambda allocates to my function's provisioned memory? AWS Fargate 集群 - 在容器内运行的 java 进程可以消耗多少任务 memory? - AWS Fargate Cluster - How much task memory can be consumed by java process running inside the container? 无法使用 sendgrid 发送包含超过 2 张照片的 pdf 附件 - Unable to send pdf attachment with more than 2 photos using sendgrid AWS Lambda GitLab CI/CD 部署 package 大小比从我的本地环境部署大得多 - AWS Lambda GitLab CI/CD deployment package size is much bigger than deploy from my local environment 为什么 amazon s3 cli 复制比 java sdk 在同一个桶中复制快得多? - Why amazon s3 cli copy much faster than java sdk in the same bucket? 使用 GAE 服务 HTML 内容 JAVA - Serving HTML content with GAE JAVA 我的 Firestore 中有超过 50,000 个文档,排序和查找的时间超过 30 秒,限制为 50 个。如何加速? - I have more than 50,000 documents in my firestore and it is taking more than 30secs to sort and find in limits of 50. how to speedup? GAE 可以限制我的 websocket 连接吗? - Can GAE restrict my websocket connections?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM