Closed keynmol closed 8 years ago
Forgot to mention, that I'm experimenting with 3.8.0:
libraryDependencies += "net.openhft" % "chronicle-map" % "3.8.0"
Iterator[(String, Int)]
(rather than Iterator[(Int, String)]
) for key type is String
and value type is Int
, while the error message is compaining about key's type (int/Integer)Key must be a %type%
it means that you configured that type in the first ChronicleMapBuilder.of(keyType, valueType)
statement. So in your case it means that you configured int.class
(the Class
object, representing the primitive int
type in Java), that is not allowed, and providing java.lang.Integer
instance to map's methods (probably you provide primitive int
s, but they become Integer
due to boxing), that is allowed. You should ensure that you are providing java.lang.Integer.class
(or some other Scala's class) to ChronicleMapBuilder.of(keyType, valueType)
call.I don't know what size estimation this project gives: https://github.com/phatak-dev/java-sizeof, but in any case you should specify size in bytes that the object will take in serialized form. Serialized form itself depends on default serializers, chosen for a specific type in Chronicle Map (and may change between Chronicle Map versions), or custom serializers configured for specific ChronicleMapBuilder
. So using any information about key/value "sizes" to configure a Chronicle Map, other than out of the Chronicle Map itself, is fragile. You can use the following procedure to estimate sizes more reliably:
public static <V> double averageValueSize(Class<V> valueClass, Iterable<V> values) {
try (ChronicleMap<Integer, V> testMap = ChronicleMap.of(Integer.class, valueClass)
// doesn't matter, anyway not a single value will be written to a map
.averageValueSize(1)
.entries(1)
.create()) {
LongSummaryStatistics statistics = new LongSummaryStatistics();
for (V value : values) {
try (MapSegmentContext<Integer, V, ?> c = testMap.segmentContext(0)) {
statistics.accept(c.wrapValueAsData(value).size());
}
}
return statistics.getAverage();
}
}
You can find it in this test: https://github.com/OpenHFT/Chronicle-Map/blob/7aedfba7a814578a023f7975ef15ba88b4d435db/src/test/java/eg/AverageValueSizeTest.java
This procedure is hackish, but there are no better options right now.
Another recommendation:
averageKey/averageValue/averageKeySize/averageValueSize
methods, better you use constantKeySizeBySample/constantValueSizeBySample
method. Specifically for java.lang.Integer
, Long
and Double
even this is not needed, Chronicle Map already knows that those types are constantly sized.
Hello.
We're using ChronicleMap to support off-heap persistence in a large number of different stores, but hit a bit a of a problem with the most simple usecase.
First of all, here's the helper I wrote to make creation easier:
It uses https://github.com/phatak-dev/java-sizeof for object size estimation. Here's the kind of usage we want to support:
But it throws an exception:
I can see that it might have something to do with atomicity of Scala's Int as opposed to Java's Integer, but how do I bypass that?