FlexyPool

Connection pool monitoring

The FlexyPool library adds metrics and flexible strategies to a given Connection Pool, allowing it to resize on demand. This is very handy since most connection pools offer a limited set of dynamic configuration strategies.

Features

Tutorials

  1. The anatomy of Connection Pooling
  2. FlexyPool, reactive connection pooling
  3. Professional connection pool sizing
  4. The simple scalability equation
  5. How to monitor a Java EE DataSource
  6. How does FlexyPool support the Dropwizard Metrics package renaming
  7. How does FlexyPool support both Connection proxies and decorators

Enter your email address to follow this blog and receive notifications of new posts by email.

Advertisements

11 thoughts on “FlexyPool

  1. Hi vladmihalcea,

    We uses the below connection pools in our application via spring configuration

    1) DB2DataSource
    2) OracleDataSource

    Can we implement flexypool metrics and failover strategies to the above connection pools?
    If so could you please let me know how can I do that?
    I didn’t find any specific doc or example code related to it under flexyool github tutorial or repository?

    does flexy-pool support only below connection pools ?

    ◦Apache DBCP
    ◦Apache DBCP2
    ◦C3P0
    ◦BoneCP
    ◦HikariCP
    ◦Tomcat CP
    ◦Vibur DBCP

    It’s Me

    Privacy
    My Account

    1. You can always use the generic DataSource connection pool that was designed for Java EE. It should work with any DataSource implementation and it will collect all metrics for you. You won;t be able to adjust the pool size using overflow buffer, that being the only limitation.

      If you want to develop a new adaptor, it’s fairly simple. You just have to add a new Maven module, set the Maven dependency and then provide the Adaptor implementation which can set the max pool size and translate the connection acquisition request timeout exception. You can take any other adaptor module as an example, it’s really straight forward.

  2. Greetings vladmihalcia,

    You have a nice tool. I’m trying to use Flexypool to find methods/transactions that hold onto connections too long. Do you have advice about correlating connections that exceed connectionLeaseTimeThresholdMillis with the things they were doing while on-loan?

    I tried implementing a ConnectionLeaseTimeThresholdExceededEventListener and printing a stack trace, but it’s useless because there’s a fair amount of Spring/Hibernate/JPA/AOP magic at work, and all the stack traces are the same. 😦

    It would be excellent to be able to write the SQL executed to the log for any connection that exceeds connectionLeaseTimeThresholdMillis.

    1. But, the connection acquisition is not correlated to the SQL query that comes afterwards. These are two separate mechanisms. You could print the query execution time with datasource-proxy or p6spy, and aggregate all data using ElasticSearch and view it in Kibana. You might want to print the threadId, to make sure that all logs get correlated by thread and time.

  3. I’m thinking that correlating by thread is perhaps the only reasonable way to make this connection.

    I can get query times, and (using your tool) I can see when a connection is out of the pool longer than I wish it was. The thing I’m specifically trying to find in my application is circumstances where a code component leases a connection, executes some SQL, but also does some computationally expensive stuff (not additional SQL) while it’s holding on to the connection.

    My first choice would be to have all this info in one log entry, and only for connections that exceed connectionLeaseTimeThresholdMillis.

    1. Makes sense. Logging all query executions can let you know how much time is spent by executing statements. But you should also take into consideration the fetching phase as well. You could add a timer in your data access logic to measure the duration of the whole data execution.

  4. Hello Mr. Mihalcea,

    I am trying to implement flexy pool with c3p0 connection pool. My flexy pool configuration looks like this.

    <bean id="configuration" factory-bean="configurationBuilder" factory-method="build"></bean>
    
    <bean id="dataSource" class="com.vladmihalcea.flexypool.FlexyPoolDataSource" init-method="start" destroy-method="stop">
        <constructor-arg ref="configuration"/>
        <constructor-arg>
            <array>
                <bean class="com.vladmihalcea.flexypool.strategy.IncrementPoolOnTimeoutConnectionAcquiringStrategy.Factory">
                    <!-- The overflow is a buffer of extra connections allowing the connection pool to grow beyond its initial maximum size -->
                    <constructor-arg value="5"/>
                </bean>
                <bean class="com.vladmihalcea.flexypool.strategy.RetryConnectionAcquiringStrategy.Factory">
                    <!-- for those connection pools lacking a connection acquiring retry mechanism. 2 retry attempts will  be made -->
                    <constructor-arg value="2"/>
                </bean>
            </array>
        </constructor-arg>
    </bean>
    

    I have added following dependencies in my code

    compile group: ‘com.vladmihalcea.flexy-pool’, name: ‘flexy-c3p0’, version: ‘1.2.7’
    compile group: ‘com.vladmihalcea.flexy-pool’, name: ‘flexy-pool-core’, version: ‘1.2.7’
    compile group: ‘com.vladmihalcea.flexy-pool’, name: ‘flexy-dropwizard-metrics’, version: ‘1.2.7’
    compile group: ‘io.dropwizard.metrics’, name: ‘metrics-core’, version: ‘3.1.0’

    I also have slf4j dependency in build.gradle.

    The code is building and deploying without any error, but when I try to accsess histograms using jconsole, I see only JmxMetricReporter, I can not see Codehale CodeMetrics folder.

    Is there anything I am missing?

  5. As explained in the project Installation Guide, you have to set the JMX autoStart and enable JMX as well:

    @Bean
    public Configuration<PoolingDataSource> configuration() {
    	return new Configuration.Builder<PoolingDataSource>(
    			uniqueId,
    			poolingDataSource,
    			C3P0PoolAdapter.FACTORY
    	)
    	.setJmxEnabled(true)
    	.setJmxAutoStart(true)
    	.build();
    }
    
    1. I already have that code in place
      I can see codeHale.JmxMetricReporter on Jconsole, but I am more interested in studying ConnectionRequestHistograms

      This is code in place, is it correct?

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