如何在Google Cloud Functions中触发编译后的二进制执行文件?

huangapple go评论86阅读模式
英文:

How to trigger compiled binary execution file in Google Function

问题

目前,我正在使用带有Python的Google Function,对Google OCR(Vision API)的结果进行重构。因此,当前的结构如下所示。

用户使用移动应用程序发送目标图像 -> 触发Google Function -> 将结果发送到移动应用程序。

由于速度相当慢,我正在尝试使用Golang更改该过程。所以这是我的问题。

我认为,尽管我将我的Golang函数部署到Google Functions中,但它并没有被编译。代码在创建实例并运行时进行编译。然而,我希望在用户触发时编译代码并只执行程序。那么我该如何在Google Function中使用编译后的文件呢?

英文:

Currently, I'm using Google Function with python which refactors the result of Goolge OCR (Vision API). So, the current structure is as below.

User sends the target image with mobile application -> Trigger the function in Goolge Function -> Sends the result to mobile application.

Since it is quite slow, I am trying to change the process with Golang. So this is my question.

I think although I deploy my golang function to Google Functions, it isn't compiled. The code is compiled when instance is made and runs. However, I want to compile the code and just execute the program when the user triggers. So how can I use compiled file in Google Function?

答案1

得分: 1

请问你为什么这样认为呢?

> 我认为尽管我将我的 Golang 函数部署到 Google Functions,但它并没有被编译。代码是在实例创建并运行时编译的。

根据我最好的理解,构建发生在部署时,如文档页面构建 Cloud Functions 镜像所述:

> 当您将函数的源代码部署到 Cloud Functions 时,该源代码将存储在 Cloud Storage 存储桶中。然后,Cloud Build 会自动将您的代码构建为容器镜像,并将该镜像推送到容器注册表。

根据您的上下文、要求和预算,可能有一些方法可以提高性能并减少延迟-请参阅 Go 的一次性初始化Cloud Functions 执行环境,特别关注Cold starts部分...

英文:

Can you elaborate please, why do you think so:

> I think although I deploy my golang function to Google Functions, it isn't compiled. The code is compiled when instance is made and runs.

From the best of my understanding, the build happens at the deployment time, as described on the documentation page Building Cloud Functions Images:

> When you deploy your function's source code to Cloud Functions, that source is stored in a Cloud Storage bucket. Cloud Build then automatically builds your code into a container image and pushes that image to Container Registry.

There may be a few ways to improve performance and decrease latency (depending on your context, requirements and budget) - see One-time initialization for Go, and Cloud Functions Execution Environment paying attention to the Cold starts section...

huangapple
  • 本文由 发表于 2021年11月22日 18:39:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/70064447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定