【问题标题】:Google Cloud Storage Upload object using Java API in Google Kubernetes Engine fails on 90 MB file在 Google Kubernetes Engine 中使用 Java API 的 Google Cloud Storage Upload 对象在 90 MB 文件上失败
【发布时间】:2021-07-25 23:09:48
【问题描述】:

我正在使用 Java API 将对象上传到 Google Cloud Storage。当我通过我的本地系统尝试相同的代码时,它工作正常,我能够毫无问题地上传 66MB 和 90MB 的对象。

但是,当我在 GKE pod 中将应用程序部署为微服务后尝试相同的操作时,它会停止响应编写器代码上的 90MB 文件,而只会创建一个 0 字节的文件。虽然它适用于 66MB 对象/文件。 POD 正在从 PersistentVolume 访问文件

这是我用于将对象写入云存储的代码。

try (Stream<String> lines = Files.lines(Paths.get(localPathFileName))) { //path is from persistentvolume

        log.info("read all lines in stream"); //this line prints and after this nothing, no exception
        try (WriteChannel writer = storage.writer(blobInfo)) {
          lines.forEachOrdered(
              line -> {
                try {
                  writer.write(
                      ByteBuffer.wrap(line.concat("\n").getBytes(Charset.forName("UTF-8"))));
                } catch (Exception e) {
                  log.error(
                      "Error while writing lines - " + bucketName + "/" + bucketPath + fileName);
                  e.printStackTrace();
                }
              });
        } catch (Exception ex) {
          log.error(
              "Error while uploading through writer 2 - "
                  + bucketName
                  + "/"
                  + bucketPath
                  + fileName);
          ex.printStackTrace();
        }

我无法理解这里可能出现的问题。因为相同的代码在我的本地系统上运行良好,但在 pod 上却不行。我检查了内存和 CPU 都远低于上限。

当我尝试创建 90 MB 的文件时,它会创建一个 0 字节的文件。 没有抛出异常或错误,即使我试图在每次迭代和之后捕获它。

是否有人对此有任何想法,比如可能是什么问题?

【问题讨论】:

  • 错误信息或异常会给你一个线索。如果没有错误信息或异常,添加更好的错误处理。
  • 没有抛出异常或错误,即使我试图在每次迭代和之后捕获它。
  • 帖子没有足够的细节来得到一个好的答案。尝试使用此guide 为您的服务设置调试器,然后用您的发现更新您的问题。

标签: google-cloud-platform file-upload google-cloud-storage microservices google-kubernetes-engine


【解决方案1】:

我发现了这个问题,它与 jvm 堆大小有关。基本上创建了 20K 个对象,文件大小为 90MB,但内存不足。

我增加了 POD 中的内存大小并且它起作用了。

但我仍然不确定,为什么 POD 没有抛出任何内存不足错误。

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 1970-01-01
    • 2021-04-25
    • 2020-04-04
    • 2014-11-22
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多