firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Getting Cold start latency of 5+ seconds even after using the preferRest option for firebase-admin

Open HarshitPersona opened this issue 2 years ago • 8 comments

I was getting a cold start latency of 5+ seconds while using firestore database. I came across this age old issue- https://issuetracker.google.com/issues/158014637 and the solution here- https://github.com/firebase/firebase-admin-node/pull/1901 but even after implementing the solution as mentioned, I am still getting a latency of 5-6 seconds.

"firebase-admin": "^11.8.0" is the only dependencies I have.

Please find below my code snippet- `` const { initializeApp } = require("firebase-admin/app");

const { initializeFirestore } = require("firebase-admin/firestore");

if (!isAlreadyInitialized) {
  const app = initializeApp();
  db = initializeFirestore(app, { preferRest: true });
  isAlreadyInitialized = true;
}

const query = db.collection("apps").where("apiKey", "==", apiKey);

const querySnapshot = await query.get();

`` Do let me know in case of any other queries.

HarshitPersona avatar May 26 '23 12:05 HarshitPersona

@alexander-fenster @lahirumaramba can you please help on this

HarshitPersona avatar May 26 '23 12:05 HarshitPersona

I'm also still seeing slow cold starts (> 5 seconds) after implementing preferRest.

johnnyoshika avatar Jul 11 '23 15:07 johnnyoshika

@johnnyoshika @HarshitPersona have you found the fix? I am also experiencing super slow cold start with Vercel serverless when using the admin sdk

juniorforlife avatar May 08 '24 16:05 juniorforlife

@juniorforlife I had to disable preferRest because of this issue.

johnnyoshika avatar May 09 '24 05:05 johnnyoshika

@johnnyoshika then how do you fix the slow cold start issue? Isn't preferRest supposed to fix it?

juniorforlife avatar May 09 '24 05:05 juniorforlife

@juniorforlife Sadly I'm still living with painfully slow cold starts on some functions. For critical ones, I set a minInstances of 1 or greater to reduce cold starts. On other ones, I have a uptime monitoring service pinging it every minute to keep it warm. They're all costly options 😔

johnnyoshika avatar May 09 '24 06:05 johnnyoshika

it's a shame the firebase team keeps ignoring this problem 😔

juniorforlife avatar May 09 '24 06:05 juniorforlife

I enabled preferRest in my projects again. I'm not getting the ECONNRESET error anymore but the cold start doesn't seem to be any better than before preferRest was enabled. Cold start seems to be > 7 seconds or so.

johnnyoshika avatar May 27 '24 20:05 johnnyoshika