yyu-nim / yyu-nim.github.io

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

https://yyu-nim.github.io/rust/crossbeam/concurrent/queue/2022/08/21/crossbeam-queue.html #10

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

crossbeam <7> - non-blocking concurrent queues | Production-ready Rust Libraries (PRL)

코드 리뷰 중에, 누군가가 만약 queue에 아이템을 넣고 빼는 연산의 전후에 lock을 잡고 획득하고 풀어주는 패턴으로 작성한 것을 보았다면, 보통은 아래와 같은 코멘트를 달게 될 것이다: 본 PR에서 사용된 queue가 thread-safe 하지 않기 때문에, lock을 사용하신 것으로 이해하면 될까요? Lock이 coarse-gr

https://yyu-nim.github.io/rust/crossbeam/concurrent/queue/2022/08/21/crossbeam-queue.html

huijeong-kim commented 2 years ago

우와 만연체 재미있습니다 ㅎㅎㅋㅋ blocking queue 보다 non-blocking queue가 더 좋을 때는 언제일까요,,?

yyu-nim commented 2 years ago

개인적인 생각은, 두 queue를 1개씩 두고 직접 비교를 하면 큰 차이점이 없을 수도 있겠는데 (blocking queue 구현은 "non-blocking queue + conditional wait" 으로 되는 경우도 많을 것 같아서), queue가 여러개 있는 경우 (e.g., event queue, io queue, ...), non blocking queue 를 써서 single thread로도 효과적인/쉬운 multiplexing이 가능해지는 것을 꼽을 수 있지 않을지 생각합니다 ㅎ 특히 병렬성이 높아질수록 (혹은 시스템의 로드가 클수록) non blocking queue로 context switch overhead 등을 최소화하여 부수적으로 성능 이득을 얻을 수 있지 않을까 예상합니다 ㅎ

huijeong-kim commented 2 years ago

아하 의견 주셔서 감사합니다!! single therad로도 효과적인/쉬운 multiplexing은 큰 장점일 것 같습니다 ㅎㅎ multithread에서는 큰 차이가 없을 수도 있겠군요 ㅎㅎ