firebase-functions: Slow execution of (simple) functions
Version info
firebase-functions: 0.8.0
firebase-tools: 3.16.0
firebase-admin: Currently not in use.
Test case
I have just created a simple cloud function:
exports.sayHelloToUser = functions.https.onRequest((req, res) => {
return res.send("That's a test.");
});
Steps to reproduce
Just create the function - deploy - test. You can even test my function via the url: https://us-central1-fnx-pbox.cloudfunctions.net/sayHelloToUser
Were you able to successfully deploy your functions?
Yes.
Expected behavior
Due to the fact that the function basically returns a simple string, I expect to get a response within a few milliseconds. I know that firebase-functions is currently in beta, but I think the execution time, especially of simple functions, shouldn’t be that long.
Actual behavior
It depends - sometimes I am getting the response instantly, sometimes I am getting the response after seconds (!!!). Why is there such a high fluctuation?
Log:
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 63 (9 by maintainers)
I’m also encountering a terrible response time from Firebase Functions, the simple “Hello World” example is taking around 2 seconds to respond on average. This makes the platform absolutely unusable in production. Is there any optimizations that we can do to improve it?
The idea behind Firebase Functions looks amazing, we would definitely want to use it in our next project, but performance issue raises very serious concerns right now.
Also, the response time is very unstable. Sometimes it’s 2s, sometimes it’s 200ms and it fluctuates randomly.
This answer isn’t good enough. If the delay was only due to cold start, then you’d expect to see subsequent calls be performant. That’s simply not the case.
Furthermore, the documentation linked by @merlinnot is for GCP Cloud Functions. Since Firebase Functions appear to be a rebranded (and possibly watered-down) version of Cloud Functions, it’d be useful to know what the differences are (especially performance differences).
The Firebase Functions logs lack the debugging tools that developers need to diagnose performance issues on their own. While they can be viewed in the more advanced GCP Logging console, there does not appear to be any detailed Trace capabilities like there are for other GCP offerings.
Edit: Here are some other discussions w/ workarounds which indicate that there are performance improvements that need to be implemented on GCP’s end. If developers are spending time on these kinds of hacks and seeing 2-3x performance boosts, it seems like a platform issue.
I can second what @enzomd said. I even wrote a little cron job that pings my function every minute. Despite some 3 seconds wait time, the majority of waiting time for requests still seem very random, averaging at 10-15 seconds. Even the engineering manager for React agrees with us.
I have interacted with a few people at the Firebase team (on SO) and from email support. Based on the replies, I think the team should really face/tackle this issue, instead of just telling us that we need to improve our codebase, or that this is just a trade off.
Firebase is really an amazing platform, and I’m really thankful for the people behind it, so please don’t take my comments as criticizing. I simply want the best for Firebase and I really hope the team could eventually solve this issue and make it an even better platform.
From: https://cloud.google.com/functions/docs/bestpractices/tips
You can find some context in https://github.com/firebase/firebase-functions/issues/35
ugh, I’ve just implemented a relatively straight-forward function triggered from a realtime db update, and it takes SECONDS, some times many. Unusable.
Slow response times happen on every request for me also - its not the “cold start” issue.
I think this issue should be reopened, and only closed when response times are acceptable.
I have a function that sends a few network requests to Firestore, some requests take over 10 seconds.
This is now an issue for my client. I thought I’d try pinging my firebase app server regularly to keep it awake and monitor the response time. Its great to see StackDriver does this (StackDriver is a hidden gem I’m finding).
I created a heartbeat function that simply tries to get a non-existant record from firestore (to wake it up) then returns {success: true} as json.
Attached are the graphs, highlighting different client locations.
Conclusions :
BTW, I regularly see 5 to 10s in occasional use from Western Australia, perhaps including a cold start. We are very close to Singapore, in fact some of our backbone traffic comes from there.
Thought : Pinging one function in the app doesn’t necessarily keep all functions in a project awake. Functions could be deployed on different servers in different datacenters. Perhaps each function could look for a special KeepWarm header that causes it to do nothing. Then I could ping certain critical functions.
Do these tests, if someone serves you. The function returns a simple “hello world” ✌ The first 10 are cold starts. Make your own conclusions.
@buzzware it’s better to report a new issue about slow console loading time. This thread is focused on firebase functions/firestore latency issues.
Hey @erichiggins we share the same infrastructure as Google Cloud Functions so the performance characteristics are the same. Everything on that page applies.
We are aware that lack of advanced trace capabilities is a concern, and we are actively working on it.
By combining @buzzware’s StackDriver suggestion and writing a lazy loading function, I managed to get most functions to execute in under a second. Thanks! Here’s the function I use for anyone who’s interested:
Usage eg:
exports.createCategory = hotloadFunction('createCategory', 'categories', 'create');
It assumes functions are stored in./$moduleName.js
, so tweak accordingly.@stevebrush It was closed in January. That is a good question, but right now my only issue is the speed with a couple of low traffic sites in development. It seems to perform ok when under load. My issue above turned out to be the DNS.
Can anyone else comment on performance under load? Hopefully I’ll have something to report in coming months.
@couchfault really works without side effects?
After emails with @mbleigh I’ve made this test project https://github.com/buzzware/latency-test-us hosted at https://latency-test-us.firebaseapp.com and set up stack driver to monitor index.html (on FB Hosting), heartbeat?database=true and heartbeat?database=false. I did a quick test with https://www.webpagetest.org eg. https://www.webpagetest.org/result/181104_7X_6f1c3dcd8e83dbdba2dd7c114cb3058e/ and as he says, the latency there is decent (~600ms) including a database request. The issue may be stackdriver, but I have seen long delays on my projects in Chrome dev tools.
I am a Googler, I’m telling you for certain that the latency you’re seeing on a static file on Firebase Hosting is unexpectedly high, and I’m asking for more details so that I can help find out what’s going on. I’m also doing some of my own analysis, but I can actually go look at specific data to your tests if you give me some more info.
Just trying to help! 👍
It looks like multiple instances of a Function are created at run time. Some of them might be in a cold state but some might be already warmed up. So as many requests you have as lower latency will be (less ~2-3sec fluctuations)
This is still very much an issue. I’ve been working with firebase / node 8 and simple https callable functions querying small firestore collections for documents containing small paragraphs of text takes between 4 and 10 seconds, with some functions occasionally taking upwards of a minute and timing out. None of these functions implement complex logic or large queries, and my firestore database is quite small.
Hi, I’m based out of Melbourne, Australia. Have hosted my web pages with SiteGround (Singapore) and have linked in with a Firestore database. We’re not using Firebase hosting for now. I have a client in Perth, Australia who seems to be having major issues with data loads. The static web pages (hosted in Singapore) load blazingly fast but the data from Firestore takes forever to load - sometimes more than 60 seconds. And there’s just 2 documents in the collection that is being queried. Refreshing the page doesn’t solve the issue - so we can rule out cold starts.
Curious why this issue was closed?