From: Sasa M. <sa...@us...> - 2004-03-24 14:06:30
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31594/org/jrobin/core Modified Files: Archive.java Robin.java RrdDoubleArray.java RrdFile.java Log Message: creation of big rrd files (> 1Mb) seriously improved Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Archive.java 8 Dec 2003 13:47:40 -0000 1.10 --- Archive.java 24 Mar 2004 13:55:52 -0000 1.11 *************** *** 159,167 **** } } // update robin in bulk ! long bulkUpdates = Math.min(numUpdates / steps.get(), (long) rows.get()); ! for(long i = 0; i < bulkUpdates; i++) { ! robin.store(value); ! } // update remaining steps long remainingUpdates = numUpdates % steps.get(); --- 159,171 ---- } } + // update robin in bulk ! int bulkUpdateCount = (int) Math.min(numUpdates / steps.get(), (long) rows.get()); ! //TODO: Check this ! //for(long i = 0; i < bulkUpdates; i++) { ! // robin.store(value); ! //} ! // OLD CODE ENDS ! robin.bulkStore(value, bulkUpdateCount); // update remaining steps long remainingUpdates = numUpdates % steps.get(); Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdFile.java 19 Feb 2004 12:23:57 -0000 1.4 --- RrdFile.java 24 Mar 2004 13:55:52 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- import java.util.LinkedList; import java.util.List; + import java.util.Arrays; /** *************** *** 178,180 **** --- 179,214 ---- } + void writeDouble(double value, int count) throws IOException { + // THIS IS SLOW! RandomAccessFile is crap + // for(int i = 0; i < count; i++) { + // super.writeDouble(value); + // } + // HACK to speed things up! + long valueAsLong = Double.doubleToLongBits(value); + byte[] valueAsBytes = new byte[8]; + // high byte comes first + valueAsBytes[7] = (byte)(valueAsLong & 0xFFL); + valueAsBytes[6] = (byte)((valueAsLong >>> 8) & 0xFFL); + valueAsBytes[5] = (byte)((valueAsLong >>> 16) & 0xFFL); + valueAsBytes[4] = (byte)((valueAsLong >>> 24) & 0xFFL); + valueAsBytes[3] = (byte)((valueAsLong >>> 32) & 0xFFL); + valueAsBytes[2] = (byte)((valueAsLong >>> 40) & 0xFFL); + valueAsBytes[1] = (byte)((valueAsLong >>> 48) & 0xFFL); + valueAsBytes[0] = (byte)((valueAsLong >>> 56) & 0xFFL); + // memory hungry, but very efficient + byte[] image = new byte[count * 8]; + for(int i = 0, k = 0; i < count; i++) { + image[k++] = valueAsBytes[0]; + image[k++] = valueAsBytes[1]; + image[k++] = valueAsBytes[2]; + image[k++] = valueAsBytes[3]; + image[k++] = valueAsBytes[4]; + image[k++] = valueAsBytes[5]; + image[k++] = valueAsBytes[6]; + image[k++] = valueAsBytes[7]; + } + super.write(image); + image = null; + } + } Index: RrdDoubleArray.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDoubleArray.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdDoubleArray.java 27 Nov 2003 14:15:11 -0000 1.2 --- RrdDoubleArray.java 24 Mar 2004 13:55:52 -0000 1.3 *************** *** 39,60 **** super(updater, length * RrdDouble.SIZE); this.length = length; ! for(int i = 0; i < length; i++) { ! set(i, initVal); ! } } void set(int index, double value) throws IOException { ! if(index >= length) { ! throw new IOException("Invalid index supplied: " + index + ", max = " + length); ! } RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); ! rrdFile.writeDouble(value); } double get(int index) throws IOException { ! if(index >= length) { ! throw new IOException("Invalid index supplied: " + index + ", max = " + length); ! } RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); --- 39,60 ---- super(updater, length * RrdDouble.SIZE); this.length = length; ! set(0, initVal, length); } void set(int index, double value) throws IOException { ! set(index, value, 1); ! } ! ! void set(int index, double value, int count) throws IOException { ! // rollovers not allowed! ! assert index + count <= length: "Invalid robin index supplied: index=" + index + ! ", count=" + count + ", length=" + length; RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); ! rrdFile.writeDouble(value, count); } double get(int index) throws IOException { ! assert index < length: "Invalid index supplied: " + index + ", length=" + length; RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Robin.java 8 Dec 2003 13:47:40 -0000 1.7 --- Robin.java 24 Mar 2004 13:55:52 -0000 1.8 *************** *** 74,77 **** --- 74,78 ---- } + // stores single value void store(double newValue) throws IOException { int position = pointer.get(); *************** *** 80,83 **** --- 81,101 ---- } + // TODO: NOT TESTED ENOUGH + // stores the same value several times + void bulkStore(double newValue, int bulkCount) throws IOException { + assert bulkCount <= rows: "Invalid number of bulk updates"; + int position = pointer.get(); + // update tail + int tailUpdateCount = Math.min(rows - position, bulkCount); + values.set(position, newValue, tailUpdateCount); + pointer.set((position + tailUpdateCount) % rows); + // do we need to update from the start? + int startUpdateCount = bulkCount - tailUpdateCount; + if(startUpdateCount > 0) { + values.set(0, newValue, startUpdateCount); + pointer.set(startUpdateCount); + } + } + /** * Returns the underlying RrdFile object. |