FlexyPool, reactive connection pooling

Introduction

When I started working on enterprise projects we were using J2EE and the pooling data source was provided by the application server.

EnterpriseApplicationServer

Scaling up meant buying more powerful hardware to support the increasing request demand. The vertical scaling meant that for supporting more requests we would have to increase the connection pool size accordingly.

Horizontal scaling

Our recent architectures shifted from scaling up to scaling out. So instead of having one big machine hosting all our enterprise services, we now have a distributed service network.

EnterpriseArchitecture

This has numerous advantages:

  • Each JVM is tuned according to the hosted service intrinsic behaviour. Web nodes employ the concurrent low pause collector, while batch services use the throughput collector
  • Deploying a batch service doesn’t affect the front services
  • If one service goes down it won’t affect the rest

Database connection provisioning

But all those services end up calling the database and that’s always done through a database connection. A database server can offer only a limited number of concurrent connections, so connection provisioning is mandatory.

The current connection pooling solutions offer limited monitoring and failover support. This is what we’ve been struggling with lately and that’s why I decided to build FlexyPool.

There’s a new guy in town

FlexyPool is a data source proxy offering better monitoring and failover for the following connection pools:

FlexyPoolArchitecture

We concluded that sizing connection pools is not an upfront design decision. In large enterprise systems you need adaptability and monitoring is the first step to taking the right decisions.

Advance monitoring

Name Description

concurrentConnectionsHistogram

This indicates how many connections are being used at once.

concurrentConnectionRequestsHistogram

This indicates how many connection are being requested at once.

connectionAcquireMillis

A time histogram of the target data source connection acquire interval.

connectionLeaseMillis

The lease time is the duration between the moment a connection is acquired and the time it gets released.

maxPoolSizeHistogram

A histogram of the target pool size.

overallConnectionAcquireMillis

A time histogram of the total connection acquire interval.

overflowPoolSizeHistogram

A histogram of the pool size overflowing.

retryAttemptsHistogram

A histogram of the retry attempts number.

Failover strategies

When all pooled connections are being used, a new connection acquire request will wait for a limited amount of time before giving up. This prevents system overloading but to avoid rejecting connection requests you have to properly configure the connection pool size. You will also have to consider traffic spikes and take into consideration all other services competing for the limited amount of database connections. The monitored data can provide you a better insight into connection usage so you’ll be better equipped when deciding the proper pools size.

FlexyPool was design to be reactive, so it can better adapt to traffic spikes. For this it offers a configurable failover strategy mechanism.

A Strategy is a connection acquiring safety mechanisms, a resort that’s called when a connection is not successfully fetched from the target Connection Pool.

FlexyPool comes with the following default strategies

  • Increment Pool On Timeout

    This strategy will increment the target connection pool maximum size on connection acquire timeout.

    The connection pool has a minimum size and on demand it can grow up to its maximum size. The overflow is a buffer of extra connections allowing the connection pool to grow beyond its initial maximum size. Whenever a connection acquire timeout is detected, the current request won’t fail if the pool hasn’t grown to its maximum overflow size.

    OverFlowPoolSize

  • Retrying Attempts

    This strategy is useful for those connection pools lacking a connection acquiring retry mechanism

Stay tuned. My next article will demonstrate how FlexyPool can assist you finding the right pool size.

If you have enjoyed reading my article and you’re looking forward to getting instant email notifications of my latest posts, you just need to follow my blog.

About these ads

5 thoughts on “FlexyPool, reactive connection pooling

  1. Pingback: The Baeldung Weekly Review 16

  2. Aha, I thought that reactive was meant in the sense of reactive programming. I.e. asynchronous, non-blocking IO-ish. Too bad, that would’ve been awesome, too ;-)

    • Well, I intentionally use it as a catchword, although I meant the “ad litteram” meaning. Most connection pools are simply fail passively during traffic spikes. Being proactive or reactive is a great trait of any enterprise resource.

      • Yes, it is indeed. It’s just that – coincidentally – I had been thinking about reactive (as in reactive programming) connection pools and discussing these things with various people, recently. It would’ve been too big of a coincidence…

      • That would be a great step forward, but it’s very difficult to have both ACID and async non blocking I/O. But there are so many great talents out there who will eventually find a way to do it. For the moment, we try to get the best of what we already have.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s