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
470
Go の GC の不得意な部分を克服したい
taiyow
4
2k
Other Decks in Programming
See All in Programming
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
250
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
100
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
150
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
410
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
カツオ、ご期待ください
suneo3476
0
120
The Rails Doctrine Decade
koic
2
420
iOSDCのペンライトを自動制御したい!
akkeylab
0
240
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
180
Agents on Rails - Rails at Scale 2026
irinanazarova
0
300
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.5k
Featured
See All Featured
Mind Mapping
helmedeiros
1
380
Site-Speed That Sticks
csswizardry
13
1.5k
Amusing Abliteration
ianozsvald
1
320
Bash Introduction
62gerente
615
220k
A designer walks into a library…
pauljervisheath
211
25k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
330
Between Models and Reality
mayunak
4
470
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
Paper Plane
katiecoart
PRO
4
53k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
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 を熱望している