首页 > 解决方案 > App Engine 和 Firestore 的内存问题

问题描述

我正在使用Kotlin访问 Firestore 数据库的 Micronaut 开发 MS。当我在本地运行这个 MS 时,我可以让它与 128M 一起工作,因为它非常简单,只需将数据读写到 Firestore,而不是大量数据,像这样的非常小的数据:

{
    "project": "DUMMY",
    "columns": [
        {
            "name": "TODO",
            "taskStatus": "TODO"
        },
        {
            "name": "IN_PROGRESS",
            "taskStatus": "IN_PROGRESS"
        },
        {
            "name": "DONE",
            "taskStatus": "DONE"
        }
    ],
    "tasks": {}
}

我在 App Engine Standard 中的 F1 实例(256 MB 600 MHz)中运行它,并在我的 app.yaml 中使用此属性

runtime: java11
instance_class: F1 # 256 MB     600 MHz
entrypoint: java -Xmx200m -jar MY_JAR.jar
service: data-connector
env_variables:
  JAVA_TOOL_OPTIONS: "-Xmx230m"
  GAE_MEMORY_MB: 128M

automatic_scaling:
  max_instances: 1
  max_idle_instances: 1

我知道处理内存的所有属性都不是必需的,但我拼命地试图完成这项工作,只是尝试了很多解决方案,因为我的第一条错误消息是:

Exceeded soft memory limit of 256 MB with 263 MB after servicing 1 requests total. Consider setting a larger instance class in app.yaml.

下面的错误没有用 中的属性修复app.yaml,但是现在每次我调用 return 时都会JSON收到此错误

2020-04-10 12:09:15.953 CEST
While handling this request, the process that handled this request was found to be using too much memory and was terminated. This is likely to cause a new process to be used for the next request to your application. If you see this message frequently, you may have a memory leak in your application or may be using an instance with insufficient memory. Consider setting a larger instance class in app.yaml.

It always last longer in the first request, I think due to some Firestore configuration, but the thing is that I cannot make that work, always getting the same error.

Do you have any idea what I could be doing wrong or what I need to fix this?

标签: javaperformancegoogle-app-enginegoogle-cloud-firestorejvm

解决方案


TL;DR The problem was I tried to used a very small instance for a simple application, but even with that I needed more memory.

Ok, a friend helped me with this. I was using a very small instance and even when I didn't get the error of memory limit it was a memory problem.

Updating my instance to a F2 (512 MB 1.2 GHz) solved the problem and testing my app with siege resulted in a very nice performance:

Transactions:               5012 hits
Availability:             100.00 %
Elapsed time:              59.47 secs
Data transferred:           0.45 MB
Response time:              0.30 secs
Transaction rate:          84.28 trans/sec
Throughput:             0.01 MB/sec
Concurrency:               24.95
Successful transactions:        3946
Failed transactions:               0
Longest transaction:            1.08
Shortest transaction:           0.09

My sysops friends tells me that this instances are more for python scripting code and things like that, not JVM REST servers.


推荐阅读