-
Hi, I'm writing a service to convert data pushed by clients in bidirectional streaming mode. My code is like: #[async_trait::async_trait]
impl XXXFacade for XXXServer {
type ResponseStream = Pin<Box<dyn Stream<Item = Result<Response, Status>> + Send>>;
async fn handle_request(
&self,
request: tonic::Request<tonic::Streaming<Response>>,
) -> Result<tonic::Response<Self::ResponseStream>, tonic::Status> {
tokio::spawn(async move {
let stream = request.into_inner();
while let Some(req) = stream.next().await {
// process request obj.
}
Ok::<_, anyhow::Error>(())
});
Ok(Response::new(
Box::pin(client_rx) as Self::routeRequestStream
))
}
}
tokio::spawn(async move {
Server::builder()
.timeout(Duration::from_secs(30))
.add_service(XXXServer::new(self))
.serve_with_incoming_shutdown(
TcpListenerStream::new(listener),
shutdown_rx.map(drop),
)
.await
.unwrap();
}); My problem is: I'm not able to get full CPU usage. I set up a few client pods and generate a total of 100~200 connections to push as much synthetic mock data as possible. When I run the service on a pod of 4-core, the maximum CPU usage is around 300%~350%. I'm not able to take it further. When I check I'm expecting 800% CPU usage on a 8-core pod for my test. I don't know how to. Are there any settings I can try? I'm using the latest version of everything:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
I would run a flamegraph and potentially an off-cpu flamegraph to see what is stopping the cpu from being saturated. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I might know what's going on. When I add test loads, at some point of time, the client will get a Some clients stop pushing data, that's why the throughput cannot go higher. The error I get is: Client (java)
Server (I guess it is because the client reconnected)
I'm still try to figure out where the |
Beta Was this translation helpful? Give feedback.
-
Then I change my client to manual flow control (by referencing this: https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/manualflowcontrol/ManualFlowControlClient.java) The I suspect there's a server IO congestion. Does tonic (or hyper) has any settings to tune incoming IO performance? |
Beta Was this translation helpful? Give feedback.
-
My bad. Thanks for looking into my question! |
Beta Was this translation helpful? Give feedback.
Unfortunately, the off-cpu perf I get isn't very useful.
I keep the clients settings the same, and change the server code.
// process request obj.
(from code sample above, to poll requests and simply drops them), the throughput can go as high as 900 MB/s.I think it shows the server has reached some limits so the clients been back pressured. But in either case, the cpu usage is a little higher than 300%. Don't know why I'm not able to us…