핫 코드 교체와 실시간 업그레이드
Erlang이 시스템을 중단하지 않고 실행 중인 코드를 업그레이드하는 방식과 OTP 동작이 상태를 유지하는 실시간 업그레이드를 지원하는 방식을 배웁니다.
핫 코드 교체와 실시간 업그레이드은(는) CoddyKit의 무료 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Zero-Downtime Upgrades
One of Erlang's signature features is hot code swapping: replacing a module's code while the system keeps running, with no restart and no dropped connections.
Two Code Versions
The VM keeps up to two versions of each module: current and old. Loading a third version purges the oldest.
Local vs External Calls
A local call (foo()) stays in the running version. An external/qualified call (?MODULE:foo()) jumps to the newest loaded version. This distinction drives upgrades.
loop(State) ->
receive
Msg ->
NewState = handle(Msg, State),
?MODULE:loop(NewState) % picks up new code
end.Loading New Code
You compile and load the new version with the code module or via the shell.
c(my_module).
code:load_file(my_module).The code_change Callback
Stateful OTP behaviors like GenServer support a code_change/3 callback. OTP calls it during an upgrade so you can transform old state into the new format.
code_change(_OldVsn, State, _Extra) ->
{ok, migrate_state(State)}.Why State Migration Matters
If your new version stores state differently (say a tuple becomes a map), code_change bridges the gap so live processes do not crash on the new code.
migrate_state({old, A, B}) ->
#{a => A, b => B}.Release Upgrades
For whole-system upgrades, OTP uses appup and relup files that describe the steps to move from one release version to the next.
{"1.1.0",
[{"1.0.0", [{update, my_server, {advanced, []}}]}],
[{"1.0.0", [{update, my_server, {advanced, []}}]}]}.Suspending Processes
During an advanced upgrade, OTP suspends the affected processes, applies code_change, then resumes them, ensuring no message is handled with mismatched state.
Purging Old Code
After an upgrade, processes still running old code can be checked and the old version purged once safe.
code:soft_purge(my_module).
% returns false if any process still runs old codeWhen to Use It
Hot upgrades shine for telecom-grade always-on systems. For many apps, a rolling restart of nodes is simpler. Choose based on your uptime requirements.
Best Practices
Key rules:
- Always make the recursive loop call qualified (
?MODULE:loop) - Implement
code_changefor any stateful behavior - Test upgrades in staging before production
Quick Check
Test your hot-swap knowledge.
Recap
You learned Erlang's live upgrade model.
- The VM keeps two code versions
- Qualified calls adopt new code
code_change/3migrates state during OTP upgrades- appup/relup drive full release upgrades
AI 튜터와 함께 Erlang을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 48
자주 묻는 질문
“핫 코드 교체와 실시간 업그레이드” 강의는 무료인가요?
네 — “핫 코드 교체와 실시간 업그레이드” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“핫 코드 교체와 실시간 업그레이드”에서 뭘 배우나요?
Erlang이 시스템을 중단하지 않고 실행 중인 코드를 업그레이드하는 방식과 OTP 동작이 상태를 유지하는 실시간 업그레이드를 지원하는 방식을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Erlang OTP: Distributed & Fault-Tolerant Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“핫 코드 교체와 실시간 업그레이드” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 상태 관리를 위한 GenStatem
- 이벤트 처리를 위한 GenEvent
- 사용자 지정 OTP 동작
- 핫 코드 교체와 실시간 업그레이드