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

why tarpc so slow? #501

Open
work-chausat opened this issue Jan 3, 2025 · 7 comments
Open

why tarpc so slow? #501

work-chausat opened this issue Jan 3, 2025 · 7 comments

Comments

@work-chausat
Copy link

work-chausat commented Jan 3, 2025

client:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    init_tracing("tarpc_tracing_example")?;

    let remotes = match conf::parse() {
        Some((_, res)) => res,
        None => vec![],
    };
    if remotes.len() > 1 {
        print!("not support");
        process::exit(exitcode::DATAERR)
    }

    let server_addr = remotes[0].0;
    let mut connect = tcp::connect(server_addr, Bincode::default);
    connect.config_mut().max_frame_length(usize::MAX);
    let transport = connect.await.unwrap();

    let mut cli_cfg = client::Config::default();
    cli_cfg.max_in_flight_requests = 10000;
    cli_cfg.pending_request_buffer = 8000;

    let rpc_cli = RaclClient::new(cli_cfg.clone(), transport).spawn();

    let args: Vec<String> = env::args().collect();
    loop {
        let ret = rpc_cli.npu_smi(context::current(), args.clone()).await.expect("failed to execute");
        print!("{}", ret);
    }
}

server:

    async fn start(self) -> anyhow::Result<()> {
        let server_addr = (IpAddr::V4(Ipv4Addr::UNSPECIFIED), self.port);

        let mut listener = tcp::listen(&server_addr, Bincode::default).await?;
        info!("Listening on port {}", listener.local_addr().port());
        listener.config_mut().max_frame_length(usize::MAX);

        let mut incoming = listener
            .filter_map(|r| future::ready(r.ok()))
            .map(|transport| server::BaseChannel::new(server::Config { pending_response_buffer: 2000 }, transport));
        pin_mut!(incoming);

        while let Some(channel) = incoming.next().await {
            tokio::spawn(channel.execute(self.clone().serve()).for_each(|rpc| async move {
                tokio::spawn(rpc);
            }));
        }

        self.running.store(false, Ordering::SeqCst);

        Ok(())
    }

    async fn npu_smi(self, _ctx: Context, param: Vec<String>) -> String {
        return "cmd executed".to_string();
    }

service:

#[tarpc::service]
pub trait Racl {
    async fn npu_smi(param: Vec<String>) -> String;
}

performance:

Image
@work-chausat
Copy link
Author

Image

@work-chausat
Copy link
Author

work-chausat commented Jan 3, 2025

cpu:Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz 64 core
memory : 251G
tarpc = { version = "0.35", features = ["full"] }

Image

@work-chausat
Copy link
Author

Image Image Image

@work-chausat
Copy link
Author

so bad performance!!

@tikue
Copy link
Collaborator

tikue commented Jan 3, 2025

Hi! Are you building with optimizations?

@work-chausat
Copy link
Author

work-chausat commented Jan 4, 2025

Hi! Are you building with optimizations?

yes.
RUSTFLAGS="-C target-cpu=native" cargo build --release

[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = "symbols"


[build]
rustflags = ["-C", "target-cpu=native"]

@work-chausat
Copy link
Author

all the code:
tarpc_test.zip

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants