Skip to content

Commit

Permalink
Initial commit, as copied from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 22, 2020
0 parents commit 708901b
Show file tree
Hide file tree
Showing 17 changed files with 2,318 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Created by https://www.gitignore.io/api/rust
# Edit at https://www.gitignore.io/?templates=rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# End of https://www.gitignore.io/api/rust
50 changes: 50 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "prodash"
version = "1.1.1"
authors = ["Sebastian Thiel <[email protected]>"]
description = "A dashboard for visualizing progress of asynchronous and possibly blocking tasks"
edition = "2018"
include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE.md"]
license = "MIT"
repository = "https://github.com/Byron/crates-io-cli-rs"
readme = "README.md"

[lib]
doctest = true

[features]
default = ["tui-renderer", "log-renderer"]
tui-renderer = ["tui", "tui-react", "termion", "futures-timer", "futures", "unicode-segmentation", "unicode-width", "humantime" ]
log-renderer = ["log"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dashmap = "3.4.3"
parking_lot = "0.10.0"

# with-logging
log = { version = "0.4.8", optional = true }

# tui-renderer
tui = { version = "0.8.0", optional = true }
tui-react = { version = "0.2.0", optional = true }
termion = { version = "1.5.5", optional = true }
futures-timer = { version = "3.0.1", optional = true }
futures = { version = "0.3.4", optional = true }
unicode-segmentation = { version = "1.6.0", optional = true }
humantime = { version = "2.0.0", optional = true }
unicode-width = { version = "0.1.7", optional = true }

[dev-dependencies]
futures = { version = "0.3.4", features = ["thread-pool"] }
futures-timer = "3.0.1"
rand = "0.7.3"
env_logger = { version = "0.7.1", default-features = false, features = ["termcolor", "atty", "humantime"] }
criterion = "0.3.1"
termion = "1.5.5"
argh = "0.1.3"

[[bench]]
name = "usage"
path = "benches/usage.rs"
harness = false
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2020` `Sebastian Thiel`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
**prodash** is a dashboard for displaying progress of concurrent applications.

It's easy to integrate thanks to a pragmatic API, and comes with a terminal user interface by default.

[![asciicast](https://asciinema.org/a/301838.svg)](https://asciinema.org/a/301838)

## How to use…

Be sure to read the documentation at https://docs.rs/prodash, it contains various examples on how to get started.

Or run the demo application like so `cd prodash && cargo run --example dashboard`.

## Features

* fast insertions and updates for transparent progress tracking of highly concurrent programs
* a messages buffer for information about success and failure
* a terminal user interface for visualization, with keyboard controls and dynamic re-sizing
* unicode and multi-width character support

## Limitations

* it does copy quite some state each time it displays progress information and messages
* The underlying sync data structure, `dashmap`, does not document every use of unsafe
* I also evaluated `evmap`, which has 25% less uses of unsafe, but a more complex interface.
* Thus far it seemed 'ok' to use, who knows… we are getting mutable pieces of a hashmap from multiple threads,
however, we never hand out multiple handles to the same child which should make actual concurrent access to
the same key impossible.
* If there are more than 2^16 tasks
* then
* running concurrently on a single level of the tree, they start overwriting each other
* over its lifetime, even though they do not run concurrently, eventually new tasks will seem like old tasks (their ID wrapped around)
* why
* on drop, they never decrement a child count used to generate a new ID
* fix
* make the id bigger, like u32
* we should do that once there is a performance test

## Lessons Learned

* `drop()` is not garantueed to be called when the future returns Ready and is in the futures::executor::ThreadPool
* Workaround: drop and cleanup explicitly, prone to forgetting it.
* This is also why `futures::future::abortable()` works (by stopping the polling), but doesn't as cleanup is not performed,
even though it clearly would be preferred.
* fix
* Use a join handle and await it - this will drop the future properly
* `select()` might not work with complex futures - these should then be `boxed()` if `Unpin` isn't implemented.
70 changes: 70 additions & 0 deletions benches/usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use criterion::*;

use prodash::{tree::MessageLevel, Tree, TreeOptions};

fn usage(c: &mut Criterion) {
fn small_tree() -> Tree {
TreeOptions {
initial_capacity: 10,
message_buffer_capacity: 2,
}
.create()
};
c.benchmark_group("Tree::add_child")
.throughput(Throughput::Elements(4))
.bench_function(
"add children to build a tree of tasks and clear them (in drop)",
|b| {
let root = small_tree();
b.iter(|| {
let mut c = root.add_child("1");
let _one = c.add_child("1");
let _two = c.add_child("2");
let _three = c.add_child("3");
});
},
);
c.benchmark_group("tree::Item::set")
.throughput(Throughput::Elements(5))
.bench_function("set tree 5 times", |b| {
let root = small_tree();
let mut progress = root.add_child("the one");
progress.init(Some(20), Some("element"));
b.iter(|| {
progress.set(1);
progress.set(2);
progress.set(3);
progress.set(4);
progress.set(5);
});
});
c.benchmark_group("tree::Item::message")
.throughput(Throughput::Elements(1))
.bench_function(
"send one message with a full message buffer (worst case performance)",
|b| {
let root = small_tree();
let mut progress = root.add_child("the one");
progress.init(Some(20), Some("element"));
b.iter(|| {
progress.message(MessageLevel::Success, "for testing");
});
},
);
c.benchmark_group("Tree::copy_messages")
.throughput(Throughput::Elements(2))
.bench_function("copy all messages with buffer being at capacity", |b| {
let root = small_tree();
let mut progress = root.add_child("the one");
progress.init(Some(20), Some("element"));
progress.done("foo");
progress.done("bar");
let mut out = Vec::new();
b.iter(|| {
root.copy_messages(&mut out);
});
});
}

criterion_group!(benches, usage);
criterion_main!(benches);
Loading

0 comments on commit 708901b

Please sign in to comment.