Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(grpc): remove build script for grpc convert benchmark #1721

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
67 changes: 1 addition & 66 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ dotenvy = "0.15"
convert_case = "0.6.0"
rand = "0.8.5"

[build-dependencies]
tonic-build = "0.11.0"
protoc-bin-vendored = "3.0.0"


[dev-dependencies]
criterion = "0.5.1"
Expand Down
61 changes: 37 additions & 24 deletions benches/protobuf_convert_output.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
use std::path::Path;

use anyhow::Result;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use prost::Message;
use rand::random;
use rand::{thread_rng, Fill};
use serde_json::{json, Value};
use tailcall::blueprint::GrpcMethod;
use tailcall::grpc::protobuf::ProtobufSet;

pub mod dummy {
tonic::include_proto!("dummy");
}

const OUT_DIR: &str = "benches/grpc";
const PROTO_DIR: &str = "benches/grpc";
const PROTO_FILE: &str = "dummy.proto";
const SERVICE_NAME: &str = "dummy.DummyService.GetDummy";
const N: usize = 1000;
const M: usize = 100;

pub struct Dummy;

impl Dummy {
#[allow(clippy::new_ret_no_self)]
fn new(n: usize, m: usize) -> dummy::Dummy {
dummy::Dummy {
ints: (0..n).map(|_| random()).collect(),
flags: (0..n).map(|_| random()).collect(),
names: (0..n)
.map(|_| (0..m).map(|_| random::<char>()).collect())
.collect(),
floats: (0..n).map(|_| random()).collect(),
}
}
fn create_dummy_value(n: usize, m: usize) -> Result<Value> {
let rng = &mut thread_rng();
let mut ints = vec![0i32; n];
let mut floats = vec![0f32; n];
let mut flags = vec![false; n];
let names: Vec<String> = (0..n)
.map(|_| {
let mut chars = vec![' '; m];

chars.try_fill(rng)?;

Ok(chars.into_iter().collect::<String>())
})
.collect::<Result<_>>()?;

ints.try_fill(rng)?;
floats.try_fill(rng)?;
flags.try_fill(rng)?;

let value = json!({
"ints": ints,
"floats": floats,
"flags": flags,
"names": names,
});

Ok(value)
}

fn benchmark_convert_output(c: &mut Criterion) {
let proto_file_path = Path::new(OUT_DIR).join(PROTO_FILE);
let proto_file_path = Path::new(PROTO_DIR).join(PROTO_FILE);
let file_descriptor_set = protox::compile([proto_file_path], ["."]).unwrap();
let protobuf_set = ProtobufSet::from_proto_file(&file_descriptor_set).unwrap();
let method = GrpcMethod::try_from(SERVICE_NAME).unwrap();
let service = protobuf_set.find_service(&method).unwrap();
let protobuf_operation = service.find_operation(&method).unwrap();
let mut msg: Vec<u8> = vec![0, 0, 0, 0, 14];
Dummy::new(N, M).encode(&mut msg).unwrap();

let dummy_value = create_dummy_value(N, M).unwrap();
let msg = protobuf_operation
.convert_input(&dummy_value.to_string())
.unwrap();
meskill marked this conversation as resolved.
Show resolved Hide resolved

c.bench_function("test_batched_body", |b| {
b.iter(|| {
Expand Down
12 changes: 0 additions & 12 deletions build.rs

This file was deleted.

Loading