0
votes

Introduction

I am using the Azure Face API in my Google Cloud Function (I make around 3 or 4 https requests everytime my function is called) but I am getting a really slow execution time, 5 seconds.

Function execution took 5395 ms, finished with status: 'ok'

Function execution took 3957 ms, finished with status: 'ok

Function execution took 2512 ms, finished with status: 'ok

Basically what I am doing in my cloud function is:

1. Detect a face using Azure
2. Save the face in the Azure LargeFaceList
3. Find 20 similar faces using Azure
4. Train the updated Azure LargeFaceList (if it is not being trained already)

I have the Google Cloud Function located in us-central1 ('near' my Azure Sace Service, which is in north-central-us). I have assigned it a memory of 2GB and a timeout of 540 secs. I am in Europe.

Problem

As I said before, the function takes too long to complete its execution (from 3.5 to 5 seconds). I don't know if this is because of the "Cold Start" or because it takes a time to run the algorithm.

Pd: The LargeFaceList currently only contains 10 faces (for 1000 faces the training duration is 1 second, and for 1 million 30 minutes).

My Options

Run the code on:

  1- Google Cloud Function (doing this now)
  2- Google Cloud App Engine

I have been experimenting with cloud functions from the last 3 months, and I have never used the App Engine service.

My Question

Is it possible to use firestore triggers on App Engine? And will I get a faster execution time if I move this code to App Engine?

1
I don't really know the Azure product. What is the step 4 'Train the updated Azure LargeFaceList'? You relaunch a train every time that you have a new face? Is it an Azure API that you call for this training? If so, do you really need to wait the end of the training in the function? (do you need to perform specific action in case of failure?)guillaume blaquiere
@guillaumeblaquiere The product is based on Machine Learning, and for getting similar faces quickly it is necessary to train the model (the list). As I want to do it dinamically, every time a face is added, the code tries (it would not can if the model is currently being trained) to train the LargeFaceList (at the end of the function and without having to wait for the training process completion and handle possible errors). Every single action that involves the Azure API is a HTTPs request.Victor Molina
Also, I can perfectly do the steps 1, 2, 3 during the current model trainingVictor Molina
Thanks for watching my video, but if you understood this it's because my english isn't good!! LOL. So, in fact, you can process only one request on 1 instance of function. If you have 2 requests, Cloud Functions creates 2 instances and each one are processed on only one instance. Thus, if you have 180 concurrent requests you will have 180 function instances in the same time. (up to 1000 instance, default quotas)guillaume blaquiere
Cloud Run runs on the same underlying infrastructure as Cloud Functions, but run containers. On 1 instance of Cloud Run, you can handle up to 80 requests concurrently. Therefore, for 180 concurrent request, you should have 3 or 4 instance, and not 180 as for Cloud Functions. And because you pay the processing time (CPU + Memory), 180 Cloud Functions instances is more expensive than 3 Cloud Run services. I wrote an article on this. Is your question the same with this description?guillaume blaquiere

1 Answers

2
votes

With Cloud Functions, you can process only one request on 1 instance of function. If you have 2 requests, Cloud Functions creates 2 instances and each one are processed on only one instance.

Thus, if you have 180 concurrent requests you will have 180 function instances in the same time. (up to 1000 instance, default quotas)

Cloud Run runs on the same underlying infrastructure as Cloud Functions, but run containers. On 1 instance of Cloud Run, you can handle up to 80 requests concurrently.

Therefore, for 180 concurrent request, you should have 3 or 4 instance, and not 180 as for Cloud Functions. And because you pay the processing time (CPU + Memory), 180 Cloud Functions instances is more expensive than 3 Cloud Run services.

I wrote an article on this.

In summary, serverless architecture are highly scalable and process the request in parallel. Think about the processing time of only one request, not about the max amount of concurrent requests. (So, do it to have a cost perspective)