yyu-nim / yyu-nim.github.io

Production-ready Rust Libraries (PRL)
5 stars 0 forks source link

https://yyu-nim.github.io/crossbeam/rust/2022/07/21/crossbeam-workstealing-2.html #5

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Crossbeam work-stealing queue <2> | Your awesome title

100만개의 일을 만들어서, 10개의 worker들에게 나눠주기. 방식은 work-stealing으로 worker들이 일을 빼앗아 감. ```rust use std::thread; use std::time::Duration; use crossbeam::deque::{Steal, Worker};

https://yyu-nim.github.io/crossbeam/rust/2022/07/21/crossbeam-workstealing-2.html

huijeong-kim commented 2 years ago

tokio blog를 보다가 이 블로그글이 생각나 돌아왔습니다 ㅎㅎ

제 컴퓨터에서 돌려보면 항상 worker 0 이 모든 일을 다 하고 있었는데요, worker::Steal() 을 동시에 여러 thread가 시도하면서 실패하는 경우가 있는 것 같아요. Steal::Retry 시에는 continue, Steal::Empty 시에만 break하도록 수정하니 task가 여러 thread에 골고루 분배되었습니다!

yyu-nim commented 2 years ago

그게 문제였나 보네요! 테스트 해보고 반영하도록 하겠습니다 ㅎ 감사합니다!

yyu-nim commented 2 years ago

아주 잘 되네요!! worker 간에 work들이 균등하게 잘 배분되는 것 같습니다.