【问题标题】:Why does Appengine image rotation give cache resources error?为什么 Appengine 图片旋转会出现缓存资源错误?
【发布时间】:2023-03-17 08:01:01
【问题描述】:

我使用 Appengine 标准:

basic_scaling:
  max_instances: 7
  idle_timeout: 4m

instance_class: B4_1G

我尝试旋转图像:

def get_image(bucket_name, file_name):   
    blob = storage_client.bucket(bucket_name).get_blob(file_name)
    _, temp_local_filename = tempfile.mkstemp()
    blob.download_to_filename(temp_local_filename)
    with Image(filename=temp_local_filename) as i:
      encoded_image = base64.b64encode(open(i.rotate(125), 'rb').read())
      del i

  gc.collect()    
  return (html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode('utf-8')), style={'height':'400%', 'width':'100%'}))

但我明白了:

 File "/layers/google.python.pip/pip/lib/python3.8/site-packages/wand/resource.py", line 222, in raise_exception
    raise e
wand.exceptions.CacheError: cache resources exhausted `/tmp/tmp0gu_437j' @ error/cache.c/OpenPixelCache/3984

在旋转线上。

【问题讨论】:

  • 请记住,App Engine Standard 将所有文件存储在实例 RAM 中的 /tmp 目录中,因此写入 /tmp 会占用系统内存,如 here 所记录的那样
  • 不是内存错误,而是缺少系统资源来完成任务。你能描述一下失败的图像吗?
  • 这是一个 1MB 的 jpeg。
  • @Lundincast。谢谢,有什么办法增加吗?
  • RAM 取决于您在 app.yaml 文件中定义的 instance class。您已经在使用具有最高可用 RAM 值 (2GB) 的实例类,因为 B8 实例类仅提供更多 CPU 能力。您可以根据并发请求和 CPU 利用率进行扩展。很高兴您通过旋转 90º 解决了这个问题。

标签: python google-app-engine imagemagick wand


【解决方案1】:

i.rotate(125) 给出错误,但是 i.rotate(90) 和 270 一样有效。我只想要 90 度旋转,这样就可以了。

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 2016-09-11
    • 2018-07-08
    • 1970-01-01
    • 2013-04-23
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多