Advanced

## 7 Advanced

### 7.1 Memory

A good start when programming efficient is to have knowledge about how much memory different data types and operations require. It is implementation dependent how much memory the Erlang data types and other items consume, but here are some figures for the current beam emulator version 5.2 system (OTP release R9B). The unit of measurement is memory words. There exists both a 32-bit and a 64-bit implementation, and a word is therefore, respectively, 4 bytes and 8 bytes.

Memory size of different data types
Data type | Memory size
Integer (-16#7FFFFFF < i <16#7FFFFFF) | 1 word
Integer (big numbers) | 3..N words
Atom | 1 word. Note, an atom refers into an atom table which also consumes memory. The atom text is stored once for each unique atom in this table. Note also, this table is not garbage collected.
Float | On 32-bit architectures: 4 words On 64-bit architectures: 3 words
Binary | 3..6 + data (can be shared)
List | 1 words per element + the size of each element
String (is the same as a List of Integers) | 2 words per character
Tuple | 2 words + the size of each element
Pid | 1 word for a process identifier from the current local node, and 5 words for a process identifier from another node. Note, a process identifier refers into a process table and a node table which also consumes memory.
Port | 1 word for a port identifier from the current local node, and 5 words for a port identifier from another node. Note, a port identifier refers into a port table and a node table which also consumes memory.
Reference | On 32-bit architectures: 5 words for a reference from the current local node, and 7 words for a reference from another node. On 64-bit architectures: 4 words for a reference from the current local node, and 6 words for a reference from another node. Note, a reference refers into a node table which also consumes memory.
Fun | 9..13 words + size of environment. Note, a fun refers into a code table which also consumes memory.
Ets table | Initially 768 words + the size of each element (6 words + size of Erlang data). The table will grow when necessary.
Erlang process | 327 words when spawned including a heap of 233 words.

### 7.2 System limits

The Erlang language specification puts no limits on number of processes, length of atoms etc. but for performance and memory saving reasons there will always be limits in a practical implementation of the Erlang language and execution environment. The current implementation has a few limitations that is good to know about since some of them can be of great importance for the design of an application.

Processes
  The maximum number of simultaneously alive Erlang processes is by default 32768. This limit can be raised up to at most 268435456 processes at startup (see documentation of the system flag +P in the erl(1) documentation). The maximum limit of 268435456 processes will at least on a 32-bit architecture be impossible to reach due to memory shortage.
Distributed nodes
  Known nodes
    A remote node Y has to be known to the node X if there exists any pids, ports, references, or funs (Erlang data types) from Y on X, or if X and Y are connected. The maximum number of remote nodes simultaneously/ever known to a node is limited by the maximum number of atoms available for node names. All data concerning remote nodes, except for the node name atom, are garbage collected.
  Connected nodes
    The maximum number of simultaneously connected nodes is limited by either the maximum number of simultaneously known remote nodes, the maximum number of (Erlang) ports available, or the maximum number of sockets available.
Characters in an atom
  255
Atoms
  The maximum number of atoms is 1048576.
Ets-tables
  default=1400, can be changed with the environment variable `ERL_MAX_ETS_TABLES`.
Elements in a tuple
  The maximum number of elements in a tuple is 67108863 (26 bit unsigned integer). Other factors such as the available memory can of course make it hard to create a tuple of that size.
Length of binary
  Unsigned
Total amount of data allocated by an Erlang node
  The Erlang runtime system can use the whole 32 bit address space, but the operating system often limits one single process to use less than that.
length of a node name
  An Erlang node name has the form host@shortname or host@longname. The node name is used as an atom within the system so the maximum size of 255 holds for the node name too.
Open ports
  The maximum number of simultaneously open Erlang ports is by default 1024. This limit can be raised up to at most 268435456 at startup (see environment variable ERL_MAX_PORTS in erlang(3)) The maximum limit of 268435456 open ports will at least on a 32-bit architecture be impossible to reach due to memory shortage.
Open files, and sockets
  The maximum number of simultaneously open files and sockets depend on the maximum number of Erlang ports available, and operating system specific settings and limits.
Number of arguments to a function or fun
  256

Copyright © 1991-2007 Ericsson AB