Skip to content

Add some benchmarks #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ edition = "2018"
default = []
# Enable integration tests with a running TiKV and PD instance.
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
integration-tests = []
integration-tests = ["property-testing"]
# Enable propery testing features with `proptest`.
property-testing = ["proptest", "proptest-derive"]

[lib]
name = "tikv_client"
Expand All @@ -28,6 +30,8 @@ serde = "1.0"
serde_derive = "1.0"
tokio-core = "0.1"
tokio-timer = "0.2"
proptest = { version = "0.9", optional = true }
proptest-derive = { version = "0.1.0", optional = true }

[dependencies.kvproto]
git = "https://github.com/pingcap/kvproto.git"
Expand All @@ -38,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).
57 changes: 57 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.

#![feature(async_await)]

#[cfg(feature = "property-testing")]
use core::fmt::Debug;
#[cfg(feature = "integration-tests")]
use criterion::criterion_main;
#[cfg(feature = "property-testing")]
use proptest::{
self,
strategy::{Strategy, ValueTree},
};
#[cfg(feature = "property-testing")]
mod integration;

use std::env::var;

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()
}

#[cfg(feature = "property-testing")]
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 = "property-testing")]
const PROPTEST_BATCH_SIZE_MAX: usize = 16;

#[cfg(feature = "property-testing")]
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!("Try adding the `integration-tests` feature with the `PD_ADDR` ENV variable.");
}
16 changes: 16 additions & 0 deletions benches/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.

// All integration tests are deliberately annotated by
//
// ```
// #[cfg_attr(not(feature = "integration-tests"), ignore)]
// ```
//
// This is so that integration tests are still compiled even if they aren't run.
// This helps avoid having broken integration tests even if they aren't run.

// If integration tests aren't being run, we still want to build them. We'll have unused things
// though. Allow that.
#![cfg_attr(not(feature = "integration-tests"), allow(dead_code))]

pub mod raw;
Loading