Skip to content
Merged

Perf #15

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
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ serde_json = "1.0.140"
tokio-tungstenite = { version = "0.29.0", features = ["native-tls"] }
http = "1.3.1"
futures-util = "0.3.31"
sstr = {version = "0.3.0", features = ["sqlx-postgres", "serde"]}

[dev-dependencies]
alloy = {version = "2.0", features = ["node-bindings", "network", "rpc-types", "signer-local"]}
Expand Down
17 changes: 9 additions & 8 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::sync::LazyLock;

use axum::body::Body;
use criterion::{AxisScale, BatchSize, PlotConfiguration};
use criterion::{Criterion, criterion_group, criterion_main};
use http::{HeaderValue, header::CONTENT_TYPE};
use reqwest::Client;
use serde_json::json;
pub mod types;

async fn relay_benchmark(body: Vec<u8>, provider: String, client: Client) {
let byte_stream = client
pub static PROXY_CLIENT: LazyLock<Client> = LazyLock::new(Client::new);

async fn relay_benchmark(body: Vec<u8>, provider: String) {
let byte_stream = PROXY_CLIENT
.post(&provider)
.header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
.body(body)
Expand All @@ -17,11 +20,10 @@ async fn relay_benchmark(body: Vec<u8>, provider: String, client: Client) {
.error_for_status()
.expect("")
.bytes_stream();

let _ = Body::from_stream(byte_stream);
}

fn generate_body() -> (Vec<u8>, String, Client) {
fn generate_body() -> (Vec<u8>, String) {
let body = json!({
"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id": 1
})
Expand All @@ -31,9 +33,8 @@ fn generate_body() -> (Vec<u8>, String, Client) {

let key = dotenvy::var("D_D_CLOUD_API_KEY").expect("D_D_CLOUD_API_KEY");
let provider = format!("https://api.cloud.developerdao.com/rpc/base/{}", &key);
let client = Client::new();

(body, provider, client)
(body, provider)
}

fn test_relay_pocket(c: &mut Criterion) {
Expand All @@ -46,7 +47,7 @@ fn test_relay_pocket(c: &mut Criterion) {
group.bench_function("RPC Benchmark", move |b| {
b.to_async(&runtime).iter_batched(
generate_body,
async move |data| relay_benchmark(data.0, data.1, data.2).await,
async move |data| relay_benchmark(data.0, data.1).await,
BatchSize::SmallInput,
)
});
Expand Down
Loading
Loading