Click or drag to resize

Connection Pooling

When SphinxConnector.NET connects to Sphinx via the MySQL protocol, it has to perform several initialization steps before it can execute a command. These initialization steps require several network roundtrips in addition to sending the command, and as such impose a certain overhead to every command that is executed. To avoid this overhead, SphinxConnector.NET supports a technique called Connection Pooling.

Concept

The concept of pooling connections to a network resource is pretty simple: When an application uses a connection for the first time, it is initialized normally and the request is send to the network resource. Now, when the application closes the connection, instead of being physically closed, it is returned to a pool which holds on to the connection. The next time a network request is send, the connection from the pool can be used without the overhead of initializing it first. In a high throughput application this provides significant performance improvements.

Connection Pooling in SphinxConnector.NET

Generally, connection pooling in SphinxConnector.NET works exactly as described in the previous section. But, to use pooling effectively one should read the following sections carefully.

Caution note Caution

Connection pooling will only work with Sphinx 1.10.1 and above.

Enabling Connection Pooling

Whether a connection will be pooled, is determined by the connection string option pooling. By default, i.e. nothing is specified in the connection string, pooling is disabled. To enable pooling add "pooling=true" to your connection string. Also make sure that the workers option in your sphinx.conf file is set to a value other than none.

Connection Pool Size

Each connection pool has a minimum and maximum size. These are determined by the connection string options Min Pool Size and Max Pool Size. The default values are 0 for Min Pool Size and 20 for Max Pool Size.

The mininum size option specifies the minimal amount of connections the pool should contain at all times. E.g. for Min Pool Size = 5, the first time a connection is requested from the pool, SphinxConnector.NET will open a new connection and determine that the min pool size is not reached, and open four additional connections.

If a connection is requested and the pool does not contain any available connections, SphinxConnector.NET will open a new connection, unless that would exceed the maximum pool size. If the maximum pool size is reached an exception will be thrown.

One Pool per Distinct Connection String

SphinxConnector.NET maintains one connection pool for each distinct connection string. To determine whether two connection strings are equal, the original, un-altered connection string that was assigned to the SphinxQLConnection instance is used. That means that even an additional space in a connection string can cause more than one pool to be created.

See Also