Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

533
Visualizações
Why does performance degrade when a serverless function exits without completing Promise.all() successfully in Firebase Cloud Function?

Why does performance degrade when a serverless function exits without completing Promise.all() successfully in Firebase Cloud Function?

In the past, I used to run Promise.all() without await in Cloud Function. Then, this would cause the Cloud Function to exit without waiting for Promise.all() to complete. As a result, my Cloud Function sometimes worked correctly and sometimes did not.

This is problem, so we fixed it to await Promise.all() to wait for all the processing to finish.

Then, the Cloud Function, which used to take several minutes to complete, now completes in a few seconds.

I am curious about this issue and would like to understand it. Why is it that when I fix all async process to wait, the function completes immediately?

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's simply the serverless model of Google Cloud. You pay when you process traffic, I mean, when your request is handled.

When you have sent a response, you stop to pay, and so, Google limit the CPU available to your Cloud Functions (about 5% of the CPU available). Indeed, if you don't pay, Google threshold the CPU and propose the processing power to other Cloud Function that handle traffic, and which pays for it.

To free the memory reserved by your cloud functions, after a while (about 15 minutes) Google stop the instance.


So, in your case, if you send the response before the end of the processing, the processing will continue in background with a low percentage of CPU. Either it finishes or it doesn't have the time to finish before the instance stop;

Now, because you await all the promises before sending the response, you have 100% of the CPU power for you (because you pay for it) and you finish quickly the processing.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda