SlideShare a Scribd company logo
12
Most read
13
Most read
16
Most read
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 to Rust (https://
github.com/rust-lang/rust/pull/33976)
https://github.com/komamitsu/td-client-rust
https://github.com/komamitsu/treasuredata_fdw
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 Lock
Write: Exclusive Lock
Can contain
Send + Sync
Atomic types Atomic counter -
We can update these types in multi-threads
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
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

More Related Content

PPTX
本当は恐ろしい分散システムの話
PPTX
コンテナネットワーキング(CNI)最前線
PDF
Azure上の データベース 機能の選び方。KVSからDWHまで
PPTX
root権限無しでKubernetesを動かす
PDF
コンテナイメージの脆弱性スキャンについて
PDF
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
PDF
Akkaとは。アクターモデル とは。
PPTX
Dockerからcontainerdへの移行
本当は恐ろしい分散システムの話
コンテナネットワーキング(CNI)最前線
Azure上の データベース 機能の選び方。KVSからDWHまで
root権限無しでKubernetesを動かす
コンテナイメージの脆弱性スキャンについて
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
Akkaとは。アクターモデル とは。
Dockerからcontainerdへの移行

What's hot (20)

PDF
「さくらのクラウド」におけるVyattaの活用事例
PDF
MapReduce/YARNの仕組みを知る
PDF
分散システムの限界について知ろう
PDF
BuildKitの概要と最近の機能
PDF
コンテナの作り方「Dockerは裏方で何をしているのか?」
PDF
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
ODP
シェルスクリプトを極める
PDF
Dockerセキュリティ: 今すぐ役に立つテクニックから,次世代技術まで
PDF
Docker Compose 徹底解説
PPTX
Ceph アーキテクチャ概説
PPTX
NGINXをBFF (Backend for Frontend)として利用した話
PDF
ElasticSearch+Kibanaでログデータの検索と視覚化を実現するテクニックと運用ノウハウ
PDF
トランザクション処理可能な分散DB 「YugabyteDB」入門(Open Source Conference 2022 Online/Fukuoka 発...
PDF
ストリーム処理を支えるキューイングシステムの選び方
PDF
なかったらINSERTしたいし、あるならロック取りたいやん?
PDF
PG-REXで学ぶPacemaker運用の実例
PDF
アーキテクチャから理解するPostgreSQLのレプリケーション
PDF
ロードバランスへの長い道
PDF
MySQLバックアップの基本
「さくらのクラウド」におけるVyattaの活用事例
MapReduce/YARNの仕組みを知る
分散システムの限界について知ろう
BuildKitの概要と最近の機能
コンテナの作り方「Dockerは裏方で何をしているのか?」
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
シェルスクリプトを極める
Dockerセキュリティ: 今すぐ役に立つテクニックから,次世代技術まで
Docker Compose 徹底解説
Ceph アーキテクチャ概説
NGINXをBFF (Backend for Frontend)として利用した話
ElasticSearch+Kibanaでログデータの検索と視覚化を実現するテクニックと運用ノウハウ
トランザクション処理可能な分散DB 「YugabyteDB」入門(Open Source Conference 2022 Online/Fukuoka 発...
ストリーム処理を支えるキューイングシステムの選び方
なかったらINSERTしたいし、あるならロック取りたいやん?
PG-REXで学ぶPacemaker運用の実例
アーキテクチャから理解するPostgreSQLのレプリケーション
ロードバランスへの長い道
MySQLバックアップの基本

Recently uploaded (20)

PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Essential Infomation Tech presentation.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
top salesforce developer skills in 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Essential Infomation Tech presentation.pptx
L1 - Introduction to python Backend.pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PTS Company Brochure 2025 (1).pdf.......
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administraation Chapter 3
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Performance Comparison of Mutex, RWLock and Atomic types in Rust