Improving API Response Times by Migrating from Cloud Functions to Cloud Run
unloc.app
unloc.app
I'm pretty sure somewhere north of 80% of load testing tasks play out exactly like this - certainly at least 4 or 5 of these efforts that I've been a part of started with an attempt to get the latest version of JMeter to work ("we should use the mature solution and not reinvent the wheel, right?"), hit major difficulties, and ended up with me cobbling together an ugly but working 100 LoC script that did the job with far fewer headaches than the feature-rich but not really functional Cadillac solutions out there. Apache Bench can do quite a bit in a pinch, and doesn't choke up as quickly as a lot of other ways that you might generate traffic.
Re: Cloud Functions vs. Cloud Run, both are fantastic services and I do tend to prefer Cloud Run lately. For minimizing cold start latency another trick you can use if that's too big a move is to do your function routing within a single global endpoint (obviously this only works for internal-only APIs) - rather than having 100+ endpoints that you hit, you always hit the same endpoint and just include the desired call as a parameter, and route to the correct logic in a few extra lines of code. With all your functionality now passing through the same cloud function call, you're much less likely to incur the cold start penalty on your less frequently called functions, though it comes at the cost of some complexity in code. If you're going through Firebase it also speeds up your deployments quite a bit because you only have 1 function to deploy. Not a silver bullet (and it's also not a good solution if you want a proper REST API, since you're basically forced to jam everything through a POST endpoint), but can be an effective intermediate workaround if going all the way to Cloud Run is too daunting.
https://newscatcherapi.com/blog/google-kubernetes-engine-as-...
[0]: https://cloud.google.com/blog/products/containers-kubernetes...
You can learn the basics of Kubernetes and save around 20-25% compare to use the same Docker Containers but with Cloud Run.
There is a minor cost for one Kubernetes cluster to be run on GCP, but it is negligible if you consider to have some heavy jobs.
[0] https://cloud.google.com/functions/docs/configuring/min-inst...
Functions still only run a single request at a time, while Cloud Run can run as many as the container can handle. We want to build for multiple smaller requests, so when we get ~10k requests incoming in a short timespan it's a lot more useful to have Cloud Run.
I may be mistaken, but I believe cold start is roughly the same for both.
Do you have any idea of where your performance gains are coming from? Is there a lot of async, non-blocking waiting happening in the process of fulfilling requests against your API?
I believe the majority of our performance gain is from having far fewer cold starts during large traffic loads.
Deleted comment
We tried several techniques but by far what got us to reduce response times the most was migrating from Cloud Functions to Google Cloud Run.
We hit some snags when we started requiring a performant API, which is why we don't use Firebase for that any more, although we still use Firestore and a lot of other stuff for the platform.
As every other technology it's choosing what pains you want, and the current Firesbase pains are quite easy to live with.
The promise of Cloud Functions is to give them code and they run it. They should be optimizing how it's run and you shouldn't have to do anything different to optimize performance.
I feel like this is a failure on Google's part.
Does anyone disagree?
On the other hand I can see the appeal of one instance, one request. I don't know if the answer is to enable (optional) request parallelism or to optimize cold start times down further, but OP's requirements feel like they are way too modest to basically force them out of the serverless paradigm.
Functions are used for a lot more than HTTP, we use them for a lot of DB event handling such as post-processing, in which case cold starts does not really matter.
Maybe we'll one day get to a point where the cloud service knows the best way to run our code?
So, it's nothing at all like REST.
> All indicators points to it being a lot of work with little to no reward
That depends what you are doing, but, yes, REST is the wrong solution for lots of problems, but that's not a good reason for calling whatever the non-REST thing is that you’ve chosen to do instead “REST”.
REST is at it's core hypertext as the engine of application state, it is an architectural pattern developed for and as part of the process of refining standards for the WWW; everything else about it is details of how you do HATEOAS. If you aren't doing HATEOAS, you aren't, even approximately, doing REST.