Skip to content

Commit

Permalink
Criterion and proptest
Browse files Browse the repository at this point in the history
Signed-off-by: Ana Hobden <operator@hoverbear.org>
  • Loading branch information
Hoverbear committed Jun 19, 2019
1 parent ebe3261 commit e17d3f1
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 74 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ integration-tests = ["property-testing"]
# Enable propery testing features with `proptest`.
property-testing = ["proptest", "proptest-derive"]


[lib]
name = "tikv_client"

Expand All @@ -43,7 +42,13 @@ default-features = false
features = ["push", "process"]

[dev-dependencies]
criterion = "0.2"
proptest = "0.9"
clap = "2.32"
tempdir = "0.3"
runtime = "0.3.0-alpha.3"
runtime-tokio = "0.3.0-alpha.3"

[[bench]]
name = "bench"
harness = false
164 changes: 91 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,91 @@
# TiKV Client (Rust)

[![Build Status](https://travis-ci.org/tikv/client-rust.svg?branch=master)](https://travis-ci.org/tikv/client-rust)
[![Documentation](https://docs.rs/tikv-client/badge.svg)](https://docs.rs/tikv-client/)

> Currently this crate is experimental and some portions (e.g. the Transactional API) are still in active development. You're encouraged to use this library for testing and to help us find problems!
This crate provides a clean, ready to use client for [TiKV](https://github.com/tikv/tikv), a
distributed transactional Key-Value database written in Rust.

With this crate you can easily connect to any TiKV deployment, interact with it, and mutate the data it contains.

This is an open source (Apache 2) project hosted by the Cloud Native Computing Foundation (CNCF) and maintained by the TiKV Authors. *We'd love it if you joined us in improving this project.*

## Using the client

The TiKV client is a Rust library (crate). It requires version 1.36 of the compiler and standard libraries (which will be stable from the 4th July 2019, see below for ensuring compatibility).

To use this crate in your project, add it as a dependency in your `Cargo.toml`:

```toml
[dependencies]
# ...Your other dependencies...
tikv-client = { git = "https://github.com/tikv/client-rust.git" }
```

The client requires a Git dependency until we can [publish it](https://github.com/tikv/client-rust/issues/32).

There are [examples](examples) which show how to use the client in a Rust program.

The examples and documentation use async/await syntax. This is a new feature in Rust and is currently unstable. To use async/await you'll need to add the feature flag `#![async_await]` to your crate and use a nightly compiler (see below).

## Access the documentation

We recommend using the cargo-generated documentation to browse and understand the API. We've done
our best to include ample, tested, and understandable examples.

You can visit [docs.rs/tikv-client](https://docs.rs/tikv-client/), or build the documentation yourself.

You can access the documentation on your machine by running the following in any project that depends on `tikv-client`.

```bash
cargo doc --package tikv-client --open
# If it didn't work, browse file URL it tried to open with your browser.
```

## Toolchain versions

To check what version of Rust you are using, run

```bash
rustc --version
```

You'll see something like `rustc 1.36.0-nightly (a784a8022 2019-05-09)` where the `1.36.0` is the toolchain version, and `nightly` is the channel (stable/beta/nightly). To install another toolchain use

```bash
rustup toolchain install nightly
```

Where `nightly` here is the channel to add. To update your toolchains, run

```bash
rustup update
```

To build your project using a specified toolchain, use something like

```bash
cargo +nightly build
```

Where `nightly` names the toolchain (by specifying the channel, in this case).
# TiKV Client (Rust)

[![Build Status](https://travis-ci.org/tikv/client-rust.svg?branch=master)](https://travis-ci.org/pingcap/client-rust)
[![Documentation](https://docs.rs/tikv-client/badge.svg)](https://docs.rs/tikv-client/)

> Currently this crate is experimental and some portions (e.g. the Transactional API) are still in active development. You're encouraged to use this library for testing and to help us find problems!
This crate provides a clean, ready to use client for [TiKV](https://github.com/tikv/tikv), a
distributed transactional Key-Value database written in Rust.

With this crate you can easily connect to any TiKV deployment, interact with it, and mutate the data it contains.

This is an open source (Apache 2) project hosted by the Cloud Native Computing Foundation (CNCF) and maintained by the TiKV Authors. *We'd love it if you joined us in improving this project.*

## Using the client

The TiKV client is a Rust library (crate). It requires version 1.36 of the compiler and standard libraries (which will be stable from the 4th July 2019, see below for ensuring compatibility).

To use this crate in your project, add it as a dependency in your `Cargo.toml`:

```toml
[dependencies]
# ...Your other dependencies...
tikv-client = { git = "https://github.com/tikv/client-rust.git" }
```

The client requires a Git dependency until we can [publish it](https://github.com/tikv/client-rust/issues/32).

There are [examples](examples) which show how to use the client in a Rust program.

The examples and documentation use async/await syntax. This is a new feature in Rust and is currently unstable. To use async/await you'll need to add the feature flag `#![async_await]` to your crate and use a nightly compiler (see below).

## Access the documentation

We recommend using the cargo-generated documentation to browse and understand the API. We've done
our best to include ample, tested, and understandable examples.

You can visit [docs.rs/tikv-client](https://docs.rs/tikv-client/), or build the documentation yourself.

You can access the documentation on your machine by running the following in any project that depends on `tikv-client`.

```bash
cargo doc --package tikv-client --open
# If it didn't work, browse file URL it tried to open with your browser.
```

## Running benchmarks

This crate uses [`criterion`](https://github.com/bheisler/criterion.rs) for benchmarking. Most benchmarks use [`proptest`](https://github.com/altsysrq/proptest) to generate values for bench runs.

Currently, all of the benchmarks are gated by the `integration-tests` feature, and require a functioning TiKV (and PD) cluster.

```bash
export PD_ADDRS=192.168.0.100:2379,192.168.0.101:2379,192.168.0.102:2379
cargo +nightly bench --features integration-tests
```

It is possible to limit the scope of benchmarks:

```bash
export PD_ADDRS=192.168.0.100:2379,192.168.0.101:2379,192.168.0.102:2379
cargo +nightly bench --features integration-tests raw
```

## Toolchain versions

To check what version of Rust you are using, run

```bash
rustc --version
```

You'll see something like `rustc 1.36.0-nightly (a784a8022 2019-05-09)` where the `1.36.0` is the toolchain version, and `nightly` is the channel (stable/beta/nightly). To install another toolchain use

```bash
rustup toolchain install nightly
```

Where `nightly` here is the channel to add. To update your toolchains, run

```bash
rustup update
```

To build your project using a specified toolchain, use something like

```bash
cargo +nightly build
```

Where `nightly` names the toolchain (by specifying the channel, in this case).
58 changes: 58 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#![feature(async_await)]
use core::fmt::Debug;
use proptest::{
self,
strategy::{Strategy, ValueTree},
};

#[cfg(feature = "integration-tests")]
use criterion::criterion_main;
#[cfg(feature = "integration-tests")]
mod integration;

use std::env::var;

// Typical usage
pub const DEFAULT_KEY_SIZE_BOUND: usize = 512;
pub const DEFAULT_VALUE_SIZE_BOUND: usize = 2048;
pub const DEFAULT_BATCH_BOUND: usize = 8;

pub const ENV_PD_ADDR: &str = "PD_ADDR";

pub fn pd_addrs() -> Vec<String> {
var(ENV_PD_ADDR)
.expect(&format!("Expected {}:", ENV_PD_ADDR))
.split(",")
.map(From::from)
.collect()
}

pub fn generate<T: Debug>(strat: impl Strategy<Value = T>) -> T {
strat
.new_tree(&mut proptest::test_runner::TestRunner::new(
proptest::test_runner::Config::default(),
))
.unwrap()
.current()
}

#[cfg(feature = "proptest")]
const PROPTEST_BATCH_SIZE_MAX: usize = 16;

#[cfg(feature = "proptest")]
pub fn arb_batch<T: core::fmt::Debug>(
single_strategy: impl Strategy<Value = T>,
max_batch_size: impl Into<Option<usize>>,
) -> impl Strategy<Value = Vec<T>> {
let max_batch_size = max_batch_size.into().unwrap_or(PROPTEST_BATCH_SIZE_MAX);
proptest::collection::vec(single_strategy, 0..max_batch_size)
}


#[cfg(feature = "integration-tests")]
criterion_main!(integration::raw::suite);

#[cfg(not(feature = "integration-tests"))]
fn main() {
unimplemented!();
}
1 change: 1 addition & 0 deletions benches/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod raw;
Loading

0 comments on commit e17d3f1

Please sign in to comment.