From: Sasa M. <sa...@us...> - 2004-07-21 07:10:36
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31656/org/jrobin/core Modified Files: RrdDbPool.java Util.java Log Message: Minor changes Index: RrdDbPool.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDbPool.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdDbPool.java 28 May 2004 10:22:47 -0000 1.8 --- RrdDbPool.java 21 Jul 2004 07:10:25 -0000 1.9 *************** *** 85,89 **** * becomes eligible for closing so that the oldest RRD file gets closed first.<p> * ! * Initial RrdDbPool capacity is set to 50. Use {@link #setCapacity(int)} method to * change it at any time.<p> * --- 85,89 ---- * becomes eligible for closing so that the oldest RRD file gets closed first.<p> * ! * Initial RrdDbPool capacity is set to {@link #INITIAL_CAPACITY}. Use {@link #setCapacity(int)} method to * change it at any time.<p> * *************** *** 105,111 **** /** * Constant to represent the maximum number of internally open RRD files ! * which still does not force garbage collector to run. */ ! public static final int INITIAL_CAPACITY = 50; private int capacity = INITIAL_CAPACITY; --- 105,111 ---- /** * Constant to represent the maximum number of internally open RRD files ! * which still does not force garbage collector (the process which closes RRD files) to run. */ ! public static final int INITIAL_CAPACITY = 100; private int capacity = INITIAL_CAPACITY; *************** *** 113,116 **** --- 113,117 ---- private List rrdGcList = new LinkedList(); private RrdBackendFactory factory; + private int poolHitsCount, poolRequestsCount; /** *************** *** 147,150 **** --- 148,152 ---- public synchronized RrdDb requestRrdDb(String path) throws IOException, RrdException { String keypath = getCanonicalPath(path); + RrdDb rrdDbRequested; if (rrdMap.containsKey(keypath)) { // already open *************** *** 152,162 **** reportUsage(rrdEntry); debug("EXISTING: " + rrdEntry.dump()); ! return rrdEntry.getRrdDb(); } else { // not found, open it RrdDb rrdDb = new RrdDb(path, getFactory()); addRrdEntry(keypath, rrdDb); ! return rrdDb; } } --- 154,167 ---- reportUsage(rrdEntry); debug("EXISTING: " + rrdEntry.dump()); ! rrdDbRequested = rrdEntry.getRrdDb(); ! poolHitsCount++; } else { // not found, open it RrdDb rrdDb = new RrdDb(path, getFactory()); addRrdEntry(keypath, rrdDb); ! rrdDbRequested = rrdDb; } + poolRequestsCount++; + return rrdDbRequested; } *************** *** 177,180 **** --- 182,186 ---- RrdDb rrdDb = new RrdDb(path, xmlPath, getFactory()); addRrdEntry(keypath, rrdDb); + poolRequestsCount++; return rrdDb; } *************** *** 194,197 **** --- 200,204 ---- RrdDb rrdDb = new RrdDb(rrdDef, getFactory()); addRrdEntry(keypath, rrdDb); + poolRequestsCount++; return rrdDb; } *************** *** 418,421 **** --- 425,460 ---- } } + + /** + * Calculates pool's efficency ratio. The ratio is obtained by dividing the number of + * RrdDb requests served from the internal pool of open RRD files + * with the number of total RrdDb requests. + * @return Pool's efficiency ratio as a double between 1 (best) and 0 (worst). If no RrdDb reference + * was ever requested, 1 would be returned. + */ + public synchronized double getPoolEfficency() { + if(poolRequestsCount == 0) { + return 1.0; + } + double ratio = (double) poolHitsCount / (double) poolRequestsCount; + // round to 3 decimal digits + return Math.round(ratio * 1000.0) / 1000.0; + } + + /** + * Returns the number of RRD requests served from the internal pool of open RRD files + * @return The number of pool "hits". + */ + public synchronized int getPoolHitsCount() { + return poolHitsCount; + } + + /** + * Returns the total number of RRD requests successfully served by this pool. + * @return Total number of RRD requests + */ + public synchronized int getPoolRequestsCount() { + return poolRequestsCount; + } } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Util.java 20 Jul 2004 08:21:02 -0000 1.20 --- Util.java 21 Jul 2004 07:10:26 -0000 1.21 *************** *** 85,90 **** /** ! * Rounds the given timestamp to the nearest whole "step" by evaluating ! * the following expression:<p> * <code>timestamp - timestamp % step;</code> * @param timestamp Timestamp in seconds --- 85,90 ---- /** ! * Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained ! * from the following expression:<p> * <code>timestamp - timestamp % step;</code> * @param timestamp Timestamp in seconds |