Skip to content

Commit

Permalink
Merge branch 'main' into mkysel/xdgb-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mkysel authored Dec 16, 2024
2 parents 9dbedd8 + 97eca90 commit cf6f0fb
Show file tree
Hide file tree
Showing 40 changed files with 853 additions and 264 deletions.
1 change: 1 addition & 0 deletions .cargo/nextest.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[profile.default]
retries = 3
default-filter = "not test(test_stream_all_messages_does_not_lose_messages)"
4 changes: 2 additions & 2 deletions .github/workflows/test-http-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: build tests
run: cargo nextest run --no-run --tests --workspace --exclude xmtp_api_grpc --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm --features http-api
run: cargo nextest run --config-file ".cargo/nextest.toml" --no-run --tests --workspace --exclude xmtp_api_grpc --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm --features http-api
- name: cargo test
run: cargo nextest run --workspace --exclude xmtp_api_grpc --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm --features http-api --test-threads 2
run: cargo nextest run --config-file ".cargo/nextest.toml" --workspace --exclude xmtp_api_grpc --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm --features http-api --test-threads 2
52 changes: 27 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
"xtask",
"xmtp_debug",
"xmtp_content_types",
"common"
"common",
]

# Make the feature resolver explicit.
Expand Down Expand Up @@ -75,7 +75,6 @@ bincode = "1.3"
console_error_panic_hook = "0.1"
const_format = "0.2"
diesel = { version = "2.2", default-features = false }
diesel-wasm-sqlite = "0.0.1"
diesel_migrations = { version = "2.2", default-features = false }
dyn-clone = "1"
fdlimit = "0.3"
Expand All @@ -87,6 +86,7 @@ libsqlite3-sys = { version = "0.29", features = [
openssl = { version = "0.10", features = ["vendored"] }
openssl-sys = { version = "0.9", features = ["vendored"] }
parking_lot = "0.12.3"
sqlite-web = "0.0.1"
tonic = { version = "0.12", default-features = false }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false }
Expand All @@ -97,21 +97,29 @@ wasm-bindgen-futures = "0.4"
wasm-bindgen-test = "0.3.49"
web-sys = "0.3"
zeroize = "1.8"
criterion = { version = "0.5", features = [
"html_reports",
"async_tokio",
]}
once_cell = "1.2"

# Internal Crate Dependencies
xmtp_api_grpc = { path = "xmtp_api_grpc" }
xmtp_common = { path = "common" }
xmtp_content_types = { path = "xmtp_content_types" }
xmtp_cryptography = { path = "xmtp_cryptography" }
xmtp_id = { path = "xmtp_id" }
xmtp_mls = { path = "xmtp_mls" }
xmtp_proto = { path = "xmtp_proto" }
xmtp_content_types = { path = "xmtp_content_types" }
xmtp_common = { path = "common" }

[profile.dev]
# Disabling debug info speeds up builds a bunch,
# and we don't rely on it for debugging that much.
debug = 0

[profile.bench]
debug = true

# Setting opt-level to 3 for proc macros/build scripts
# speeds up buildtime
[profile.dev.build-override]
Expand Down Expand Up @@ -147,6 +155,6 @@ opt-level = "s"
# (cfg-specific patche support does not exist)
[patch.crates-io]
diesel = { git = "https://github.com/diesel-rs/diesel", branch = "master" }
diesel-wasm-sqlite = { git = "https://github.com/xmtp/sqlite-web-rs", branch = "main" }
diesel_derives = { git = "https://github.com/diesel-rs/diesel", branch = "master" }
diesel_migrations = { git = "https://github.com/diesel-rs/diesel", branch = "master" }
sqlite-web = { git = "https://github.com/xmtp/sqlite-web-rs", branch = "main" }
14 changes: 14 additions & 0 deletions bindings_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ xmtp_user_preferences = { path = "../xmtp_user_preferences" }
xmtp_v2 = { path = "../xmtp_v2" }
xmtp_common.workspace = true

# Bench
criterion = { workspace = true, optional = true }
fdlimit = { version = "0.3", optional = true}


[target.'cfg(target_os = "android")'.dependencies]
paranoid-android = "0.2"

Expand All @@ -47,3 +52,12 @@ uuid = { workspace = true, features = ["v4", "fast-rng"] }
xmtp_api_grpc = { path = "../xmtp_api_grpc", features = ["test-utils"] }
xmtp_mls = { path = "../xmtp_mls", features = ["test-utils"] }
xmtp_proto = { path = "../xmtp_proto", features = ["test-utils"] }

[features]
bench = ["xmtp_mls/bench", "xmtp_common/bench", "dep:criterion", "dep:fdlimit"]

[[bench]]
harness = false
name = "create_client"
required-features = ["bench"]

148 changes: 148 additions & 0 deletions bindings_ffi/benches/create_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//! NOTE:
// `MAX_DB_POOL_SIZE` in `configuration.rs` must be set to `10`
// in order for these benchmarks to succesfully run & generate a report.
// (file descriptor issue)

use crate::tracing::Instrument;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use tokio::runtime::{Builder, Runtime};
use xmtp_common::{bench::BENCH_ROOT_SPAN, tmp_path};
use xmtp_id::InboxOwner;
use xmtp_mls::utils::test::HISTORY_SYNC_URL;
use xmtpv3::generate_inbox_id;

#[macro_use]
extern crate tracing;

fn setup() -> Runtime {
Builder::new_multi_thread()
.enable_time()
.enable_io()
.thread_name("xmtp-bencher")
.build()
.unwrap()
}

fn network_url() -> (String, bool) {
let dev = std::env::var("DEV_GRPC");
let is_dev_network = matches!(dev, Ok(d) if d == "true" || d == "1");

if is_dev_network {
(xmtp_api_grpc::DEV_ADDRESS.to_string(), true)
} else {
(xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(), false)
}
}

fn create_ffi_client(c: &mut Criterion) {
xmtp_common::bench::logger();

let runtime = setup();

let _ = fdlimit::raise_fd_limit();
let mut benchmark_group = c.benchmark_group("create_client");

// benchmark_group.sample_size(10);
benchmark_group.sampling_mode(criterion::SamplingMode::Flat);
benchmark_group.bench_function("create_ffi_client", |b| {
let span = trace_span!(BENCH_ROOT_SPAN);
b.to_async(&runtime).iter_batched(
|| {
let wallet = xmtp_cryptography::utils::generate_local_wallet();
let nonce = 1;
let inbox_id = generate_inbox_id(wallet.get_address(), nonce).unwrap();
let path = tmp_path();
let (network, is_secure) = network_url();
(
inbox_id,
wallet.get_address(),
nonce,
path,
network,
is_secure,
span.clone(),
)
},
|(inbox_id, address, nonce, path, network, is_secure, span)| async move {
xmtpv3::mls::create_client(
network,
is_secure,
Some(path),
Some(vec![0u8; 32]),
&inbox_id,
address,
nonce,
None,
Some(HISTORY_SYNC_URL.to_string()),
)
.instrument(span)
.await
.unwrap();
},
BatchSize::SmallInput,
)
});

benchmark_group.finish();
}

fn cached_create_ffi_client(c: &mut Criterion) {
xmtp_common::bench::logger();

let runtime = setup();

let _ = fdlimit::raise_fd_limit();
let mut benchmark_group = c.benchmark_group("create_client_from_cached");
let wallet = xmtp_cryptography::utils::generate_local_wallet();
let nonce = 1;
let inbox_id = generate_inbox_id(wallet.get_address(), nonce).unwrap();
let address = wallet.get_address();
let path = tmp_path();

// benchmark_group.sample_size(10);
benchmark_group.sampling_mode(criterion::SamplingMode::Flat);
benchmark_group.bench_function("cached_create_ffi_client", |b| {
let span = trace_span!(BENCH_ROOT_SPAN);
b.to_async(&runtime).iter_batched(
|| {
let (network, is_secure) = network_url();
(
inbox_id.clone(),
address.clone(),
nonce,
path.clone(),
HISTORY_SYNC_URL.to_string(),
network,
is_secure,
span.clone(),
)
},
|(inbox_id, address, nonce, path, history_sync, network, is_secure, span)| async move {
xmtpv3::mls::create_client(
network,
is_secure,
Some(path),
Some(vec![0u8; 32]),
&inbox_id,
address,
nonce,
None,
Some(history_sync),
)
.instrument(span)
.await
.unwrap();
},
BatchSize::SmallInput,
)
});

benchmark_group.finish();
}

criterion_group!(
name = create_client;
config = Criterion::default().sample_size(10);
targets = create_ffi_client, cached_create_ffi_client
);
criterion_main!(create_client);
2 changes: 1 addition & 1 deletion bindings_ffi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ static LOGGER_INIT: Once = Once::new();
pub fn init_logger() {
LOGGER_INIT.call_once(|| {
let native_layer = native_layer();
tracing_subscriber::registry().with(native_layer).init()
let _ = tracing_subscriber::registry().with(native_layer).try_init();
});
}
Loading

0 comments on commit cf6f0fb

Please sign in to comment.