简体   繁体   English

在 Node.js Azure 函数应用程序共享 memory 中执行单独的函数吗?

[英]Do separate functions in a Node.js Azure Functions app share memory?

As an example, lets say that an Azure Functions App contains a shared module which provides a global connection pool to some resource:例如,假设 Azure Functions App 包含一个共享模块,该模块为某些资源提供全局连接池:

// connection-pool.js
const pool = /* initialize pool ... */

exports.getPool = () => pool

And two functions within the FunctionsApp that make use of the shared connection pool module: FunctionsApp 中使用共享连接池模块的两个函数:

// fn1/index.js
const pool = require('../connection-pool').getPool()

module.exports = async function (ctx, req) {
  // Do something...
}
// fn2/index.js
const pool = require('../connection-pool').getPool()

module.exports = async function (ctx, req) {
  // Do something...
}

Will there exist 1 or 2 pools within a single instance of the Functions App at runtime? Functions App 的单个实例在运行时是否存在 1 或 2 个池?

The worker for a language starts along with the host in each instance and within the same instance, the loaded modules are in the same memory space.一种语言的 worker 与每个实例中的主机一起启动,并且在同一实例中,加载的模块位于同一 memory 空间中。

Do note that as your function scales, each instance would have its own memory space.请注意,随着 function 的扩展,每个实例都有自己的 memory 空间。 So, this won't work for cases where you want to store any state.因此,这不适用于您想要存储任何 state 的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM