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:

From: https://cloud.google.com/functions/docs/bestpractices/tips
Note: Several of the recommendations in this document center around what is known as a cold start. Functions are stateless, and the execution environment is often initialized from scratch, which is called a cold start. Cold starts are expensive. It is best practice to avoid unnecessary cold starts, and to streamline the cold start process to whatever extent possible (for example, by avoiding unnecessary dependencies).
You can find some context in https://github.com/firebase/firebase-functions/issues/35
Thanks for stepping in @merlinnot !
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.
- https://stackoverflow.com/a/47985480/1452558
- https://github.com/firebase/functions-samples/issues/170#issuecomment-323375462
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.
Thanks @laurenzlong . Great to hear that tracing is being worked on!
Regarding the original issue, is there agreement on your end that more could be done to improve the performance of Firebase Functions from an infrastructure standpoint? If so, is there at least one public ticket open for tracking progress?
Here's the public tracker for Google Cloud Functions https://issuetracker.google.com/savedsearches/559729
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.
Agreed. One use case for an app we're building is accessing a Facebook Graph API edge without a user access token - which means using our app secret in the server environment to handle the API call. Having a long response time for http function triggers means that we'll probably have to look for a solution elsewhere for this sort of API request.
I think the primary use case for HTTP triggers (and the new callable functions thing) is to have a sort of pseudo-api to handle requests you can't handle in-app. These are sorts of situations in which long response times aren't acceptable. For other functions (onCreate triggers, etc) we aren't requesting a response right a way, so the slightly longer wait isn't as big a deal.
ugh, I've just implemented a relatively straight-forward function triggered from a realtime db update, and it takes SECONDS, some times many. Unusable.
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)
My educated guess would be that you're hitting a load balancer, with X (8'ish I'm guessing) nodes behind it, each with their own execution environment and cold starts (after deployment).
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.
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.
I just updated my function to the node 8 runtime, with 2GB of RAM (even though the GCP web UI says the function only uses 150MB max).
My response times dropped from >10s to around 3 seconds. Still too slow.
I'm seeing this too. It basically denies the basic promise of the whole platform. We accept certain inconveniences, limitations, costs and risks on the assumption that we'll get performance, scaleability and real time features! And when it doesn't deliver, there is very little we can do except move away.
I have hope this is taken seriously and one day will be given the attention, hardware and bandwidth it deserves.
Why not just throw hardware at it for now!
A few days ago, I implemented a sort of complex cloud function that does a lot of calculation based off of the users "history" in a collection. Kind of an audit sort of thing. On a dry run, it takes about 3 seconds from call to response (it's https callable), which is much better than I thought it would be. So it definitely seems that the feature is getting better, but definitely not in the real-time category yet.
Do these tests, if someone serves you. The function returns a simple "hello world" ✌ The first 10 are cold starts. Make your own conclusions.

I'm in Australia and I also find the Firebase console slow. I'm on Telstra FTTN. Here's a speed check

and here's what I get loading the firebase console database tab in Chrome Canary's network waterfall graph with caching disabled in the browser :

It repeatedly takes about 15 seconds to load everything (not counting the ongoing listening request). 16 of the requests take over 500ms, and 4 of them are over 1s.
Is this normal?
@buzzware it's better to report a new issue about slow console loading time. This thread is focused on firebase functions/firestore latency issues.
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 :
- When pinging every minute the issue is perhaps more geographic than due to cold starts. You get good results if you are US based, but can still be regularly over 5s for Singapore and Belgium. Perhaps this explains the complaints here that don't seem to be recognised by the dev team - it doesn't happen from where they are.
- Pinging every 5 minutes gives a worse response (need to investigate further) - probably due to cold starts.
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.