0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · レッスン

ノード間のロードバランシングとフェイルオーバー

Erlangノード間で処理を均等に分散し、分散クラスターで自動フェイルオーバーを行ってサービスの可用性を維持します。

「ノード間のロードバランシングとフェイルオーバー」はCoddyKit上の無料Erlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはErlang OTP: Distributed & Fault-Tolerant Systems Programming学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Load Balancing?

In a cluster, spreading work across nodes prevents any one node from becoming a bottleneck and lets you scale by adding machines. Failover keeps the system available when a node dies.

Listing Cluster Nodes

A node sees its connected peers with nodes/0. This list is the pool you balance work over.

nodes().
% => ['worker1@host', 'worker2@host']

Round-Robin Dispatch

A simple strategy cycles through nodes in order, giving each an equal share of tasks.

pick_node(Index) ->
    Nodes = [node() | nodes()],
    lists:nth((Index rem length(Nodes)) + 1, Nodes).

Spawning on a Remote Node

spawn/4 can start a process on a chosen node, sending the work where you want it.

spawn(TargetNode, my_worker, run, [Task]).

The pg Process Groups

The pg module maintains named groups of processes spread across nodes. You can fetch group members and dispatch to them.

pg:join(workers, self()).
Members = pg:get_members(workers).

Choosing a Local Member

For low latency, prefer a worker on the local node when one exists, falling back to remote members otherwise.

case pg:get_local_members(workers) of
  [] -> pick_remote();
  Local -> hd(Local)
end.

Detecting Node Failure

Call net_kernel:monitor_nodes(true) to receive {nodedown, Node} messages when a peer disconnects, the trigger for failover.

net_kernel:monitor_nodes(true).
% receive {nodedown, Node} -> handle_failure(Node) end.

Failover Strategy

On nodedown, redistribute that node's pending work to surviving nodes and remove it from your dispatch pool.

handle_failure(Node) ->
    Tasks = pending_tasks(Node),
    [reassign(T) || T <- Tasks].

Stateless vs Stateful

Stateless work is trivial to reassign. Stateful work needs its state replicated (e.g. via Mnesia) so a survivor can resume it. Design state placement up front.

Avoiding Thundering Herds

When a node returns, do not dump all reconnection or rebalancing work at once. Stagger it to avoid overwhelming the cluster.

Putting It Together

A resilient setup: register workers in a pg group, dispatch round-robin with local preference, monitor nodes, and reassign work on failure with state backed by replicated storage.

Quick Check

Test your failover knowledge.

Recap

You learned distributed load balancing and failover.

  • Dispatch work across nodes/0 with round-robin and local preference
  • Use pg groups to track workers
  • Monitor nodes and reassign work on nodedown
  • Replicate state for stateful failover

よくある質問

「ノード間のロードバランシングとフェイルオーバー」レッスンは無料ですか?

はい。「ノード間のロードバランシングとフェイルオーバー」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

「ノード間のロードバランシングとフェイルオーバー」で何を学びますか?

Erlangノード間で処理を均等に分散し、分散クラスターで自動フェイルオーバーを行ってサービスの可用性を維持します。 ブラウザで直接実行するハンズオンコードでErlang OTP: Distributed & Fault-Tolerant Systems Programmingを演習し、24時間対応の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フィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ネットワーク分断への対処
  2. ETSとMnesiaによる分散データ
  3. スケーラビリティとレジリエンスの設計
  4. ノード間のロードバランシングとフェイルオーバー
← Erlang OTP: Distributed & Fault-Tolerant Systems Programmingに戻る