> For the complete documentation index, see [llms.txt](https://openai.gitbook.io/code-cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openai.gitbook.io/code-cheatsheets/all/elixir/otp.md).

# OTP

## OTP

(Open Telecom Platform) is a collection of framework/lib/tools written in Erlang

Horrible error messaging

### Observer

```
iex(1)> observer.start()
```

## [Erlang Term Storage (ETS)](https://elixirschool.com/en/lessons/specifics/ets/)

* [Docs](http://erlang.org/doc/man/ets.html)

In-memory store key value for elixir and erlang

\>10x Faster than redis according [to](https://github.com/minhajuddin/redis_vs_ets_showdown)

* Created and owned by individual processes(destroyed on exit), so back with GenServer and now any process can access, no bottleneck
* Only limit is server memory.
* Because multiple can access at the same time unlike message based agents, operations must be atomic (ft for something like counter updating)
  * Concurrent reads with serial writes is a common ETS pattern

#### Applications of ETS

* persisent shared state(tzdata, )
* ephemeral shared state(cache, rate limiter)
* IPC

#### Usage

```elixir
tab = :ets.new(:my_table, [:set]) #=> 8211

:ets.insert(tab, {:key1, "value1"}) #=> true

:ets.lookup(tab, :key1) #=> [key1: "value1"]
```

**Advanced**

```elixir
:ets.tab2list(:rate_limiter_requests) #[[key1: "value1"]]
```

<http://erlang.org/doc/man/disk_log.html>

#### [Disk Based ETS(DETS)](https://erlang.org/doc/man//dets.html)

APIS are interchangeable except

* how tables are created with named table default
* `:dets` vs `:ets` and fewer features
* Slower cuz disk

```elixir
{:ok, table} = :dets.open_file(:disk_storage, [type: :set]) #{:ok, :disk_storage}
:dets.open_file(:file_table, [{:file, "test/test.txt"}])
```

**Usage**

```elixir
:dets.insert(table, {:k, 1}) #can also use :name to access table as that is what table is
:dets.lookup(:file_table, :a) # => [a: 3]
:dets.close(:file_table) #If you don't do this, the table will be repaired the next time it is opened.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/all/elixir/otp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
