Cloud run vs. Cloud functions determines cloud service cost comparison based on each product’s pricing and limits. The performance of processing is supposed to be equal in both solutions.
The vCPU determines the pricing of cloud function in GHz/s and memory in GB/s. You can adjust the vCPU speed and memory according to the requirement to minimize cost. But you cannot reduce them separately because both are linked to each other. You need to increase or decrease the memory and vCPU together.
Cloud Run depends upon the usage of vCPU. Memory usage of vCPU is measured in GHz/s, while the use of memory is measured in GB/s. It should be rounded off to the nearest hundred microseconds, just like in cloud functions. It is also not possible to use vCPU partially or memory separately. The instance you use will always have a version of vCPU assigned. Memory can be adjusted from 128 MB to 2 GB.
Cloud Run vs. Cloud Functions
An instance can handle a maximum of 80 concurrent requests, and therefore you are only charged when any instance processes a minimum of one request. The network cost is slightly different for cloud functions in the egress free tier, and only one cloud run depends on the network premium tier.
In Europe, North America cloud run is comparatively cheaper as compared to Asian countries. Cloud run can handle only one request per instance, but it allows adjusting the vCPU speed per memory in use. The overall cost of the number of requests remains equal.
You can consider two main cases while making a comparison. The first one is with only one concurrent request and the second with multiple concurrent requests.
Case 1: Concurrent Request
In this case, just one request is considered for processing to compare. Cloud function and cloud run have just one instance up for processing the unique request, and just one instance is charged. To make this happen, we need to set the currency to 1 in case of a cloud run. Therefore in this condition, performance and pricing are the same with cloud function and cloud run.
Case 2: Multiple Concurrent Requests
Mostly multiple requests are handled by a service at the same time. Cloud run can handle up to 80 multiple requests with the help of one instance. In contrast to this Cloud function creates many instances in the form of concurrent requests. That means if you are processing many requests concurrently, Cloud run service will be cheaper.
Which one to choose?
The selection depends on your choice of cost optimization, your specific needs, and your usage.
1. Low Latency
You can choose a cloud to run if your goal is the lowest latency. You can choose a memory size from 128 MB to 2GB. In the case of vCPU, always 1 vCPU is used by a cloud run. If your goal is to achieve the best processing performance, you can choose a cloud function. You will need 2GB of memory and a 2.4 GHz CPU. If the footprint of memory is low in your case, then using 2 GB of memory is nothing but an unwanted expense.
2. Minimum Cost
It is normally not recommended to compromise on quality and cost, but it always varies from business to business as cutting the cost can reduce your customer satisfaction. The Cloud usage in cloud function and Cloud run is almost 100ms. If the processing time is less than 100ms for one request, then the cloud function is economical.
Cloud function vCPU can be slowed down. The duration of processing can be increased under the limit of 100ms. If you know smart ways to use it, then cost can be optimized directly, reducing the total amount you pay. This means that if you make cloud function ten times less in cost, your clients will have to wait ten times more, and this comparison of rising stands true just in case we have sequential requests.
For example: if we have ten simultaneous requests, the cloud function will cost less. In this case, the cloud run is handling 81 concurrent requests at the same time before creating a new instance.
On the other hand, if a cloud function takes care of multiple requests on separate instances, you will have to pay for every instance and pay extra for every created instance. In another case, the cost of cloud function is comparatively less, and we can slow down the vCPU: when an application is making calls to API, and it is waiting for a return response. For this purpose, we will need a cloud function with 200mhz. Using a full vCPU of cloud run is an unwanted expenditure for this purpose.
3. Limitation of instance
A maximum number of instances in parallel are limited to 1000 for each product and quota page in limitation. We have an option to limit the number of parallel instances by setting up a custom upper bound. Limiting resource usage is a great way to optimize the upper bound of our services to reduce expenses, but it may negatively impact customers’ satisfaction.
4. Handling events
You can trigger the cloud function with the help of an HTTP request. These are called HTTP functions. It can also be done with the help of event triggers in the cloud environment of vendors like Google. On the other hand, a container of Cloud run can be accessed only with the help of HTTP requests. You can also publish storage events to PubSub topics.
Cost comparison between cloud and cloud function as we see goes further than simply comparing the cost. It is recommended to use solutions altogether to take advantage of the capabilities and strengths of your project. Cloud recommended for development is cloud run because of its testability and portability, and openness on the libraries.
If you want to get similar isolation levels in the cloud function, it can be achieved by simply setting the current parameter to one. In a cloud run, it is applied on every container irrespective of the languages and used binaries. You can still choose cloud function because of vCPU capability, but you will not like to do this because of its cost.