uk.co.probablyfine:java-dirty-benchmarks

A file-based append-only object store, using memory mapped files for persistence.

License

License

Categories

Categories

Java Languages
GroupId

GroupId

uk.co.probablyfine
ArtifactId

ArtifactId

java-dirty-benchmarks
Last Version

Last Version

1.7
Release Date

Release Date

Type

Type

jar
Description

Description

A file-based append-only object store, using memory mapped files for persistence.

Download java-dirty-benchmarks

How to add to project

<!-- https://jarcasting.com/artifacts/uk.co.probablyfine/java-dirty-benchmarks/ -->
<dependency>
    <groupId>uk.co.probablyfine</groupId>
    <artifactId>java-dirty-benchmarks</artifactId>
    <version>1.7</version>
</dependency>
// https://jarcasting.com/artifacts/uk.co.probablyfine/java-dirty-benchmarks/
implementation 'uk.co.probablyfine:java-dirty-benchmarks:1.7'
// https://jarcasting.com/artifacts/uk.co.probablyfine/java-dirty-benchmarks/
implementation ("uk.co.probablyfine:java-dirty-benchmarks:1.7")
'uk.co.probablyfine:java-dirty-benchmarks:jar:1.7'
<dependency org="uk.co.probablyfine" name="java-dirty-benchmarks" rev="1.7">
  <artifact name="java-dirty-benchmarks" type="jar" />
</dependency>
@Grapes(
@Grab(group='uk.co.probablyfine', module='java-dirty-benchmarks', version='1.7')
)
libraryDependencies += "uk.co.probablyfine" % "java-dirty-benchmarks" % "1.7"
[uk.co.probablyfine/java-dirty-benchmarks "1.7"]

Dependencies

compile (3)

Group / Artifact Type Version
uk.co.probablyfine : java-dirty jar 1.7
org.openjdk.jmh : jmh-core jar 1.10.1
org.openjdk.jmh : jmh-generator-annprocess jar 1.10.1

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-core jar 1.9.5

Project Modules

There are no modules declared in this project.

java-dirty

Build Status

A fast file-based append-only object store, using memory mapped files.

Is java-dirty safe to use with multiple concurrent writers?

Absolutely not - but it's fast enough that putting it behind e.g. a Disruptor and consuming writes in a single thread should be fine.

Downloading from Maven

<dependency>
  <groupId>uk.co.probablyfine</groupId>
  <artifactId>java-dirty</artifactId>
  <version>1.6</version>
</dependency>

Usage

Creating a store.

Store<Foo> store = Store.of(Foo.class).from("/path/to/file");

Inserting an object

store.put(new Foo(1,2));

Iterating over all objects in the store

store.all().forEach(System.out::println);

Iterate over objects, most recent first

store.reverse().forEach(System.out::println);

Iterate over objects from a starting index

store.from(100).forEach(System.out::println);

Access an index directly

Optional<Foo> foo = store.get(1234);

Reset the entire store

store.reset(); // Reset position to 0, overwriting old entries

Close the store and its backing file

store.close();

Trying to read from/write to a closed store will throw a ClosedStoreException.

Observe each write

store.observeWrites((object, index) ->
  System.out.println("Stored "+object+" at "+index);
);

java-dirty does not support replacements, or deletions. Both .all() and .reverse() expose a Stream.

Examples

Look up most recent version of an object by index

Optional<StoredObject> first = store
    .reverse()
    .filter(x -> x.indexField == valueToFind)
    .findFirst();

Build an lookup index using write observers

Store<StoredObject> store = Store.of(StoredObject.class).from("/some/path");

Map<Integer, Integer> index = new HashMap<>();

store.observeWrites((object, location) -> {
  index.put(object.indexField, location);
});

store.put(new StoredObject(1234,5));

store.get(index.get(1234)); // Optional[StoredObject(1234,5)];

Supported Fields

java-dirty will only persist primitive fields on objects. All primitive types are currently supported.

Performance

See the README in java-dirty-benchmarks for the latest

Versions

Version
1.7