Crates.io | vclock |
lib.rs | vclock |
version | 0.4.4 |
source | src |
created_at | 2020-01-05 16:17:25.246654 |
updated_at | 2024-03-17 14:46:00.590705 |
description | VClock is a vector clock. |
homepage | https://gitlab.com/liberecofr/vclock |
repository | https://gitlab.com/liberecofr/vclock/tree/main |
max_upload_size | |
id | 195445 |
size | 49,185 |
VClock is a vector clock implemented in Rust.
It offers a partial order of events in a distributed system. In practice, it implements the rust partial order trait over hash maps which maintain an integer count of each modification, per key.
This is, to my knowledge, not used in "real" production, so the only safety net is unit tests. Project has a reasonable test harness, so it should be OK to use it. Again, DISCLAIMER, use at your own risks.
use vclock::VClock64;
let c1 = VClock64::new("a"); // c1 is now a:0
let mut c2 = VClock64::new("b"); // c2 is now b:0
c2.incr(&"a"); // c1 is now a:1, b:0
assert!(c1 < c2, "c1 should be a child of c2");
Package has two optional features:
serde
to enable Serde support for (de)serializationbigint
to enable big integers support and have "infinite" vector clocksTaken from a random CI job:
running 15 tests
test tests::bench_vclock64_int_cmp_10 ... bench: 383 ns/iter (+/- 12)
test tests::bench_vclock64_int_cmp_100 ... bench: 2,889 ns/iter (+/- 78)
test tests::bench_vclock64_int_cmp_1000 ... bench: 26,221 ns/iter (+/- 384)
test tests::bench_vclock64_int_cmp_10000 ... bench: 276,902 ns/iter (+/- 3,855)
test tests::bench_vclock64_int_incr ... bench: 35 ns/iter (+/- 2)
test tests::bench_vclock64_str_cmp_10 ... bench: 346 ns/iter (+/- 8)
test tests::bench_vclock64_str_cmp_100 ... bench: 3,104 ns/iter (+/- 87)
test tests::bench_vclock64_str_cmp_1000 ... bench: 36,570 ns/iter (+/- 2,054)
test tests::bench_vclock64_str_cmp_10000 ... bench: 663,951 ns/iter (+/- 52,968)
test tests::bench_vclock64_str_incr ... bench: 53 ns/iter (+/- 10)
test tests::bench_vclockbig_str_cmp_10 ... bench: 548 ns/iter (+/- 11)
test tests::bench_vclockbig_str_cmp_100 ... bench: 3,945 ns/iter (+/- 96)
test tests::bench_vclockbig_str_cmp_1000 ... bench: 37,310 ns/iter (+/- 3,270)
test tests::bench_vclockbig_str_cmp_10000 ... bench: 688,678 ns/iter (+/- 157,335)
test tests::bench_vclockbig_str_incr ... bench: 113 ns/iter (+/- 4)
test result: ok. 0 passed; 0 failed; 0 ignored; 15 measured; 0 filtered out; finished in 11.35s
This is not the result of thorough, intensive benchmarking, but we can at least infer that one significant game changer, when comparing, is the length of the vector clocks. It grows more or less linearily as their size increases.
To run the benchmarks:
cd bench
rustup default nightly
cargo bench
VClock is licensed under the MIT license.