diff --git a/README.md b/README.md index 0e4959162..1c4ef9bc8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Click here to get the [Latest Version Number](http://search.maven.org/#search%7C * [Flow Interface](https://github.com/OpenHFT/Chronicle-Map#flow-interface) * [Sharing Data Between Two or More Maps](https://github.com/OpenHFT/Chronicle-Map#sharing-data-between-two-or-more-maps) * [Entries](https://github.com/OpenHFT/Chronicle-Map#entries) + * [Size of Space Reserved on Disk](https://github.com/OpenHFT/Chronicle-Map#size-of-space-reserved-on-disk) * [Chronicle Map Interface](https://github.com/OpenHFT/Chronicle-Map#chronicle-map-interface) * [Oversized Entries Support] (https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#oversized-entries-support) * [Serialization](https://github.com/OpenHFT/Chronicle-Map#serialization) @@ -207,6 +208,21 @@ map = ChronicleMapBuilder.of(Integer.class, CharSequence.class) ``` In this example above we have set 1000 entries. +### Size of space reserved on disk + +In linux, if you looked at the size of the 'file', it will report the used entry size, so if you have just added one entry, it will report the size of this entry, but Windows will report the reserved size, as it reserves the disk space eagerly ( in fact windows also reserves the memory eagerly as well ), in other words number-of-entries x entry-size. + +so on linux, if your type +``` +# It shows you the extents. +ls -l + +# It shows you how much is actually used. +du +``` + +To illustrate this with an example - On Ubuntu we can create a 100 TB chronicle map. Both top and ls -l say the process virtual size / file size is 100 TB, however the resident memory via 'du' says the size is 71 MB after adding 10000 entries. + ### Chronicle Map Interface The Chronicle Map interface adds a few methods above an beyond the standard ConcurrentMap, The ChronicleMapBuilder can also be used to return the ChronicleMap, see the example below : @@ -394,7 +410,7 @@ ChronicleMapBuilder builder; builder = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(1000) - .file(getPersistenceFile()); + .file(file); map = clusterReplicatorBuilder.create((short) 1, builder); ``` @@ -438,7 +454,7 @@ ChronicleMapBuilder builder; builder = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(1000) - .file(getPersistenceFile()); + .file(file); cluster = clusterReplicatorBuilder.create(); @@ -566,7 +582,7 @@ ChronicleMapBuilder builder; builder = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(1000) - .file(getPersistenceFile()); + .file(file); cluster = clusterReplicatorBuilder.create(); diff --git a/src/test/java/net/openhft/chronicle/map/example/WordCount.java b/src/test/java/net/openhft/chronicle/map/example/WordCount.java new file mode 100644 index 000000000..af8a83afb --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/example/WordCount.java @@ -0,0 +1,35 @@ +package net.openhft.chronicle.map.example; + +public class WordCount { + + static String[] words; + static int expectedSize; + static { + try { + // english version of war and peace -> ascii + String fullText = + new String(Files.readAllBytes(Paths.get("war_and_peace.txt")), UTF_8); + words = fullText.split("\\s+"); + expectedSize = (int) Arrays.stream(words).distinct().count(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + static interface ByteableIntValue extends IntValue, Byteable {} + + @Benchmark + public int chronicleMap() throws IOException { + ChronicleMap map = + ChronicleMapBuilder.of(String.class, ByteableIntValue.class) + .entrySize(16) + .actualSegments(1) + .entries(expectedSize) + .create(); + ByteableIntValue v = map.acquireUsing("a", null); + for (String word : words) { + map.acquireUsing(word, v).addValue(1); + } + return map.acquireUsing("a", v).getValue(); + } +} \ No newline at end of file diff --git a/src/test/resources/war_and_peace.txt.gz b/src/test/resources/war_and_peace.txt.gz new file mode 100644 index 000000000..16131fa4b Binary files /dev/null and b/src/test/resources/war_and_peace.txt.gz differ