计算引擎使用 gsutil 下载 tgz 文件有 crcmod 错误

use*_*766 5 google-cloud-storage google-compute-engine

我发现如果你创建一个计算引擎(CentOS 或 Debian)机器并使用 gsutil 下载(cp)一个 tgz 文件会导致一个 crcmod 错误......

$ gsutil cp gs://mybucket/data.tgz .
Copying gs://mybucket/data.tgz...
CommandException:
Downloading this composite object requires integrity checking with CRC32c, but
your crcmod installation isn't using the module's C extension, so the the hash
computation will likely throttle download performance. For help installing the
extension, please see:
  $ gsutil help crcmod
To download regardless of crcmod performance or to skip slow integrity checks,
see the "check_hashes" option in your boto config file.
Run Code Online (Sandbox Code Playgroud)

目前我使用“check_hashes = never”来绕过检查......

$ vi /etc/boto.cfg
[GSUtil]
default_project_id = 429100748693
default_api_version = 2
check_hashes = never
...
Run Code Online (Sandbox Code Playgroud)

但是,根本原因是什么?有什么好的解决办法来解决这个问题吗?

Mik*_*rtz 6

您尝试下载的对象复合对象,这基本上意味着它是以并行块上传的。当上传大于 150M(可配置的阈值)的对象时,gsutil 会自动执行此操作,以提供更好的性能。

复合对象只有一个 crc32c 校验和(没有 MD5),所以为了在下载复合对象时验证数据完整性,gsutil 需要执行一个 crc32c 校验和。不幸的是,随 Python 分发的库不包含编译的 crc32c 实现,因此除非您安装编译的 crc32c,否则 gsutil 将使用非常慢的 crc32c 的非编译 Python 实现。打印该警告是为了让您知道有一种方法可以解决该性能问题:请运行:

gsutil help crcmod
Run Code Online (Sandbox Code Playgroud)

并按照那里的说明安装已编译的 crc32c。这很容易做到,值得付出努力。

另一个注意事项:我强烈建议不要check_hashes = never在您的 boto 配置文件中进行设置。这将禁用完整性检查,这意味着您的下载可能会损坏而您不知道。您希望启用数据完整性检查以确保您使用正确的数据。

  • Robert - 您可以使用 gsutil -o 选项将配置文件参数传递给 gsutil,例如 gsutil -o GSUtil:check_hashes=if_fast_else_fail cp file gs://my-bucket (4认同)