问题描述
我想知道-有没有一种方法可以在Azure函数(Node.js)请求之间建立Azure SQL连接池?
I wonder - is there a way to have an Azure SQL connection pool between Azure Functions (Node.js) requests?
创建连接是我的请求运行总时间的很大一部分,我想知道如何改善它.
Creating a connection is a significant chunk of the total time my requests are running and I wonder how to improve it.
乏味网站上的所有示例 http://tediousjs.github.io/tedious/getting-started.html 打开一个新连接,而tedious-connection-pool 我看到的https://github.com/tediousjs/tedious-connection-pool 是为在单个请求的生命周期内而不是在请求之间使用单个连接池而设计的.
All the examples on the tedious website http://tediousjs.github.io/tedious/getting-started.html open a new connection, while tedious-connection-pool https://github.com/tediousjs/tedious-connection-pool from what I can see is designed for using a single connection pool for a lifetime of a single request, not between requests.
任何建议都值得赞赏!
推荐答案
我会走乏味的连接池路由-它被设计为在请求之间使用.
I'd go the tedious-connection-pool route - it's designed to be used between requests.
在功能范围之外创建连接池:
Create the connection pool outside of your function scope:
// created only on first invocation
let pool = new ConnectionPool(poolConfig, connectionConfig);
module.exports = function(context, trigger) {
// runs on every invocation, acquiring a connection from the pool
pool.acquire((err, connection) => {
...
});
}
这篇关于Azure功能+ Azure SQL + Node.js以及请求之间的连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!