Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Performance Comparison of
Mutex, RWLock and
Atomic types in Rust
Mitsunori Komatsu
About me
Mitsunori Komatsu, 

Software engineer
Started learning Rust recently (7 months ago)
Contributed a small feature ...
It’s hard to update
a variable serializably
in multi-threads…
Mutable Types in Arc
(Arc uses atomic reference count)
Mutex Mutual Exclusion Lock
Can contain
Send
RWLock
Read: Shared Lo...
Benchmark program
(Mutex #1)
https://github.com/komamitsu/rust-lock-bench
Benchmark program
(Mutex #2)
https://github.com/komamitsu/rust-lock-bench
Benchmark program
(RWLock #1)
https://github.com/komamitsu/rust-lock-bench
Benchmark program
(RWLock #2)
https://github.com/komamitsu/rust-lock-bench
Benchmark program
(Atomic types #1)
https://github.com/komamitsu/rust-lock-bench
Benchmark program
(Atomic types #2)
https://github.com/komamitsu/rust-lock-bench
Let’s Benchmark!
Rust 1.15.1
Linux 4.4 (c3.2xlarge)
macOS 10.11
Benchmark result
(OS: Linux, Build: Debug, Loop: 50000,
Total Threads: 20, # of trial: 20)
Benchmark result
(OS: Linux, Build: Release, Loop: 50000,
Total Threads: 20, # of trial: 20)
Benchmark result
(OS: macOS, Build: Debug, Loop: 10000,
Total Threads: 20, # of trial: 20)
Benchmark result
Benchmark result
(OS: macOS, Build: Release, Loop: 10000,
Total Threads: 20, # of trial: 20)
Summary
The performance of RWLock expectedly
degrades when the number of writes
increases
The performance of Mutex doesn't...
Upcoming SlideShare
Loading in …5
×

Performance Comparison of Mutex, RWLock and Atomic types in Rust

3,887 views

Published on

Performance Comparison of Mutex, RWLock and
Atomic types in Rust

Published in: Software
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Performance Comparison of Mutex, RWLock and Atomic types in Rust

  1. 1. Performance Comparison of Mutex, RWLock and Atomic types in Rust Mitsunori Komatsu
  2. 2. About me Mitsunori Komatsu, 
 Software engineer Started learning Rust recently (7 months ago) Contributed a small feature to Rust (https:// github.com/rust-lang/rust/pull/33976) https://github.com/komamitsu/td-client-rust https://github.com/komamitsu/treasuredata_fdw
  3. 3. It’s hard to update a variable serializably in multi-threads…
  4. 4. Mutable Types in Arc (Arc uses atomic reference count) Mutex Mutual Exclusion Lock Can contain Send RWLock Read: Shared Lock Write: Exclusive Lock Can contain Send + Sync Atomic types Atomic counter - We can update these types in multi-threads
  5. 5. Benchmark program (Mutex #1) https://github.com/komamitsu/rust-lock-bench
  6. 6. Benchmark program (Mutex #2) https://github.com/komamitsu/rust-lock-bench
  7. 7. Benchmark program (RWLock #1) https://github.com/komamitsu/rust-lock-bench
  8. 8. Benchmark program (RWLock #2) https://github.com/komamitsu/rust-lock-bench
  9. 9. Benchmark program (Atomic types #1) https://github.com/komamitsu/rust-lock-bench
  10. 10. Benchmark program (Atomic types #2) https://github.com/komamitsu/rust-lock-bench
  11. 11. Let’s Benchmark! Rust 1.15.1 Linux 4.4 (c3.2xlarge) macOS 10.11
  12. 12. Benchmark result (OS: Linux, Build: Debug, Loop: 50000, Total Threads: 20, # of trial: 20)
  13. 13. Benchmark result (OS: Linux, Build: Release, Loop: 50000, Total Threads: 20, # of trial: 20)
  14. 14. Benchmark result (OS: macOS, Build: Debug, Loop: 10000, Total Threads: 20, # of trial: 20)
  15. 15. Benchmark result Benchmark result (OS: macOS, Build: Release, Loop: 10000, Total Threads: 20, # of trial: 20)
  16. 16. Summary The performance of RWLock expectedly degrades when the number of writes increases The performance of Mutex doesn't significantly change even under write heavy operations. Also, it’s really optimized on Linux AtomicUsize is always really fast. Use it if you want just a counter

×