`
cywhoyi
  • 浏览: 413294 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

BoneCP+extjs4开源Infographics

阅读更多

使用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();
	}
	
}

 

结论:

     有兴趣的童鞋举个手!!!!!!

 

分享到:
评论

相关推荐

    Bonecp+Spring需要的jar包

    bonecp-0.7.1.RELEASE.jar bonecp-provider-0.7.0.jar google-collections-1.0.jar bonecp-spring-0.7.1.RELEASE.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar

    Bonecp+Spring需要的jar包 0.7+0.8

    bonecp-0.7.1.RELEASE.jar bonecp-provider-0.7.0.jar google-collections-1.0.jar bonecp-spring-0.7.1.RELEASE.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar

    spring+hibernate+JPA+BoneCP

    原创资源,码超所值,价廉物美。...所用的技术比较多,如Spring的IOC,AOP,Transactiion,Annotation,Spring_JUnit_Test及Log4j;Hibernate的JPA Annotation;BoneCP的数据库连接测等。是很好的学习资料!

    SpringMVC+Mybatis

    SpringMVC+Mybatis+Maven+Bonecp+EclipseSTS, Mapper使用MapperScannerConfigurer方式

    开源数据库连接池bonecp附教程

    开源数据库连接池bonecp附教程;据说是最快的数据库连接池

    BoneCP(连接oracle例子+jar包)

    BoneCP(连接oracle例子+jar包)

    BoneCP(连接oracle例子+所有jar包)

    bonecp数据库连接池很好用的例子 BoneCPDataSource.java bonecp-0.7.1-rc2.jar bonecp-provider-0.7.0.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar guava-r07.jar oracle_jdbc_classes12.jar

    Spring+Mybatis+BoneCP配置实例

    mysql5.1、mybatis-spring1.1、bonecp0.6.7.2配置部署成功,可以修改为多数据源,多连接池底层应用。

    最新版SSH框架(spring3.1.2+hibernate4.1.4+struts2.3.4+bonecp0.7.1)

    最新版SSH框架(spring3.1.2+hibernate4.1.4+struts2.3.4+bonecp0.7.1) 使用bonecp作为数据库连接池工具 下载后可以运行,有例子,使用freemarker模板展示。

    连接池bonecp-0.8.1

    bonecp-0.8.1-20131105.191813-1.jar bonecp-jdk-compat-0.8.1-20131105.191752-1.jar bonecp-provider-0.8.1-20131105.191842-1.jar slf4j-api-1.7.7.jar slf4j-log4j12-1.7.7.jar

    bonecp-0.8.0.RELEASE.jar

    bonecp.jar、bonecp-provider-0.7.0.jar、bonecp-spring-.jar、slf4j-api.jar、slf4j-log4j.jar

    BoneCP数据源应用

    BoneCP数据源应用,详细的介绍了BoneCP的相关参数

    bonecp数据库连接池jar包

    bonecp数据库连接池jar包0.7.1: bonecp-0.7.1.RELEASE.jar bonecp-provider-0.7.1-rc2.jar bonecp-spring-0.7.1.RELEASE.jar

    bonecp-0.7.0.jar

    bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar bonecp-0.7.0.jar

    bonecp连接池

    在用C3P0数据连接池的时候,一旦并发上来就坑不住了,因为C3P0存在...在Hibernate中使用BoneCP除了需要上面提到的jar包之外,还需要下载一个名为bonecp-provider-0.7.0.jar的bonecp-provider的jar包,它的下载位置是:...

    springMVC+srping3.2+hibernate4.2+bonecp登陆示例

    最新的springMVC+srping3.2+hibernate4.2的一个登陆示例,连接池使用bonecp,中间加了一个检测页面URL合法性的filter,里面可以增加session检测等,适用于此框架的初学者(因只是通过一个登陆页面将框架构建出来) 注意:这...

    bonecp所需jar包

    bonecp所需jar包 里面包含bonecp-0.7.0.jar,google-collections-1.0.jar,slf4j-api-1.5.8.jar,slf4j-log4j12-1.5.6.jar和slf4j-simple-1.5.8.jar,有需要的同学可以下载使用

    DBCP+C3P0+BoneCP连接池参数说明

    NULL 博文链接:https://wang-jia-sina-com.iteye.com/blog/1893639

    BoneCP所需依赖包

    bonecp连接池所需的全部依赖包。。。bonecp连接池所需的全部依赖包。。。bonecp连接池所需的全部依赖包。。。bonecp连接池所需的全部依赖包。。。

    Bonecp参数配置.doc

    Bonecp的各个参数配置,以及各个参数的说明解释。

Global site tag (gtag.js) - Google Analytics