Cloud Run services by default operate within the first generation execution environment, which features fast cold start times and emulation of most, but not all operating system calls. Originally, this was the only execution environment available to services in Cloud Run.
The second generation execution environment provides full Linux compatibility rather than system call emulation. This execution environment provides:
- Faster CPU performance
- Faster network performance, especially in the presence of packet loss
- Full Linux compatibility, including support for all system calls, namespaces, and cgroups
- Network file system support
During Preview, although the second generation execution environment generally performs faster under sustained load, it has longer cold start times than first generation.
You can specify the execution environment for your Cloud Run service when you deploy a new service or a new revision of your service. If you don't specify an execution environment, first generation is used by default.
How to choose an execution environment
You should use first generation if any of the following apply:
- Your Cloud Run service has bursty traffic, and needs to scale out fast to many container instances.
- Your Cloud Run service has infrequent traffic that causes frequent scale out from zero.
- You want to use less than 512 MiB of memory. The second generation execution environment requires at least 512 MiB of memory.
Note that cold starts are faster in first generation compared to second generation, although second generation will narrow this performance gap by the end of Preview.
You should use second generation if any of the following apply to your Cloud Run service:
- Your service needs to use a network file system, which is only supported by second generation.
- Your service has fairly steady traffic and cold starts are rare.
- Your service has CPU-intensive workloads.
- Your service could benefit from faster network performance.
- Your service needs to use software that has issues running in first generation due to unimplemented system calls.
- Your service needs Linux cgroup functionality.
- To specify an execution environment for your Cloud Run services, refer to Selecting an execution environment.
- To specify memory for your for your Cloud Run services, refer to Memory limits.
- To use Filestore with Cloud Run, refer to Using Filestore with Cloud Run.
- To use Cloud Storage FUSE with Cloud Run, refer to Using Cloud Storage FUSE with Cloud Run.
- To use use network file systems such as NFS, NDB, 9P, CIFS/Samba, and Ceph
with Cloud Run, refer to Using network file systems