Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Golang と Erlang
Search
鹿
October 20, 2024
Programming
2.3k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Golang と Erlang
2024-10-20 (日) に Kyoto.go remote #54 リモートLT会 で発表したスライドです。
鹿
October 20, 2024
Transcript
9 slides
Golang(*)と Erlang 鹿 @mizushika1 (*)正式名称は「Go」ですが、並べたときの響きの良さのために、 このスライドでは Golang と表記しています
名前は似てるけど、全然似てない Golang Erlang プログラミングモデル 手続き型 関数型 代入 何回でも 単一代入 コンパイル結果
バイナリ 中間言語 コンパイル結果 1ファイル moduleごとに別ファイル panic プロセス全体が死ぬ 軽量プロセスだけが死ぬ
スレッドを起動して Hello World の例 -module(hello). -export([start/0, printer/0]). start() -> Pid
= spawn(fun printer/0), Pid ! "Hello World~n". printer() -> receive msg -> io:fwrite(msg) end. package main import "fmt" func main() { ch := make(chan string) go printer(ch) ch <- "Hello World" <-ch } func printer(ch chan string) { msg := <-ch fmt.Println(msg) close(ch) }
runtime では似ている部分もある • スレッドモデルはどちらも M:N • Golang で言う goroutine •
Erlang で言う軽量プロセス • GC • ある • Golang は Mark and Sweep 方式 • Erlang は 世代別 GC も採用 • スレッド間の共有方法 • 変数をキュー(チャンネル)にコピーして通信 • Share memory by communication
runtime で似ているけど違う部分を紹介 • スレッドモデル • GC • スレッド間の共有方法
スレッドモデル • M:N = OSスレッド:ランタイムのスレッド • スケジューラスレッドがOSスレッドとして存在 • ランタイムのスレッドを順番に実行していく •
スケジューラが空いたら他のスケジューラから奪ったりもする • Go で言う G, P, M の話 • 優先度設定は限定的 • Linuxカーネルだと、SCHED_** とか nice 値とかが指定できるが、 • Golang は優先度設定一切無し • Erlang は実質2レベルあり、ランキューが2本だけある • Golang は goroutine に名前を付けられない • 名前が無いので、外から状態を把握したり止めたりできない • Erlang は VM で動くのでリモートから接続してトレースができる
GC • Garbage Collector • プログラマがヒープメモリの開放を気にしなくて良い仕組み • 通常の人類には必須の機能 • Golang
はプロセス全体で GC をかける • Mark and Sweep という昔ながらの方式 • Mark のときに STW (Stop-the-World) が発生して、全goroutineが止まる • Erlangは軽量プロセス(runtimeスレッド)ごとにGCをかける • 他の軽量プロセスは影響を受けない • グローバル変数やポインタが無いからできる技 • 実行タイミングは「関数呼び出しの回数」
スレッド間の共有方法 • チャンネル or メッセージキューを推奨している • データがコピーして格納されるので shared nothing にできる
• Golang • チャンネルは自分で作る • 段数があり、それを超える write はブロックされる • close 済みのチャンネルに write すると panic になる • Erlang • 軽量プロセスを作ると自動でそれ用のメッセージキューも作られる • 段数は無限で、メモリの許す限り write できる • 存在しない相手に write してもエラーにならない • 1プロセス1キューなので、fan-out 構造は工夫が必要
まとめ • Golang と Erlang の、 似てないようで似てるようでやっぱり違う点の紹介をした • どちらも M:N
スレッドモデルを採用しており、 設計思想が共有できる点が多い(かも) • M:N スレッドモデルは今後広まっていきそう • Ruby の Ractor とか • Java の VirtualThread とか • 個人的感想 • Golang の GC も大量の goroutine 利用に適したものになってほしい • 世代別 GC を熱望している
More Decks by 鹿
See All by 鹿
`go get`したらELFが降ってきた件
taiyow
0
200
なぜselectはselectではないのか
taiyow
1
490
Go の GC の不得意な部分を克服したい
taiyow
4
2.1k
Other Decks in Programming
See All in Programming
はじめてのPLATEAU
nokonoko1203
1
650
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
Railsバージョンを4倍にした話
optim
0
1k
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
250
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
640
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
120
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
340
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.1k
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
300
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
Featured
See All Featured
Scaling GitHub
holman
464
140k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
480
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
310
Game over? The fight for quality and originality in the time of robots
wayneb77
1
330
How to make the Groovebox
asonas
2
2.6k
Amusing Abliteration
ianozsvald
1
390
Statistics for Hackers
jakevdp
799
230k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
640
Between Models and Reality
mayunak
4
580
Designing for Performance
lara
612
70k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k