SlideShare a Scribd company logo
12
Most read
14
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

What's hot (20)

Kubernetesでの性能解析 ~なんとなく遅いからの脱却~(Kubernetes Meetup Tokyo #33 発表資料)
Kubernetesでの性能解析 ~なんとなく遅いからの脱却~(Kubernetes Meetup Tokyo #33 発表資料)
NTT DATA Technology & Innovation
 
ロードバランスへの長い道
ロードバランスへの長い道
Jun Kato
 
わかった気になるMySQL
わかった気になるMySQL
yoku0825
 
入門 Kubeflow ~Kubernetesで機械学習をはじめるために~ (NTT Tech Conference #4 講演資料)
入門 Kubeflow ~Kubernetesで機械学習をはじめるために~ (NTT Tech Conference #4 講演資料)
NTT DATA Technology & Innovation
 
BuildKitの概要と最近の機能
BuildKitの概要と最近の機能
Kohei Tokunaga
 
そろそろ知っておきたい!!コンテナ技術と Dockerのキホン
そろそろ知っておきたい!!コンテナ技術と Dockerのキホン
Naoki Nagazumi
 
ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414
Kentaro Ebisawa
 
CyberAgentのプライベートクラウド Cycloudの運用及びモニタリングについて #CODT2020 / Administration and M...
CyberAgentのプライベートクラウド Cycloudの運用及びモニタリングについて #CODT2020 / Administration and M...
whywaita
 
Xbyakの紹介とその周辺
Xbyakの紹介とその周辺
MITSUNARI Shigeo
 
BuildKitによる高速でセキュアなイメージビルド
BuildKitによる高速でセキュアなイメージビルド
Akihiro Suda
 
Docker Compose 徹底解説
Docker Compose 徹底解説
Masahito Zembutsu
 
Redisの特徴と活用方法について
Redisの特徴と活用方法について
Yuji Otani
 
いまさら聞けない!CUDA高速化入門
いまさら聞けない!CUDA高速化入門
Fixstars Corporation
 
組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門
Norishige Fukushima
 
MagicOnion~C#でゲームサーバを開発しよう~
MagicOnion~C#でゲームサーバを開発しよう~
torisoup
 
20分でわかるgVisor入門
20分でわかるgVisor入門
Shuji Yamada
 
【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All Things
UnityTechnologiesJapan002
 
NEDIA_SNIA_CXL_講演資料.pdf
NEDIA_SNIA_CXL_講演資料.pdf
Yasunori Goto
 
Introduction to OpenCL (Japanese, OpenCLの基礎)
Introduction to OpenCL (Japanese, OpenCLの基礎)
Takahiro Harada
 
Kubernetesでの性能解析 ~なんとなく遅いからの脱却~(Kubernetes Meetup Tokyo #33 発表資料)
Kubernetesでの性能解析 ~なんとなく遅いからの脱却~(Kubernetes Meetup Tokyo #33 発表資料)
NTT DATA Technology & Innovation
 
ロードバランスへの長い道
ロードバランスへの長い道
Jun Kato
 
わかった気になるMySQL
わかった気になるMySQL
yoku0825
 
入門 Kubeflow ~Kubernetesで機械学習をはじめるために~ (NTT Tech Conference #4 講演資料)
入門 Kubeflow ~Kubernetesで機械学習をはじめるために~ (NTT Tech Conference #4 講演資料)
NTT DATA Technology & Innovation
 
BuildKitの概要と最近の機能
BuildKitの概要と最近の機能
Kohei Tokunaga
 
そろそろ知っておきたい!!コンテナ技術と Dockerのキホン
そろそろ知っておきたい!!コンテナ技術と Dockerのキホン
Naoki Nagazumi
 
ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414
Kentaro Ebisawa
 
CyberAgentのプライベートクラウド Cycloudの運用及びモニタリングについて #CODT2020 / Administration and M...
CyberAgentのプライベートクラウド Cycloudの運用及びモニタリングについて #CODT2020 / Administration and M...
whywaita
 
Xbyakの紹介とその周辺
Xbyakの紹介とその周辺
MITSUNARI Shigeo
 
BuildKitによる高速でセキュアなイメージビルド
BuildKitによる高速でセキュアなイメージビルド
Akihiro Suda
 
Redisの特徴と活用方法について
Redisの特徴と活用方法について
Yuji Otani
 
いまさら聞けない!CUDA高速化入門
いまさら聞けない!CUDA高速化入門
Fixstars Corporation
 
組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門
Norishige Fukushima
 
MagicOnion~C#でゲームサーバを開発しよう~
MagicOnion~C#でゲームサーバを開発しよう~
torisoup
 
20分でわかるgVisor入門
20分でわかるgVisor入門
Shuji Yamada
 
【Unite Tokyo 2019】Understanding C# Struct All Things
【Unite Tokyo 2019】Understanding C# Struct All Things
UnityTechnologiesJapan002
 
NEDIA_SNIA_CXL_講演資料.pdf
NEDIA_SNIA_CXL_講演資料.pdf
Yasunori Goto
 
Introduction to OpenCL (Japanese, OpenCLの基礎)
Introduction to OpenCL (Japanese, OpenCLの基礎)
Takahiro Harada
 

Recently uploaded (20)

Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 

Performance Comparison of Mutex, RWLock and Atomic types in Rust