Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

[Node.js] HDBEXT - Connection pooling example

0 Likes
2,384

Hello everyone!

We are currently developing a Node.js application using the hdbext driver to connect and execute queries against our HANA database

While the default connection works perfectly, we would like to implement connection pooling to increase our performance.

In the official documentation, the create connection snippet is written as follows:

var hanaConfig = { 
  host : 'hostname', 
  port : 30015, 
  user : 'user', 
  password : 'secret' 
}; 
hdbext.createConnection(hanaConfig, function(error, client) { 
  if (error) { 
    return console.error(error); 
  } 
  client.exec(...); 
}); 

And to use connection pooling, the "hanaConfig" object must contain the "pooling" property with value of true, like this:

var hanaConfig = { 
  host : 'hostname', 
  port : 30015, 
  user : 'user', 
  password : 'secret',
  pooling: true
}; 

Up until this point we can create the connection succesfully. However, to acquire a client from the connection pool, the function "acquire" fails:

pool.acquire(options, function(err, client) {});

Error message says that our "hdbext" object doesn't have that function, neither the client object retrieved from the "createConnection" callback.

Has anyone had the same issue, or have an idea where it originates? Any recommendation for using pooling in Node.js with a HANA database connection?

I'm thankful for any help! Best regards,

Sergio

1 ACCEPTED SOLUTION
Read only

pfefferf
Active Contributor
0 Likes
1,585

How did you create the "pool" object?

From my point of view the documentation is not really up to date. As it can be read in the "migration.md" file of the @sap/hdbext package, for using a connection pool the pooling option should be set to true when creating a connection. Than pooling is used by default. In older versions of the package (<= 4), for pooling first a pool object needed to be created (e.g. via hdbext.getPool) and then call the "acquire" function on that pool object. That is not really necessary anymore in the package versions >= 5.

5 REPLIES 5
Read only

pfefferf
Active Contributor
0 Likes
1,586

How did you create the "pool" object?

From my point of view the documentation is not really up to date. As it can be read in the "migration.md" file of the @sap/hdbext package, for using a connection pool the pooling option should be set to true when creating a connection. Than pooling is used by default. In older versions of the package (<= 4), for pooling first a pool object needed to be created (e.g. via hdbext.getPool) and then call the "acquire" function on that pool object. That is not really necessary anymore in the package versions >= 5.

Read only

0 Likes
1,585

Hi Florian! First of all sorry for the late response.

During the last week we were making performance tests with the pooling option set to true using the 6.0.1 version of the hdbext module. You are right: It is creating a pooled connection and we have no performance loss compared to the hana-client driver, along with its pooled connection.

We didn't create the pool object, we were using the same hdbext library for making the pooled connection, my mistake.

Thank you very much for your help clarifying this matter!

Read only

0 Likes
1,585

Sorry I am still not sure how connection pooling works with @sap/hdbext... Do you need this in every request ?

hdbext.createConnection({...pooling: true }, (err, conn) => {
  if (err) {
    // handle
  } else {
    conn.exec(query, (err, data) => {..});
    conn.close(); // Does this return the connection to the pool ? 
  }
});

Read only

Former Member
0 Likes
1,585

okay got it working after few tries... weird that it doesn't get installed from the first time

Read only

0 Likes
1,023

Hello, how do you use pooling now? Can you show an example?
Thanks!