jonhoo / jonhoo/bus

recv() cpu abuse

Open
#23 4 comments 6 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
846
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Hello. I'm new with Rust. 20 recv() uses 40% cpu on my linux box. Is this a known issue?

```rust
extern crate bus;
use bus::Bus;
use std::sync::{Arc, Mutex};
use std::thread;
use std::io;

fn main() {
let bus: std::sync::Arc>>
= Arc::new(Mutex::new(Bus::new(10)));

for _ in 0..20 {
let mut rxb = bus.clone().lock().unwrap().add_rx();
thread::spawn(move || loop {
let msg = rxb.recv().unwrap();
});
}

io::stdin().read_line(&mut String::new()).unwrap();
}
```

total
```
11909 root 20 0 1029148 1980 1700 S 39.2 0.1 1:01.07 bus_possible_bu
```
per thread
```
11926 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
11927 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
11931 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
```
cpu
```
model name : Intel(R) Core(TM) i3 CPU 540 @ 3.07GHz
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Rust example on Linux and observing the per-thread CPU use around recv(). Then inspect the bus receiver implementation reached by recv() to determine why idle receivers consume CPU. Done means establishing whether this is expected behavior and documenting or addressing the cause with a reproducible result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.