How to push the server to 100% CPU? #5991
-
I wrote a simple echo service based on tokio. It spawns a task for each connect received. Then I wrote a client program that can specify N tasks to request the echo service simultaneously. Each task establishes a persistent connection and sequentially makes several requests. I wanted to use this client to maximize the CPU usage of the echo service, but I was never able to do so. I'm using an M1 MacBook. The echo service automatically started 8 threads. The client program runs at the same computer. Here is the cpu usage for different number of client tasks:
You can see than the CPU stops at 137% with 8 client-tasks. However I wish to push the server and the client to use 400% CPU both, to run out of the total 8 cores. Is it possible? How to make it? I set the threads of echo server, and test it:
You can see the echo server can not use 100% CPU even for 1 thread. I found a similar discussion: #5779, but there is no further progress. Here is the echo server's code:
and the client's code:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 52 replies
-
You may set the number of worker threads to a greater number, to make more worker threads are running instead of IO waiting. And if your machine are running other process (the desktop computer always have), the tokio process cant take all cpu time because of OS preemptive schedule mechanism. |
Beta Was this translation helpful? Give feedback.
I forgot you were only running 8 connections.
You'll never be able to get enough throughput from 8 connections without resorting to the dark arts of network programming to actually use much CPU