Java堆空间:内存不足错误 - Google App Engine

时间:2018-04-03 12:13:36

标签: java google-app-engine

我正在使用App Engine Standard,使用Java 8语言。每当我从云存储中读取文件并将其转换为字符串时,我都会收到内存不足的错误。这是片段:

    BlobId blobId = BlobId.of("<Bucket Name>", "<file_name>");  // file size is 19MB
    byte[] content = storage.readAllBytes(blobId);
    String contentString = new String(content, UTF_8); // this is causing the error

这是日志跟踪:

com.google.apphosting.runtime.jetty9.JettyLogger warn: Error for /transform (JettyLogger.java:29) java.lang.OutOfMemoryError: Java heap space 
    at java.lang.StringCoding.decode(StringCoding.java:215) 
    at java.lang.String.<init>(String.java:465) 
    at java.lang.String.<init>(String.java:517) 
    at com.google.apphosting.runtime.NullSandboxPlugin$LogStream.flush(NullSandboxPlugin.java:600) 
    at java.io.PrintStream.flush(PrintStream.java:338) 
    at com.google.apphosting.runtime.NullSandboxPlugin$LogPrintStream.print(NullSandboxPlugin.java:546) 
    at java.io.PrintStream.println(PrintStream.java:806) 
    at com.google.apphosting.runtime.NullSandboxPlugin$LogPrintStream.println(NullSandboxPlugin.java:468) 
    at com.gcds.app.controller.BaseController.doGet(BaseController.java:49) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772) 
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759) 
    at com.google.apphosting.runtime.jetty9.SaveSessionFilter.doFilter(SaveSessionFilter.java:37) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759) 
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759) 
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759) 
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) 
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524) 
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) 
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180) 
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) 
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) 
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) 
    at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:297) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)

有什么办法吗?

1 个答案:

答案 0 :(得分:0)

我有同样的问题。但是,可以通过在appengine-web.xml中使用来解决。我正在使用AppEngine Java SDK。取决于您的情况,AppEngine将为您的应用程序分配必要的实例。

https://cloud.google.com/appengine/docs/standard/java/config/appref

一个问题是它不能应用于本地开发服务器。当我尝试调试当前应用程序时,遇到相同的错误。在Maven构建环境中,做到这一点并不容易。如果使用诸如Eclipse之类的IDE,则可以避免这种情况。就我而言,编辑具有首选内存大小的“调试配置”可以解决此问题。

请找到我的“调试配置”,如下所示 [程序参数]

myDb.table1,myDb.table2

[虚拟机参数]

--allow_remote_shutdown --disable_update_check --no_java_agent D:\workspace\xxxx