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
More Decks by 鹿
See All by 鹿
なぜselectはselectではないのか
taiyow
1
480
Go の GC の不得意な部分を克服したい
taiyow
4
2.1k
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
160
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
110
Railsバージョンを4倍にした話
optim
0
470
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.5k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
R8 の設定見直しでアプリサイズ削減
andpad
0
220
phperだってパンチカードでコーディングしたい
o0h
PRO
0
360
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
ActionController meets Protocol Buffers
sorah
0
580
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
1
310
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4k
Featured
See All Featured
How to Talk to Developers About Accessibility
jct
2
580
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
The browser strikes back
jonoalderson
0
1.8k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
370
The Language of Interfaces
destraynor
162
27k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
GraphQLとの向き合い方2022年版
quramy
50
15k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
Transcript
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 を熱望している