# Operating Mechanism

# Runtime Environment

The cloud function runs in the cloud-based Linux environment1. A cloud function will create multiple cloud function instances when processing concurrent requests. Cloud function instances are isolated from each other without shared memory or disk space. Cloud function instances are created, managed, and terminated automatically by the platform. A 512MB temporary disk space is provided for each cloud function instance under the /tmp directory to process read and write requests for temporary files in a single execution of cloud function. Please note that this temporary disk space may be destroyed after the function is executed, so you should not assume that temporary files stored in the disk space are always available. Use the cloud storage feature for persistent storage.

# Stateless Function

The cloud function should be stateless and idempotent, that is, the execution of a cloud function does not depend on information retained in the runtime environment during the execution of the previous cloud function.

To ensure load balancing, the cloud function platform will control the number of cloud function instances according to the current load condition, and, in some cases, reuse the cloud function instances. This makes it possible for two consecutive cloud function calls run by the same cloud function instance to share the same temporary disk space. However, since the cloud function instance may be terminated at any time and consecutive requests are not always processed by the same instance, the cloud function should not rely on data retained in the temporary disk space during the previous cloud function call. Generally, cloud function code should be stateless.

# Event Model

An event trigger model is used during cloud function calls. Each call made by the Mini Program triggers a cloud function call event, and the cloud function platform creates a new or reuse an existing cloud function instance to process the call event. Similarly, since cloud functions can call each other, such calls also trigger a call event.

# Auto Scaling

The platform will automatically scale the cloud functions according to the load.

# Footnotes

  1. The current runtime environment is CentOS 7.2. Note that, during programming, the code does not depend on a specific operating system or specific operating system version. As the runtime environment may change, the code should be platform-independent.
点击咨询小助手