I have a Google Cloud Function written in Node.js, and I would like to run parallel tasks on completely separate processors. Is this possible in Google Cloud Functions?
Additionally, would switching to another language (such as Python or Go) make a difference in terms of achieving parallelism or multithreading within the same function?
The goal is to ensure that tasks do not block or interfere with one another.
I would like to run parallel tasks on completely separate processors. Is this possible in Google Cloud Functions?
Cloud Functions doesn’t change the way the your chosen runtime works. If you’re using JavaScript on nodejs, then you are getting all the capabilities of nodejs. Nodejs happens to be a single-threaded environment for JavaScript, so if you want threading, you’re going to have to bring your own threading by way of some native library for Linux. Again, this is all standard for nodejs, and there is nothing special for Cloud Functions in all this.
Cloud Functions v2 will also handle function invocations concurrently by default, so you get concurrency “for free” under load, up to the capabilities of the server configuration you’ve chosen. However, Cloud Functions was not designed for CPU-heavy workloads at all, so if you are deeply concerned about performance and maximizing the underlying hardware (which you don’t control), then Cloud Functions is not a good choice for your workload.
? Additionally, would switching to another language (such as Python or Go) make a difference in terms of achieving parallelism or multithreading within the same function?
You still get all the same functionality of your chosen runtime. Go happens to be better at native multithreading than either Python or JavaScript, but it’s entirely up to you to benchmark and pick whatever works best for your specific use case.
The goal is to ensure that tasks do not block or interfere with one another.
This is not something you should be concerned about with Cloud Functions. It will scale server instances up and down to meet the load applied to your function. If you don’t like the way Cloud Functions manages this for you, then you shouldn’t use a serverless compute product at all – run your own servers instead to get full control.
I suggest reviewing the documentation on how the runtime works.
The most common approach is to deploy multiple GCF instances. Each instance will run on a separate processor, allowing parallel execution of tasks.
This is ideal for workloads that can be divided into independent tasks that don’t require a shared state.
GCF Concurrency