简体   繁体   English

“请求被中止,因为没有可用的实例” - Google Cloud Functions(PubSub 触发器)

[英]"The request was aborted because there was no available instance" - Google Cloud Functions (PubSub trigger)

Hey there Overflowers!嘿,溢出者!

I'm working on a small app that triggers a Cloud Function every time a message is published to a PubSub topic.我正在开发一个小应用程序,每次将消息发布到 PubSub 主题时都会触发云函数。 The code inside the function is working (apparentely) fine, but I'm experimenting some issues with the publishing process.函数内部的代码工作正常(显然),但我正在试验发布过程中的一些问题。

For some reason, when posting messages a warning log from the Cloud Function returns: "POST 429 [...] The request was aborted because there was no available instance" .出于某种原因,当发布消息时,来自 Cloud Function 的警告日志返回: “POST 429 [...] The request was aborted because there is no available instance”

I wonder to know what it means and how to deal with it, if anyone could help.我想知道这意味着什么以及如何处理它,如果有人可以提供帮助。 I'm not sure how this can be solved from my code.我不确定如何从我的代码中解决这个问题。

Thanks everyone!谢谢大家!

Edit : The function memory is limited to 256MB, with a 60 secs timeout.编辑:函数内存限制为 256MB,超时 60 秒。

Edit 2 : I've tested removing instances limitations but the service keeps failing (returning a POST 500 or a POST 429 errors).编辑 2 :我已经测试过删除实例限制,但服务一直失败(返回 POST 500 或 POST 429 错误)。

I have another question, my Cloud Functions are returning a timeout sometimes.我还有一个问题,我的 Cloud Functions 有时会返回超时。 I'm pretty sure the origin of the problem is in PubSub, the one metioned before, and these CF corresponds to the failing POST requests.我很确定问题的根源在于之前提到的 PubSub,而这些 CF 对应于失败的 POST 请求。 In the majority of the cases the functions are executed properly and inside the time range.在大多数情况下,函数会在时间范围内正确执行。

My questions: Why these functions are being executed if the message wasn't posted properly at first (maybe it is retried?) and, more important, why these functions are reaching their timeout limit (they shouldn't trigger until a message is published properly, right)?我的问题:如果最初没有正确发布消息(也许重试?),为什么会执行这些函数,更重要的是,为什么这些函数会达到超时限制(在发布消息之前它们不应触发)正确,对)?

Edit 3 : I've been reading the Google Cloud Functions documentation and I've found my problem already documented here: https://cloud.google.com/functions/docs/troubleshooting#scalability编辑 3 :我一直在阅读 Google Cloud Functions 文档,我发现我的问题已经在这里记录: https : //cloud.google.com/functions/docs/troubleshooting#scalability

As Guillaume said (thanks again!) it seems to be a scaling issue.正如纪尧姆所说(再次感谢!)这似乎是一个扩展问题。 The functions are being triggered so fast that they have no enough time to scale instances.这些函数的触发速度如此之快,以至于它们没有足够的时间来扩展实例。 I'm gonna try handling the flow of the incoming messages to be slower while ramping.我将尝试在渐变时处理传入消息的流量,使其变慢。

The notes from this section could help too: https://cloud.google.com/functions/docs/concepts/exec#auto-scaling_and_concurrency本节中的注释也有帮助: https : //cloud.google.com/functions/docs/concepts/exec#auto-scaling_and_concurrency

Note: An extremely rapid increase in inbound traffic can intermittently cause some requests to fail with an HTTP code of 500. This is because the requests are timing out in the pending queue while waiting for new instances to be created.注意:入站流量的极快增加可能会间歇性地导致某些请求失败,HTTP 代码为 500。这是因为在等待创建新实例时请求在待处理队列中超时。 Configuring your workload so that it ramps traffic up gradually over the course of a minute can help with this issue.配置您的工作负载使其在一分钟内逐渐增加流量可以帮助解决此问题。 Also see Troubleshooting Cloud Functions for more information.另请参阅 Cloud Functions 故障排除以获取更多信息。

Thanks again everyone!再次感谢大家!

You have throttled the Cloud Functions creation to 4 instances.您已将 Cloud Functions 创建限制为 4 个实例。 And Cloud Functions can only process 1 request (1 message in your case) at a time.并且 Cloud Functions 一次只能处理 1 个请求(在您的情况下为 1 条消息)。

Therefore, if you have more than 4 messages in the same time in PubSub, you will have this 429 HTTP errors.因此,如果您在 PubSub 中同时有 4 条以上的消息,则会出现此 429 HTTP 错误。

However, it's not a problem if your use case is not time sensitive.但是,如果您的用例对时间不敏感,这不是问题。 Activate the retry in your Cloud Functions deployment, and the message will be retried later on.在您的 Cloud Functions 部署中激活重试,稍后将重试该消息。

If you want that the message is processed ASAP, consider to increase the Cloud Functions max instance limit, or use product that accept parallel processing (Cloud Run and App Engine for instance)如果您希望尽快处理消息,请考虑增加 Cloud Functions 最大实例限制,或使用接受并行处理的产品(例如 Cloud Run 和 App Engine)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 CloudRun 错误“请求已中止,因为没有可用实例” - How to fix CloudRun error 'The request was aborted because there was no available instance' 如何使用PUBSUB作为触发器从Google Cloud函数返回JSON? - How to return a JSON from Google Cloud functions using PUBSUB as trigger? 验证同一项目中Google Pubsub推送的Cloud Functions URL - Authenticating Cloud Functions URLs for Google Pubsub push in same project 如何使用 Google Cloud Functions / Tasks / PubSub 进行批处理? - How to use Google Cloud Functions / Tasks / PubSub for Batch Processing? 如何在 Google Cloud PubSub 上实现请求-响应模式? - How to implement a request-response pattern on Google Cloud PubSub? 如何在可用区域中创建Google Cloud实例? - How to create google cloud instance in available zone? 如何在谷歌云中保存一些规则或配置,然后调用它来处理云函数中的发布订阅主题数据? - How can I save some rules or config in google cloud and then call it to process a pubsub topic data in cloud functions? 在一个项目中触发 Google Cloud function 从另一个项目发布到 Google PubSub - Trigger Google Cloud function in one project on publish in Google PubSub from another project Google Cloud PubSub无法确认消息 - Google Cloud PubSub not ack messages 在谷歌云中使用 PubSub function - Consume PubSub in Google cloud function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM