1

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.

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.

Any suggestions are appreciated!

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
Lech Migdal
  • 3,828
  • 5
  • 36
  • 63

1 Answers1

3

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) => {
      ...
   });
}
Matt Mason
  • 2,676
  • 9
  • 22