使用boneCP已有一段时间,在我还未到现在公司之前,公司采用的是ProxoolDataSource,在使用ProxoolDataSource过程中,碰到的问题异常之多,我开始怀疑这款开源软件质量本身问题,有一个非常显著的问题就是它的主干代码和文档是2007年之后就未动过,后来慢慢看了主流的DS,包括ProxoolDataSource、BoneCP、Druid(阿里温少开源,最崇拜的人)、C3P0等,经过简单粗暴的性能检测,感觉BoneCP最突出,就在github上clone下代码,然后花了没几天的时间看了源代码,其实没3天时间,主要里面的代码非常容易读,一点都不生涩,感觉跟著者Wallacew相识很久,代码品位有点类似。并不是说其它的开源DS不好,只是当你爱上某一些事情后,你看到更多优点,Sorry,温少。温少的fastjson框架不错的,而且温少人也nice,口音比较重,你跟他说框架中有bug,他会很快给你fix,当然如果你有更好的解决方案,他也会细心接受。
BoneCPDataSource的源代码剖析,我在比较早之前有过说明,它的分区、代理、guava的函数式编程等,把其中一些亮点通过blog的方式已有简短地说明,BoneCPDataSource有一个不好的地方是,它未提供图形化的指标,比如可用的连接、连接超时现象、缓存的命中率等,如果log4j屏蔽,那只能等待何时OOM或者ERROR等不好的现象发生才能够引起重视,之前在项目中就碰到这类蛋疼问题,所以就想能否提供Infographics,刚才说得ProxoolDataSource都能提供一般的可视化,druid的组织做得非常好,兴许他们也是爱美人士(温少看不出来)。
基本的架构和图形化,我已经完成。主要是通过extjs4,对于我而言这是最简单图形化,别鄙视我!!!
没能力玩转CSS+JS,只能依托于extjs 4 graphi。
如果有兴趣的童鞋,我会开源出来,然后我们一起改,当然也要看懂BoneCP,就我个人而言,BoneCP还有一些feature需要处理,我们以branch方式还是自主开源,都是可以吧。
接下来看下现在BoneCP提供的可视化的几个比较重要的指标
/**
* Copyright 2010 Wallace Wadge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jolbox.bonecp;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
/**
* Statistics class.
* @author wallacew
*
*/
public class Statistics implements StatisticsMBean, Serializable{
/**
* uid
*/
private static final long serialVersionUID = -5819368300823149669L;
/** No of cache hits. */
private final AtomicLong cacheHits = new AtomicLong(0);
/** No of cache misses. */
private final AtomicLong cacheMiss = new AtomicLong(0);
/** No of statements cached. */
private final AtomicLong statementsCached = new AtomicLong(0);
/** Connections obtained. */
private final AtomicLong connectionsRequested = new AtomicLong(0);
/** Time taken to give a connection to the application. */
private final AtomicLong cumulativeConnectionWaitTime = new AtomicLong(0);
/** Time taken to execute statements. */
private final AtomicLong cumulativeStatementExecuteTime = new AtomicLong(0);
/** Time taken to prepare statements (or obtain from cache). */
private final AtomicLong cumulativeStatementPrepareTime = new AtomicLong(0);
/** Number of statements that have been executed. */
private final AtomicLong statementsExecuted = new AtomicLong(0);
/** Number of statements that have been prepared. */
private final AtomicLong statementsPrepared = new AtomicLong(0);
/** Pool handle. */
private BoneCP pool;
/** BoneCP handle.
* @param pool
*/
public Statistics(BoneCP pool){
this.pool = pool;
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#resetStats()
*/
public void resetStats(){
this.cacheHits.set(0);
this.cacheMiss.set(0);
this.statementsCached.set(0);
this.connectionsRequested.set(0);
this.cumulativeConnectionWaitTime.set(0);
this.cumulativeStatementExecuteTime.set(0);
this.cumulativeStatementPrepareTime.set(0);
this.statementsExecuted.set(0);
this.statementsPrepared.set(0);
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getConnectionWaitTimeAvg()
*/
public double getConnectionWaitTimeAvg(){
return this.connectionsRequested.get() == 0 ? 0 : this.cumulativeConnectionWaitTime.get() / (1.0*this.connectionsRequested.get()) / 1000000.0;
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getStatementWaitTimeAvg()
*/
public double getStatementExecuteTimeAvg(){
return this.statementsExecuted.get() == 0 ? 0 : this.cumulativeStatementExecuteTime.get() / (1.0*this.statementsExecuted.get()) / 1000000.0;
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getStatementPrepareTimeAvg()
*/
public double getStatementPrepareTimeAvg(){
return this.cumulativeStatementPrepareTime.get() == 0 ? 0 : this.cumulativeStatementPrepareTime.get() / (1.0*this.statementsPrepared.get()) / 1000000.0;
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getTotalLeased()
*/
public int getTotalLeased() {
return this.pool.getTotalLeased();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getTotalFree()
*/
public int getTotalFree() {
return this.pool.getTotalFree();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getTotalCreatedConnections()
*/
public int getTotalCreatedConnections() {
return this.pool.getTotalCreatedConnections();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCacheHits()
*/
public long getCacheHits() {
return this.cacheHits.get();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCacheMiss()
*/
public long getCacheMiss() {
return this.cacheMiss.get();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getStatementsCached()
*/
public long getStatementsCached() {
return this.statementsCached.get();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getConnectionsRequested()
*/
public long getConnectionsRequested() {
return this.connectionsRequested.get();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCumulativeConnectionWaitTime()
*/
public long getCumulativeConnectionWaitTime() {
return this.cumulativeConnectionWaitTime.get() / 1000000;
}
/** Adds connection wait time.
* @param increment
*/
protected void addCumulativeConnectionWaitTime(long increment) {
this.cumulativeConnectionWaitTime.addAndGet(increment);
}
/** Adds statements executed.
*/
protected void incrementStatementsExecuted() {
this.statementsExecuted.incrementAndGet();
}
/** Adds statements executed.
*/
protected void incrementStatementsPrepared() {
this.statementsPrepared.incrementAndGet();
}
/**
* Accessor method.
*/
protected void incrementStatementsCached() {
this.statementsCached.incrementAndGet();
}
/**
* Accessor method.
*/
protected void incrementCacheMiss() {
this.cacheMiss.incrementAndGet();
}
/**
* Accessor method.
*/
protected void incrementCacheHits() {
this.cacheHits.incrementAndGet();
}
/**
* Accessor method.
*/
protected void incrementConnectionsRequested() {
this.connectionsRequested.incrementAndGet();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCacheHitRatio()
*/
public double getCacheHitRatio() {
return this.cacheHits.get()+this.cacheMiss.get() == 0 ? 0 : this.cacheHits.get() / (1.0*this.cacheHits.get()+this.cacheMiss.get());
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getStatementsExecuted()
*/
public long getStatementsExecuted() {
return this.statementsExecuted.get();
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCumulativeStatementExecutionTime()
*/
public long getCumulativeStatementExecutionTime() {
return this.cumulativeStatementExecuteTime.get() / 1000000;
}
/**
* Accessor method
* @param time
*/
protected void addStatementExecuteTime(long time) {
this.cumulativeStatementExecuteTime.addAndGet(time);
}
/**
* Accessor method
* @param time
*/
protected void addStatementPrepareTime(long time) {
this.cumulativeStatementPrepareTime.addAndGet(time);
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getCumulativeStatementPrepareTime()
*/
public long getCumulativeStatementPrepareTime() {
return this.cumulativeStatementPrepareTime.get() / 1000000;
}
/* (non-Javadoc)
* @see com.jolbox.bonecp.StatisticsMBean#getStatementsPrepared()
*/
public long getStatementsPrepared() {
return this.statementsPrepared.get();
}
}
结论:
有兴趣的童鞋举个手!!!!!!