View Source Speeding up with ETS Every time we need to look up a bucket, we need to send a message to the registry. In case our registry is being accessed concurrently by multiple processes, the registry may become a bottleneck! In this chapter, we will learn about ETS (Erlang Term Storage) and how to use it as a cache mechanism. Warning! Don't use ETS as a cache prematurely! Log and analyze your
はじめに 本記事はElixir Advent Calendar 2017の21日目です。 mnesiaはErlang/OTPについてくる高速、高可用性が売りのRDBMSです。 今回はこれをElixirで少し便利に使ってみようという話です。Elixir特有というよりmnesia特有の話かつhow to的なものになっています。内容は - テーブルの作成 - 分散モードへの移行とレプリケーションの構成 - 障害復旧方法 - シャーディング その他曰く云い難い何かになります。 分散モード elixir/erlangランタイムOSプロセス(群)はノードと呼ばれ、スタンドアローンと分散の二つのモードがあり、分散モードのノードはさらに、ホスト内で有効なショートネームとホストを超えて有効なロングネームのモードがあります。 モードの切り替えは、
キャッシュ機構であるErlang Term Storageについて学ぶ。 ETS as a cache ETSは etsモジュールを経由してメモリ上のETSテーブルにデータを保存できる仕組み iex(1)> table = :ets.new(:buckets_registry, [:set, :protected]) 8211 iex(2)> :ets.insert(table, {"foo", self}) true iex(3)> :ets.lookup(table, "foo") [{"foo", #PID<0.59.0>}] ETS tableを作成する際は、テーブル名とオプションの2つの引数を与える。上記の例では:buckets_registryというテーブルにテーブルの型とアクセスルールを与えている。:setはキーの重複を許さないという意味、:protected はテーブルを作
Erlang Term Storage、略してETSは、OTP内部に組み込まれている強力なストレージエンジンで、Elixirから利用することができます。このレッスンではETSを呼び出す方法と、アプリケーションで使用する方法を見ていきます。 概要 ETSは堅牢なインメモリストアで、ElixirやErlangのオブジェクトを保管するためのものです。ETSはとても大きなデータを格納し、定数時間でのデータアクセスを提供します。 ETSのテーブルは個々のプロセスによって生成、所有されています。テーブルを所有しているプロセスが死ぬと、テーブルは破壊されます。初期状態では、ETSはノードにつき1400テーブルに制限されています。 テーブルの作成 テーブルは new/2 で作成します。この関数はテーブル名と、一連のオプションを受け取り、以降の操作で用いることのできるテーブルのIDを返します。 例としてユー
この記事はElikir Advent Calendar 2015の7日目の記事です。 ETSとは Erlang Term Storage の略で、etsモジュールを経由してin memoryなテーブルにtupleを保存できる仕組みです。 子プロセス間でデータを共有できますが、ネットワーク越しの共有はできません。 ドキュメントはこちら。 http://www.erlang.org/doc/man/ets.html REPLから使ってみる iexでREPLを起動しデータを登録したり取り出してみたりします。 新しいテーブルを作成 iex(1)> table = :ets.new(:temp_table, [:set, :protected]) 8211 :ets.new/2で新しいテーブルを作成してETSのPIDが返ります。1個目の引数はテーブル名のatom、2個目はテーブルの定義をatomのl
15. 並列アプリケーションを設計する¶ すべていい感じです。概念は理解されたと思います。 が、再度いいますが、この本の最初からやってきたことは全部おもちゃです: 計算機、ツリー、ヒースローからロンドン、などなど。 そろそろ何か楽しくてもっと役に経つことをすることです。 並列Erlangで小さいアプリケーションを書きましょう。 アプリケーションは小さく行を基にしているけれど、それでいて役立つしそれなりに拡張できるものになります。 私はいくらか考えが体系立っていない人間です。 宿題を忘れたり、アパートの周りですることを忘れたり、この本や、仕事、ミーティング、約束などなど良く忘れます。 結局タスクであふれた何十ものリストを書く羽目になって、それでもなおやり忘れたり、見直しを忘れたりします。 希望的にはあなたにもすべきことのリマインダーが必要であってほしいです。(しかしあなたの場合は私ほど欲しい
安っぽいタイトルを付けてしまい大変申し訳ありません。 Hot code loading とは、データはそのままでコードだけ最新のやつに差し替える Erlang VM の機能です。 うまくやると無停止で運用できるので嬉しかったりしますが、ちゃんとわかって使わないと謎の挙動に苦しむことになるのでちょっと調べてみました。 概要 まずは 公式ドキュメント を見て、一部動作を予想しつつまとめてみました。最低限、これだけ覚えておけば勝つる。 ■関数の実体 ある関数の実体が所属する世界は current, old の2種類ある. ■関数の実体の解決方法 「Fully qualified function calls」や「Fully qualified functionが入った変数」は常に current のやつを指す. そうでないものは現在実行中の関数が所属する世界のやつを指す. ■コード更新時の処理
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く