Skip to content

Commit

Permalink
PR to fix issue #109 (running out of files on OSX) (#112)
Browse files Browse the repository at this point in the history
* Move to new version of DB and re-enable tests
* Create store explicitly, and add file limit when testing
* Raise the shell fdlimit on OSX before running tests (#114)

Co-authored-by: George Danezis <[email protected]>
Co-authored-by: François Garillot <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2022
1 parent d15cdd2 commit e29c107
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 19 deletions.
5 changes: 4 additions & 1 deletion fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tokio::{runtime::Builder, time};

use std::env;
use std::fs;
use std::sync::Arc;
use std::thread;
use strum_macros::EnumString;

Expand Down Expand Up @@ -121,7 +122,9 @@ impl ClientServerBenchmark {
let path = dir.join(format!("DB_{:?}", ObjectID::random()));
fs::create_dir(&path).unwrap();

let state = AuthorityState::new(committee.clone(), public_auth0, secret_auth0.copy(), path);
let store = Arc::new(AuthorityStore::open(path, None));
let state =
AuthorityState::new(committee.clone(), public_auth0, secret_auth0.copy(), store);

// Seed user accounts.
let mut rt = Runtime::new().unwrap();
Expand Down
7 changes: 6 additions & 1 deletion fastpay/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fastx_types::{base_types::*, committee::Committee, object::Object};
use futures::future::join_all;
use log::*;
use std::path::Path;
use std::sync::Arc;
use structopt::StructOpt;
use tokio::runtime::Runtime;

Expand All @@ -30,11 +31,15 @@ fn make_server(

let committee = Committee::new(committee_config.voting_rights());

let store = Arc::new(AuthorityStore::open(
Path::new(&server_config.authority.database_path),
None,
));
let state = AuthorityState::new(
committee,
server_config.authority.address,
server_config.key.copy(),
Path::new(&server_config.authority.database_path),
store,
);

// Load initial states
Expand Down
6 changes: 5 additions & 1 deletion fastpay_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ publish = false
edition = "2018"

[dependencies]
rocksdb = "0.17.0"
anyhow = "1.0"
bcs = "0.1.2"
failure = "0.1.8"
Expand All @@ -23,4 +24,7 @@ move-core-types = { git = "https://github.com/diem/diem", rev="346301f33b3489bb4
move-vm-runtime = { git = "https://github.com/diem/diem", rev="346301f33b3489bb4e486ae6c0aa5e030223b492" }


typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "b6bb469e0752222b1c990b1d8f39c69d4dbf12a9" }
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "c1ab69f1a4004414bf0dee412f2e5839b71bc8f6" }

[dev-dependencies]
fdlimit = "0.2.1"
9 changes: 4 additions & 5 deletions fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use move_core_types::{
resolver::{ModuleResolver, ResourceResolver},
};
use move_vm_runtime::native_functions::NativeFunctionTable;
use std::path::Path;
use std::{
collections::{BTreeMap, HashSet},
sync::Arc,
Expand All @@ -31,7 +30,7 @@ mod temporary_store;
use temporary_store::AuthorityTemporaryStore;

mod authority_store;
use authority_store::AuthorityStore;
pub use authority_store::AuthorityStore;

pub struct AuthorityState {
// Fixed size, static, identity of the authority
Expand Down Expand Up @@ -282,18 +281,18 @@ impl AuthorityState {
}

impl AuthorityState {
pub fn new<P: AsRef<Path>>(
pub fn new(
committee: Committee,
name: AuthorityName,
secret: KeyPair,
path: P,
store: Arc<AuthorityStore>,
) -> Self {
AuthorityState {
committee,
name,
secret,
native_functions: NativeFunctionTable::new(),
_database: Arc::new(AuthorityStore::open(path)),
_database: store,
}
}

Expand Down
5 changes: 3 additions & 2 deletions fastpay_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

use rocksdb::Options;
use std::path::Path;
use std::sync::Mutex;
use typed_store::rocks::{open_cf, DBMap};
Expand All @@ -16,10 +17,10 @@ pub struct AuthorityStore {

impl AuthorityStore {
/// Open an authority store by directory path
pub fn open<P: AsRef<Path>>(path: P) -> AuthorityStore {
pub fn open<P: AsRef<Path>>(path: P, db_options: Option<Options>) -> AuthorityStore {
let db = open_cf(
&path,
None,
db_options,
&[
"objects",
"order_lock",
Expand Down
25 changes: 21 additions & 4 deletions fastpay_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ use move_binary_format::{
};
use move_core_types::ident_str;

use std::env;
use std::fs;
use std::{convert::TryInto, env};

pub fn system_maxfiles() -> usize {
fdlimit::raise_fd_limit().unwrap_or(256u64) as usize
}

fn max_files_authority_tests() -> i32 {
(system_maxfiles() / 8).try_into().unwrap()
}

#[tokio::test]
async fn test_handle_transfer_order_bad_signature() {
Expand Down Expand Up @@ -572,11 +580,14 @@ async fn test_authority_persist() {
fs::create_dir(&path).unwrap();

// Create an authority
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
let store = Arc::new(AuthorityStore::open(&path, Some(opts)));
let authority = AuthorityState::new(
committee.clone(),
authority_address,
authority_key.copy(),
&path,
store,
);

// Create an object
Expand All @@ -593,7 +604,10 @@ async fn test_authority_persist() {
drop(authority);

// Reopen the authority with the same path
let authority2 = AuthorityState::new(committee, authority_address, authority_key, &path);
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
let store = Arc::new(AuthorityStore::open(&path, Some(opts)));
let authority2 = AuthorityState::new(committee, authority_address, authority_key, store);
let obj2 = authority2.object_state(&object_id).await.unwrap();

// Check the object is present
Expand All @@ -618,7 +632,10 @@ fn init_state() -> AuthorityState {
let path = dir.join(format!("DB_{:?}", ObjectID::random()));
fs::create_dir(&path).unwrap();

AuthorityState::new(committee, authority_address, authority_key, path)
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
let store = Arc::new(AuthorityStore::open(path, Some(opts)));
AuthorityState::new(committee, authority_address, authority_key, store)
}

#[cfg(test)]
Expand Down
23 changes: 18 additions & 5 deletions fastpay_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
#![allow(clippy::same_item_push)] // get_key_pair returns random elements

use super::*;
use crate::authority::AuthorityState;
use crate::authority::{AuthorityState, AuthorityStore};
use fastx_types::object::Object;
use futures::lock::Mutex;
use std::{
collections::{BTreeMap, HashMap},
convert::TryInto,
sync::Arc,
};
use tokio::runtime::Runtime;

use std::env;
use std::fs;

pub fn system_maxfiles() -> usize {
fdlimit::raise_fd_limit().unwrap_or(256u64) as usize
}

fn max_files_client_tests() -> i32 {
(system_maxfiles() / 8).try_into().unwrap()
}

#[derive(Clone)]
struct LocalAuthorityClient(Arc<Mutex<AuthorityState>>);

Expand Down Expand Up @@ -73,7 +82,10 @@ fn init_local_authorities(
let path = dir.join(format!("DB_{:?}", ObjectID::random()));
fs::create_dir(&path).unwrap();

let state = AuthorityState::new(committee.clone(), address, secret, path);
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_client_tests());
let store = Arc::new(AuthorityStore::open(path, Some(opts)));
let state = AuthorityState::new(committee.clone(), address, secret, store);
clients.insert(address, LocalAuthorityClient::new(state));
}
(clients, committee)
Expand Down Expand Up @@ -104,7 +116,10 @@ fn init_local_authorities_bad_1(
let path = dir.join(format!("DB_{:?}", ObjectID::random()));
fs::create_dir(&path).unwrap();

let state = AuthorityState::new(committee.clone(), address, secret, path);
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_client_tests());
let store = Arc::new(AuthorityStore::open(path, Some(opts)));
let state = AuthorityState::new(committee.clone(), address, secret, store);
clients.insert(address, LocalAuthorityClient::new(state));
}
(clients, committee)
Expand Down Expand Up @@ -219,7 +234,6 @@ fn test_get_strong_majority_owner() {
}

#[test]
#[ignore = "Enable after https://github.com/MystenLabs/fastnft/issues/109 is fixed"]
fn test_initiating_valid_transfer() {
let mut rt = Runtime::new().unwrap();
let (recipient, _) = get_key_pair();
Expand Down Expand Up @@ -273,7 +287,6 @@ fn test_initiating_valid_transfer() {
}

#[test]
#[ignore = "Enable after https://github.com/MystenLabs/fastnft/issues/109 is fixed"]
fn test_initiating_valid_transfer_despite_bad_authority() {
let mut rt = Runtime::new().unwrap();
let (recipient, _) = get_key_pair();
Expand Down

1 comment on commit e29c107

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bench results

�[0m�[1m�[33mwarning�[0m�[0m�[1m: unused variable: num_immutable_objects�[0m
�[0m �[0m�[0m�[1m�[38;5;12m--> �[0m�[0mfastx_programmability/adapter/src/adapter.rs:370:13�[0m
�[0m �[0m�[0m�[1m�[38;5;12m|�[0m
�[0m�[1m�[38;5;12m370�[0m�[0m �[0m�[0m�[1m�[38;5;12m| �[0m�[0m let mut num_immutable_objects = 0;�[0m
�[0m �[0m�[0m�[1m�[38;5;12m| �[0m�[0m �[0m�[0m�[1m�[33m^^^^^^^^^^^^^^^^^^^^^�[0m�[0m �[0m�[0m�[1m�[33mhelp: if this is intentional, prefix it with an underscore: _num_immutable_objects�[0m
�[0m �[0m�[0m�[1m�[38;5;12m= �[0m�[0m�[1mnote�[0m�[0m: #[warn(unused_variables)] on by default�[0m

�[0m�[0m�[1m�[33mwarning�[0m�[1m:�[0m fastx-adapter (lib) generated 1 warning
�[0m�[0m�[1m�[32m Finished�[0m release [optimized + debuginfo] target(s) in 1.76s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
[2022-01-04T11:42:35Z INFO bench] Starting benchmark: OrdersAndCerts
[2022-01-04T11:42:35Z INFO bench] Preparing accounts.
[2022-01-04T11:42:37Z INFO bench] Preparing transactions.
[2022-01-04T11:42:45Z INFO fastpay::network] Listening to Tcp traffic on 127.0.0.1:9555
[2022-01-04T11:42:46Z INFO bench] Set max_in_flight to 500
[2022-01-04T11:42:46Z INFO bench] Sending requests.
[2022-01-04T11:42:46Z INFO fastpay::network] Sending Tcp requests to 127.0.0.1:9555
[2022-01-04T11:42:47Z INFO fastpay::network] 127.0.0.1:9555 has processed 5000 packets
[2022-01-04T11:42:47Z INFO fastpay::network] In flight 500 Remaining 35000
[2022-01-04T11:42:47Z INFO fastpay::network] 127.0.0.1:9555 has processed 10000 packets
[2022-01-04T11:42:48Z INFO fastpay::network] 127.0.0.1:9555 has processed 15000 packets
[2022-01-04T11:42:49Z INFO fastpay::network] In flight 500 Remaining 30000
[2022-01-04T11:42:49Z INFO fastpay::network] 127.0.0.1:9555 has processed 20000 packets
[2022-01-04T11:42:50Z INFO fastpay::network] 127.0.0.1:9555 has processed 25000 packets
[2022-01-04T11:42:51Z INFO fastpay::network] In flight 500 Remaining 25000
[2022-01-04T11:42:51Z INFO fastpay::network] 127.0.0.1:9555 has processed 30000 packets
[2022-01-04T11:42:52Z INFO fastpay::network] 127.0.0.1:9555 has processed 35000 packets
[2022-01-04T11:42:53Z INFO fastpay::network] In flight 500 Remaining 20000
[2022-01-04T11:42:53Z INFO fastpay::network] 127.0.0.1:9555 has processed 40000 packets
[2022-01-04T11:42:54Z INFO fastpay::network] 127.0.0.1:9555 has processed 45000 packets
[2022-01-04T11:42:55Z INFO fastpay::network] In flight 500 Remaining 15000
[2022-01-04T11:42:55Z INFO fastpay::network] 127.0.0.1:9555 has processed 50000 packets
[2022-01-04T11:42:56Z INFO fastpay::network] 127.0.0.1:9555 has processed 55000 packets
[2022-01-04T11:42:57Z INFO fastpay::network] In flight 500 Remaining 10000
[2022-01-04T11:42:57Z INFO fastpay::network] 127.0.0.1:9555 has processed 60000 packets
[2022-01-04T11:42:58Z INFO fastpay::network] 127.0.0.1:9555 has processed 65000 packets
[2022-01-04T11:42:59Z INFO fastpay::network] In flight 500 Remaining 5000
[2022-01-04T11:42:59Z INFO fastpay::network] 127.0.0.1:9555 has processed 70000 packets
[2022-01-04T11:42:59Z INFO fastpay::network] 127.0.0.1:9555 has processed 75000 packets
[2022-01-04T11:43:00Z INFO fastpay::network] Done sending Tcp requests to 127.0.0.1:9555
[2022-01-04T11:43:00Z INFO fastpay::network] 127.0.0.1:9555 has processed 80000 packets
[2022-01-04T11:43:00Z INFO bench] Received 80000 responses.
[2022-01-04T11:43:00Z WARN bench] Completed benchmark for OrdersAndCerts
Total time: 14555226us, items: 40000, tx/sec: 2748.1538246125483

Please sign in to comment.