Scaling Connection in Databases using Connection Pooling

Neutrinos
4 min readJun 12, 2020

--

Opening and closing a database connection is quite an expensive operation. When you perform a database connection to read or write data, this is what happens behind the scenes:

  1. The application data layer asks the Data Source for a database connection
  2. The Data Source will use the database Driver to open a database connection
  3. A database connection is created and a socket is opened
  4. The application reads/writes to the database
  5. The connection is closed
  6. The socket is closed

We can easily reduce the number of steps mentioned above to perform a database connection if we use Connection Pooling.

Connection Pooling is well-known a database access pattern that keeps database connections active so that, when a database connection is later requested, one of the active ones are used rather than having to create one from scratch.

A connection pool is a cache maintained to keep database connections open so that they can be reused. Therefore, it reduces the overhead of opening a database connection each time.

The pool maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given database configuration. When you make your first database connection, the connection is saved in the pool. When the next set of database requests are made to the database, the database checks if there are free database connections in the pool, if there are, then it uses these active connections to perform the DB operation. If the active DB connections are in use, then the database creates a new connection if the pool size doesn’t exceed.

If the number of new connections reaches the limit of max connections, the request for Database operation goes into the queue and waits for a free connection instance.

Without database connection pooling, connection to the database takes 35–40 Milliseconds (ms) for each request. With connection pooling, this time is reduced to a mere 1- 2 MS.

Advantages of using Database Connection Pooling

  • Facilitates query processing. Connection pooling makes a single connection with pipelined database requests where requests can be executed simultaneously instead of FIFO manner.
  • Reduces the application and database management system’s overhead of creating and destroying a connection.
  • Reduces the time taken to connect to the database to perform a database operation
  • Saves memory as opening many database connections would have resulted in extensive usage of memory.

Connection Pooling in Neutrinos Platform

When you create an app on Neutrinos Platform, you can integrate your app with any SQL or NoSQL database of your choice using the Platform’s Server Services Designer . This hugely reduces your time and efforts on integration projects and allows you to quickly configure the database and access its data.

While performing connection configuration, the Server Services Designer provides you with options to configure your connection pooling parameters as well.

A few options to configure connection pooling in a SQL database:

A few options to configure connection pooling in a NoSQL database:

You can further add/configure any connection pooling parameter of your choice using the same editor. Thereby scaling your database connection and sending quick responses back to your application.

Connection pooling helps improve the speed of connectivity to the database and reduces the number of resources required to connect to a database. Using the Neutrinos Platform, you can leverage the advantage of connection pooling while performing connection configuration to a database in your app. All the connection pooling parameters are available with pre-populated, default values. You can change the existing configurations on the UI to suit your database requirements and save the settings. The Server Services Designer will handle the connections as designed by you.

Conclusion

To learn more about connection pooling in Neutrinos Platform, see:

Author:

Supriya Ananth
Lead Content Developer and Strategist
Neutrinos

--

--

No responses yet