Node.js Azure Functions 应用中的单独函数是否共享内存?



例如,假设 Azure 函数应用包含一个共享模块,该模块提供与某些资源的全局连接池:

// connection-pool.js
const pool = /* initialize pool ... */
exports.getPool = () => pool

以及 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...
}

运行时,函数应用的单个实例中是否存在 1 个或 2 个池?

一种语言的工作线程与主机一起启动 在每个实例中,在同一实例中,加载的模块位于相同的内存空间中。

请注意,随着函数的扩展,每个实例都有自己的内存空间。因此,这不适用于您想要存储任何状态的情况。

最新更新