10 releases
0.4.4 | Mar 17, 2024 |
---|---|
0.4.3 | Feb 6, 2023 |
0.4.2 | Jan 21, 2023 |
0.3.1 | Jan 3, 2023 |
0.1.0 | Jan 5, 2020 |
#657 in Network programming
40 downloads per month
Used in 2 crates
(via confitul)
38KB
392 lines
VClock
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.
Status
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.
Usage
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 clocks
Benchmarks
Taken 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
Links
License
VClock is licensed under the MIT license.
Dependencies
~0–275KB