About Connection Pooling

By default the Pivotal.Data.GemFireXD.GFXDClientConnection class and underlying driver maintain a pool of connections to avoid the overhead of repeatedly establishing the same connection over and over again. Any connection strings that match exactly (including the specification of connection pool properties) are assigned and managed from the same connection pool.

If a new connection is created that does not match a previously-created connection, then GemFire XD creates a new pool for that connection, and subsequent requests with the same string may be allocated from the pool.

As connections are closed, they are returned to the pool and may be used again by other threads requesting the exact same connection string. This saves the

By default, the ADO.NET driver maintains a pool of up to 100 connections, and idle connections are terminated after 180 seconds. If all connections in the pool are being used, a new connection request will wait for 15 seconds before receiving a an "All connections are used" exception. Each of these default behavior can be configured using the environment variables described below.

You can configure the behavior of the GemFire XD connection pool by adding properties to the connection string:

Table 1. Connection string properties to configure pooling behavior
Connection string property Description Default
Maximum Pool Size The maximum number of connections maintained in the connection pool. 100
Connection Timeout The maximum number of seconds that a thread will wait to obtain a connection from the connection pool. After this time expires, the thread receives an "All connections are used" exception. 15
Connection Lifetime The maximum length of time in seconds that a connection in the pool can remain idle. The driver automatically terminates idle connections from the pool. 180
The following code sample shows how to configure the maximum pool size in the connection string. Separate multiple properties using a semicolon:
// By default the ado.net driver uses connection pooling. The default max pool
// size is 100, "Connection Lifetime=180" and "Connect Timeout=15". You
// can change the max pool size (or other connection properties) in
// the following way.

const string connString = "Server=10.118.32.97:40409;Maximum Pool Size=50;";
	
using (var conn = new GFXDClientConnection(connString))
{
	// conn.open gets the connection from the pool (or creates one) if available, otherwise it throws 
	// GFXDException("All connections are used.") after "Connect Timeout=15"
	conn.Open();
	using (DbCommand cmd = conn.CreateCommand())
	{
	  cmd.CommandText = "update exampleTable set  REAL_ID = ? where DUMMY_ID = ?";
	  cmd.Parameters.Add(i);
	  cmd.Parameters.Add(i);
	  cmd.ExecuteNonQuery();
	} // Here, it releases resources associated with command            
} // Here, the connection goes into pool

Note that regardless of how many connection pools are created, GemFire XD uses only one thread that wakes every 10 seconds to check for expired connections in all pools. You can change the value of this using the IDLE_TIMEOUT environment variable, but keep in mind that the setting affects all pools that are created.

GemFire XD provides a number of environment variables that affect connection pooling behavior. Note, however, that setting an environment variable applies the change to all available connection pools, and the environment value overrides any property that you supply in the connection string. Use .Net Environment Methods to get or set these variables as necessary for your client application.

Table 2. Connection pool environment variables (apply to all connection pools, and override connection string properties)
Environment Variable Name Description Default
POOL_MAX_CONNECTION The maximum number of connections maintained in the connection pool. 100
CONNECTION_WAIT_TIME The number of seconds that a thread will wait to obtain a connection from the connection pool. After this time expires, the thread receives an "All connections are used" exception. 15
IDLE_TIMEOUT The maximum length of time in seconds that a connection can remain idle. The driver terminates idle threads after this time to free connection in the pool. 180