These are chat archives for HdrHistogram/HdrHistogram

8th
Nov 2015
Peter Pathirana
@ppat
Nov 08 2015 17:06

How do you store a hdr histogram in a db or send it across a wire?

It seems to have that functionality but it doesn't seem to work. it seems to have the ability to export it into a byte buffer and vice versa.

ByteBuffer byteBuffer1 = ByteBuffer.allocate(histogram.getNeededByteBufferCapacity());
histogram.encodeIntoByteBuffer(byteBuffer1);
byte[] newValue = new byte[byteBuffer1.remaining()];
byteBuffer1.get(newValue);
ByteBuffer byteBuffer2 = ByteBuffer.wrap(newValue);
histogram = Histogram.decodeFromByteBuffer(byteBuffer2, 3600000000000L);

But the last line blows up, it doesn't seem to recognize bytes that were exported out of its own.

Caused by: java.lang.IllegalArgumentException: The buffer does not contain a Histogram (no valid cookie found)
    at org.HdrHistogram.AbstractHistogram.decodeFromByteBuffer(AbstractHistogram.java:1835)
    at org.HdrHistogram.AbstractHistogram.decodeFromByteBuffer(AbstractHistogram.java:1792)
    at org.HdrHistogram.Histogram.decodeFromByteBuffer(Histogram.java:241)

I still get the error if I skip the byte array,

ByteBuffer byteBuffer1 = ByteBuffer.allocate(histogram.getNeededByteBufferCapacity());
histogram.encodeIntoByteBuffer(byteBuffer1);
histogram = Histogram.decodeFromByteBuffer(byteBuffer1, 3600000000000L);
Gil Tene
@giltene
Nov 08 2015 18:20
@ppat: you need to rewind the buffer in your tests (after encoding into it).
Gil Tene
@giltene
Nov 08 2015 18:26
@mikeb01 @ahothan @darach : Since I recently fixed an edge bug in the linear and logarithmic iterators in the Java version, you might want to see if your C/python/erlang implementations share the bug. See HdrHistogram/HdrHistogram#82
@ppat: You should probably use the compressed encodings (encodeIntoCompressedByteBuffer / decodeFromCompressedByteBuffer) forms if you want to store thus stuff in a db or send it on the wire.
Peter Pathirana
@ppat
Nov 08 2015 18:41
Hi @giltene, thanks... that worked :)
I'll switch to compressed byte buffers as well