From: Sasa M. <sa...@us...> - 2004-06-02 08:55:58
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10051/org/jrobin/core Modified Files: RrdCacher.java Sample.java Log Message: Faster RRD cacher (5-10%). StressTest should be faster. Index: RrdCacher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdCacher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdCacher.java 20 May 2004 10:34:00 -0000 1.1 --- RrdCacher.java 2 Jun 2004 08:55:48 -0000 1.2 *************** *** 26,106 **** package org.jrobin.core; ! class RrdCacher { ! private Object cache = null; ! boolean setInt(int value) { ! if(isCached(value)) { return false; } else { ! cache = new Integer(value); ! return true; } } ! boolean setLong(long value) { ! if(isCached(value)) { return false; } else { ! cache = new Long(value); ! return true; } } ! boolean setDouble(double value) { ! if(isCached(value)) { return false; } else { ! cache = new Double(value); ! return true; } } ! boolean setString(String value) { ! if(isCached(value)) { return false; } else { ! cache = value; ! return true; } } ! boolean isEmpty() { ! return cache == null; ! } ! ! int getInt() { ! return ((Integer) cache).intValue(); ! } ! ! long getLong() { ! return ((Long) cache).longValue(); ! } ! ! double getDouble() { ! return ((Double) cache).doubleValue(); } ! String getString() { ! return (String) cache; } ! private boolean isCached(int value) { ! return cache != null && getInt() == value; } ! private boolean isCached(long value) { ! return cache != null && getLong() == value; } ! private boolean isCached(double value) { ! return cache != null && getDouble() == value; } - private boolean isCached(String value) { - return cache != null && getString().equals(value); - } } --- 26,95 ---- package org.jrobin.core; ! final class RrdCacher { ! private boolean cached = false; ! private int i; ! private long l; ! private double d; ! private String s; ! final boolean setInt(int value) { ! if (cached && value == i) { return false; } else { ! i = value; ! return cached = true; } } ! final boolean setLong(long value) { ! if(cached && value == l) { return false; } else { ! l = value; ! return cached = true; } } ! final boolean setDouble(double value) { ! if(cached && value == d) { return false; } else { ! d = value; ! return cached = true; } } ! final boolean setString(String value) { ! if(cached && value.equals(s)) { return false; } else { ! s = value; ! return cached = true; } } ! final boolean isEmpty() { ! return !cached; } ! final int getInt() { ! return i; } ! final long getLong() { ! return l; } ! final double getDouble() { ! return d; } ! final String getString() { ! return s; } } Index: Sample.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Sample.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Sample.java 28 May 2004 10:22:47 -0000 1.8 --- Sample.java 2 Jun 2004 08:55:48 -0000 1.9 *************** *** 99,103 **** return; } ! throw new RrdException("Sample index " + i + " out of bounds"); } --- 99,103 ---- return; } ! throw new RrdException("Sample datasource index " + i + " out of bounds"); } *************** *** 164,190 **** * * @param timeAndValues String made by concatenating sample timestamp with corresponding ! * data source values delmited with colons. For example: ! * <code>1005234132:12.2:35.6:U:24.5</code> * @throws RrdException Thrown if too many datasource values are supplied */ public void set(String timeAndValues) throws RrdException { ! StringTokenizer st = new StringTokenizer(timeAndValues, ":", false); ! int numTokens = st.countTokens(); ! String[] tokens = new String[numTokens]; ! for(int i = 0; i < numTokens; i++) { ! tokens[i] = st.nextToken(); } ! long time = Long.parseLong(tokens[0]); ! double[] values = new double[numTokens - 1]; ! for(int i = 0; i < numTokens - 1; i++) { try { ! values[i] = Double.parseDouble(tokens[i + 1]); } ! catch(NumberFormatException nfe) { ! values[i] = Double.NaN; } } - setTime(time); - setValues(values); } --- 164,204 ---- * * @param timeAndValues String made by concatenating sample timestamp with corresponding ! * data source values delmited with colons. For example:<p> ! * <pre> ! * 1005234132:12.2:35.6:U:24.5 ! * NOW:12.2:35.6:U:24.5 ! * </pre> ! * 'N' stands for the current timestamp (can be replaced with 'NOW')<p> ! * Method will throw an exception if timestamp is invalid (cannot be parsed as Long, and is not 'N' ! * or 'NOW'). Datasource value which cannot be parsed as 'double' will be silently set to NaN.<p> * @throws RrdException Thrown if too many datasource values are supplied */ public void set(String timeAndValues) throws RrdException { ! StringTokenizer tokenizer = new StringTokenizer(timeAndValues, ":", false); ! int n = tokenizer.countTokens(); ! if(n > values.length + 1) { ! throw new RrdException("Invalid number of values specified (found " + ! values.length + ", " + dsNames.length + " allowed)"); } ! String timeToken = tokenizer.nextToken(); ! try { ! time = Long.parseLong(timeToken); ! } ! catch(NumberFormatException nfe) { ! if(timeToken.equalsIgnoreCase("N") || timeToken.equalsIgnoreCase("NOW")) { ! time = Util.getTime(); ! } ! else { ! throw new RrdException("Invalid sample timestamp: " + timeToken); ! } ! } ! for(int i = 0; tokenizer.hasMoreTokens(); i++) { try { ! values[i] = Double.parseDouble(tokenizer.nextToken()); } ! catch (NumberFormatException nfe) { ! // NOP, value is already set to NaN } } } *************** *** 210,215 **** * </pre> * @param timeAndValues String made by concatenating sample timestamp with corresponding ! * data source values delmited with colons. For example: ! * <code>1005234132:12.2:35.6:U:24.5</code> * * @throws IOException Thrown in case of I/O error. --- 224,230 ---- * </pre> * @param timeAndValues String made by concatenating sample timestamp with corresponding ! * data source values delmited with colons. For example:<br> ! * <code>1005234132:12.2:35.6:U:24.5</code><br> ! * <code>NOW:12.2:35.6:U:24.5</code> * * @throws IOException Thrown in case of I/O error. |