【问题标题】:Azure Functions + Azure SQL + Node.js and connection pooling between requests?Azure Functions + Azure SQL + Node.js 和请求之间的连接池?
【发布时间】:2017-04-05 14:34:52
【问题描述】:

我想知道 - 有没有办法在 Azure Functions (Node.js) 请求之间建立一个 Azure SQL 连接池?

在我的请求运行的总时间中,创建连接占了很大一部分,我想知道如何改进它。

繁琐的网站http://tediousjs.github.io/tedious/getting-started.html 上的所有示例都打开了一个新连接,而据我所见,繁琐的连接池https://github.com/tediousjs/tedious-connection-pool 设计用于在单个请求的整个生命周期中使用单个连接池,而不是在请求。

欢迎提出任何建议!

【问题讨论】:

    标签: node.js azure azure-functions


    【解决方案1】:

    我会选择繁琐的连接池路线 - 它旨在在请求之间使用。

    在你的函数范围之外创建连接池:

    // 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) => {
          ...
       });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-29
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多