Skip to content

Commit

Permalink
Merge pull request #230 from hackerchai/upgrade-tokio
Browse files Browse the repository at this point in the history
Upgrade tokio
  • Loading branch information
hsluoyz authored Jan 30, 2021
2 parents 9c68fc9 + 622a95f commit 85a74a1
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 36 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: Changelog Generator

on:
push:
branches:
- master
tags:
- '*'
release:
types: [created, edited]

jobs:
generate_changelog_file:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [Unreleased](https://github.com/casbin/casbin-rs/tree/HEAD)

[Full Changelog](https://github.com/casbin/casbin-rs/compare/v2.0.5...HEAD)

**Implemented enhancements:**

- Support policy.csv comment or YAML file adapter [\#213](https://github.com/casbin/casbin-rs/issues/213)

## [v2.0.5](https://github.com/casbin/casbin-rs/tree/v2.0.5) (2020-12-24)

[Full Changelog](https://github.com/casbin/casbin-rs/compare/v2.0.3...v2.0.5)
Expand All @@ -10,6 +18,7 @@

**Fixed bugs:**

- not currently running on the Tokio runtime on tonic [\#221](https://github.com/casbin/casbin-rs/issues/221)
- CSV loader deletes double quotes [\#214](https://github.com/casbin/casbin-rs/issues/214)

**Closed issues:**
Expand Down
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ license = "Apache-2.0"
name = "casbin"
readme = "README.md"
repository = "https://github.com/casbin/casbin-rs"
version = "2.0.5"
version = "2.0.6"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-std = { version = "1.8.0", optional = true }
async-trait = "0.1.37"
globset = { version = "0.4.5", optional = true }
indexmap = "1.6.0"
async-std = { version = "1.9.0", optional = true }
async-trait = "0.1.42"
globset = { version = "0.4.6", optional = true }
indexmap = "1.6.1"
ip_network = { version = "0.3.4", optional = true }
lazy_static = "1.4.0"
lru = { version = "0.6.2", optional = true }
regex = "1.4.0"
rhai = { version = "0.19.7", features = [
lru = { version = "0.6.3", optional = true }
regex = "1.4.3"
rhai = { version = "0.19.10", features = [
"sync",
"only_i32",
"no_function",
Expand All @@ -31,12 +31,13 @@ rhai = { version = "0.19.7", features = [
"serde",
"unchecked",
] }
serde = "1.0.115"
serde = "1.0.123"
slog = { version = "2.7.0", optional = true }
slog-async = { version = "2.5.0", optional = true }
slog-term = { version = "2.6.0", optional = true }
thiserror = "1.0.20"
tokio = { version = "~0.2", optional = true, default-features = false }
thiserror = "1.0.23"
tokio = { version = "1.1.1", optional = true, default-features = false }
tokio-stream = { version = "0.1", optional = true, default-features = false }

[features]
default = ["runtime-async-std", "incremental"]
Expand All @@ -52,13 +53,13 @@ runtime-tokio = ["tokio/fs", "tokio/io-util"]
watcher = []

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0.115", features = ["derive"] }
async-std = { version = "1.9.0", features = ["attributes"] }
serde = { version = "1.0.123", features = ["derive"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0.115", features = ["derive"] }
tokio = { version = "~0.2", features = ["full"] }
async-std = { version = "1.9.0", features = ["attributes"] }
serde = { version = "1.0.123", features = ["derive"] }
tokio = { version = "1.1.1", features = ["full"] }

[profile.release]
codegen-units = 1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Add this package to `Cargo.toml` of your project. (Check https://crates.io/crate

```toml
[dependencies]
casbin = { version = "2.0.5", default-features = false, features = ["runtime-async-std", "logging", "incremental"] }
async-std = { version = "1.8", features = ["attributes"] }
casbin = { version = "2.0.6", default-features = false, features = ["runtime-async-std", "logging", "incremental"] }
async-std = { version = "1.9", features = ["attributes"] }
```

## Get started
Expand Down
18 changes: 15 additions & 3 deletions src/adapter/file_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::{
use tokio::{
fs::File,
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
stream::StreamExt,
};

use async_trait::async_trait;
Expand Down Expand Up @@ -58,9 +57,14 @@ where
) -> Result<()> {
let f = File::open(&self.file_path).await?;
let mut lines = BufReader::new(f).lines();

#[cfg(feature = "runtime-async-std")]
while let Some(line) = lines.next().await {
handler(line?, m);
handler(line?, m)
}

#[cfg(feature = "runtime-tokio")]
while let Some(line) = lines.next_line().await? {
handler(line, m)
}

Ok(())
Expand All @@ -76,12 +80,20 @@ where
let mut lines = BufReader::new(f).lines();

let mut is_filtered = false;
#[cfg(feature = "runtime-async-std")]
while let Some(line) = lines.next().await {
if handler(line?, m, &filter) {
is_filtered = true;
}
}

#[cfg(feature = "runtime-tokio")]
while let Some(line) = lines.next_line().await? {
if handler(line, m, &filter) {
is_filtered = true;
}
}

Ok(is_filtered)
}

Expand Down
4 changes: 1 addition & 3 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ macro_rules! impl_args {
{
fn try_into_vec(self) -> Result<Vec<Dynamic>> {
let ($($p,)*) = self;

let mut _v = Vec::new();
$(_v.push(to_dynamic($p)?);)*
let _v = vec![$(to_dynamic($p)?,)*];

Ok(_v)
}
Expand Down
2 changes: 1 addition & 1 deletion src/enforcer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl CoreApi for Enforcer {

let mut engine = Engine::new_raw();

engine.load_package(CASBIN_PACKAGE.get());
engine.register_global_module(CASBIN_PACKAGE.as_shared_module());

for (key, &func) in fm.get_functions() {
engine.register_fn(key, func);
Expand Down
6 changes: 2 additions & 4 deletions src/rbac/default_role_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ impl RoleManager for DefaultRoleManager {
let role2 = self.create_role(name2, domain);

if !role1.write().unwrap().add_role(role2) {
return;
#[cfg(feature = "cached")]
self.cache.clear();
}

#[cfg(feature = "cached")]
self.cache.clear();
}

fn matching_fn(
Expand Down
3 changes: 1 addition & 2 deletions src/rbac_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,7 @@ mod tests {

#[cfg(feature = "runtime-tokio")]
{
tokio::runtime::Builder::new()
.basic_scheduler()
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
Expand Down

2 comments on commit 85a74a1

@GopherJ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 85a74a1 Previous: 998c3f6 Ratio
b_benchmark_abac_model 6109 ns/iter (± 86) 6397 ns/iter (± 354) 0.95
b_benchmark_basic_model 7902 ns/iter (± 191) 9249 ns/iter (± 800) 0.85
b_benchmark_cached_abac_model 926 ns/iter (± 22) 1070 ns/iter (± 91) 0.87
b_benchmark_cached_key_match 390 ns/iter (± 4) 441 ns/iter (± 35) 0.88
b_benchmark_cached_priority_model 384 ns/iter (± 2) 454 ns/iter (± 40) 0.85
b_benchmark_cached_rbac_model 380 ns/iter (± 2) 458 ns/iter (± 29) 0.83
b_benchmark_cached_rbac_model_large 385 ns/iter (± 3) 432 ns/iter (± 30) 0.89
b_benchmark_cached_rbac_model_medium 378 ns/iter (± 4) 406 ns/iter (± 54) 0.93
b_benchmark_cached_rbac_model_small 384 ns/iter (± 3) 457 ns/iter (± 29) 0.84
b_benchmark_cached_rbac_model_with_domains 657 ns/iter (± 2) 749 ns/iter (± 50) 0.88
b_benchmark_cached_rbac_with_deny 384 ns/iter (± 4) 433 ns/iter (± 26) 0.89
b_benchmark_cached_rbac_with_resource_roles 381 ns/iter (± 2) 447 ns/iter (± 58) 0.85
b_benchmark_key_match 25720 ns/iter (± 312) 26510 ns/iter (± 927) 0.97
b_benchmark_priority_model 9708 ns/iter (± 76) 9619 ns/iter (± 547) 1.01
b_benchmark_raw 14 ns/iter (± 0) 8 ns/iter (± 0) 1.75
b_benchmark_rbac_model 11955 ns/iter (± 103) 12358 ns/iter (± 588) 0.97
b_benchmark_rbac_model_large 13929486 ns/iter (± 289233) 15586168 ns/iter (± 650834) 0.89
b_benchmark_rbac_model_medium 1349121 ns/iter (± 4205) 1459919 ns/iter (± 64787) 0.92
b_benchmark_rbac_model_small 140991 ns/iter (± 1135) 155404 ns/iter (± 23514) 0.91
b_benchmark_rbac_model_with_domains 13213 ns/iter (± 90) 12651 ns/iter (± 2401) 1.04
b_benchmark_rbac_with_deny 15099 ns/iter (± 98) 14984 ns/iter (± 560) 1.01
b_benchmark_rbac_with_resource_roles 10639 ns/iter (± 91) 10600 ns/iter (± 733) 1.00
b_benchmark_role_manager_large 6749499 ns/iter (± 14235) 7464496 ns/iter (± 222629) 0.90
b_benchmark_role_manager_medium 620443 ns/iter (± 3828) 704320 ns/iter (± 23977) 0.88
b_benchmark_role_manager_small 61319 ns/iter (± 254) 67926 ns/iter (± 4216) 0.90
b_benmark_cached_basic_model 380 ns/iter (± 3) 455 ns/iter (± 42) 0.84

This comment was automatically generated by workflow using github-action-benchmark.

@GopherJ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 85a74a1 Previous: 998c3f6 Ratio
b_benchmark_raw 14 ns/iter (± 0) 8 ns/iter (± 0) 1.75

This comment was automatically generated by workflow using github-action-benchmark.

CC: @GopherJ

Please sign in to comment.