Home > Back-end >  what google cloud component to use for my client-server pub/sub?
what google cloud component to use for my client-server pub/sub?

Time:09-17

I'm building an app on google cloud that takes users' audio recording. Users would record 1 or more audio clip and upload them to the the backend, which would process the clips, run Machine Learning prediction model I built and return an integer back to the user for each of the audio that are uploaded. Processing and predicting 1 piece of audio takes about 10 seconds. Users can upload 20 audio at a time.

What I have so far is:

  • HTML, Javascript, css on the client side. The upload functionality is async using fetch and return a promise
  • The backend is running Google AppEngine (python3.7), Firebase Authentication, Google CLoud storage and cloud logging
  • The processing and the prediction is running on Google Cloud Function.

My question is as follow: Since, it might take up to 200-300 seconds for the processing to complete, how should I be handling the task once users hit the upload button? Is simple request-response enough?

I have investigated the following:

  • Google Cloud tasks. This seems inappropriate, because client actually needs to know when the processing is done. There is really no call back when the task is done
  • Google Cloud PubSub. There is a call back for when the job is done (subscribe), but it's server side. This seems more appropriate for server to server communication, instead of client-server.

What is the appropriate piece of tech to use in this case?

CodePudding user response:

There is to way to improve the user experience.

Firstly, on the processing, you can perform parallel processing. All the prediction should be handled by the same Cloud Functions. In App Engine, you should have a multi-thread processing which invoke your CLoud Functions for only one audio clip, and do that 20 time in parallel. I don't know how to achieve that with async in Python, but I know that you can

Then, if you implement that, you will wait all the end of all the audio clip processing to send a response to your users. the total should be between 15 - 20 seconds.

If you use Cloud Run, you can use streaming (or partial HTTP response). Therefore, you could send a partial response when you get a response from your CLoud Functions, whoever the audio clip (the 3rd can be finished before the 1st one).

CodePudding user response:

As you note, Cloud Pub/Sub is more appropriate for server-to-server communication since there is currently a limit of 10,000 subscriptions per-topic/per-project (this may change in the future).

Firebase Cloud Messaging may be a more appropriate solution for client-server messaging.

  • Related