1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
7
<year>2001</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
24
<title>Advanced</title>
25
<prepared>Kenneth Lundin</prepared>
27
<date>2001-08-21</date>
29
<file>advanced.xml</file>
34
<p>A good start when programming efficiently is to have knowledge about
35
how much memory different data types and operations require. It is
36
implementation-dependent how much memory the Erlang data types and
37
other items consume, but here are some figures for
38
erts-5.2 system (OTP release R9B). (There have been no significant
41
<p>The unit of measurement is memory words. There exists both a 32-bit
42
and a 64-bit implementation, and a word is therefore, 4 bytes or
43
8 bytes, respectively.</p>
46
<cell align="center" valign="middle">Data type</cell>
47
<cell align="center" valign="middle">Memory size</cell>
50
<cell align="left" valign="middle">Integer (-16#7FFFFFF < i <16#7FFFFFF)</cell>
51
<cell align="left" valign="middle">1 word</cell>
54
<cell align="left" valign="middle">Integer (big numbers)</cell>
55
<cell align="left" valign="middle">3..N words</cell>
58
<cell align="left" valign="middle">Atom</cell>
59
<cell align="left" valign="middle">1 word. Note: an atom refers into
60
an atom table which also consumes memory.
61
The atom text is stored once for each unique atom in this table.
62
The atom table is <em>not</em> garbage-collected.</cell>
65
<cell align="left" valign="middle">Float</cell>
66
<cell align="left" valign="middle">On 32-bit architectures: 4 words <br></br>
67
On 64-bit architectures: 3 words</cell>
70
<cell align="left" valign="middle">Binary</cell>
71
<cell align="left" valign="middle">3..6 + data (can be shared)</cell>
74
<cell align="left" valign="middle">List</cell>
75
<cell align="left" valign="middle">1 word per element + the size of each element</cell>
78
<cell align="left" valign="middle">String (is the same as a list of integers)</cell>
79
<cell align="left" valign="middle">2 words per character</cell>
82
<cell align="left" valign="middle">Tuple</cell>
83
<cell align="left" valign="middle">2 words + the size of each element</cell>
86
<cell align="left" valign="middle">Pid</cell>
87
<cell align="left" valign="middle">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.</cell>
90
<cell align="left" valign="middle">Port</cell>
91
<cell align="left" valign="middle">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.</cell>
94
<cell align="left" valign="middle">Reference</cell>
95
<cell align="left" valign="middle">On 32-bit architectures: 5 words for a reference from the current local node, and 7 words for a reference from another node. <br></br>
96
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.</cell>
99
<cell align="left" valign="middle">Fun</cell>
100
<cell align="left" valign="middle">9..13 words + size of environment. Note: a fun refers into a fun table which also consumes memory.</cell>
103
<cell align="left" valign="middle">Ets table</cell>
104
<cell align="left" valign="middle">Initially 768 words + the size of each element (6 words + size of Erlang data). The table will grow when necessary.</cell>
107
<cell align="left" valign="middle">Erlang process</cell>
108
<cell align="left" valign="middle">327 words when spawned including a heap of 233 words.</cell>
110
<tcaption>Memory size of different data types</tcaption>
115
<title>System limits</title>
116
<p>The Erlang language specification puts no limits on number of processes,
117
length of atoms etc., but for performance and memory saving reasons,
118
there will always be limits in a practical implementation of the Erlang
119
language and execution environment.</p>
121
<tag><em>Processes</em></tag>
123
<p>The maximum number of simultaneously alive Erlang processes is
124
by default 32768. This limit can be raised up to at most 268435456
125
processes at startup (see documentation of the system flag
126
<seealso marker="erts:erl#max_processes">+P</seealso> in the
127
<seealso marker="erts:erl">erl(1)</seealso> documentation).
128
The maximum limit of 268435456 processes will at least on a 32-bit
129
architecture be impossible to reach due to memory shortage.</p>
131
<tag><em>Distributed nodes</em></tag>
134
<tag>Known nodes</tag>
136
<p>A remote node Y has to be known to node X if there exist
137
any pids, ports, references, or funs (Erlang data types) from Y
138
on X, or if X and Y are connected. The maximum number of remote
139
nodes simultaneously/ever known to a node is limited by the
140
<seealso marker="#atoms">maximum number of atoms</seealso>
141
available for node names. All data concerning remote nodes,
142
except for the node name atom, are garbage-collected.</p>
144
<tag>Connected nodes</tag>
145
<item>The maximum number of simultaneously connected nodes is limited by
146
either the maximum number of simultaneously known remote nodes,
147
<seealso marker="#ports">the maximum number of (Erlang) ports</seealso>
149
<seealso marker="#files_sockets">the maximum number of sockets</seealso>
153
<tag><em>Characters in an atom</em></tag>
155
<tag><em>Atoms </em></tag>
156
<item> <marker id="atoms"></marker>
157
The maximum number of atoms is 1048576. </item>
158
<tag><em>Ets-tables</em></tag>
159
<item>The default is 1400, can be changed with the environment variable <c>ERL_MAX_ETS_TABLES</c>.</item>
160
<tag><em>Elements in a tuple</em></tag>
161
<item>The maximum number of elements in a tuple is 67108863 (26 bit unsigned integer). Other factors
162
such as the available memory can of course make it hard to create a tuple of that size. </item>
163
<tag><em>Size of binary</em></tag>
164
<item>In the 32-bit implementation of Erlang, 536870911 bytes is the
165
largest binary that can be constructed or matched using the bit syntax.
166
(In the 64-bit implementation, the maximum size is 2305843009213693951 bytes.)
167
If the limit is exceeded, bit syntax construction will fail with a
168
<c>system_limit</c> exception, while any attempt to match a binary that is
170
This limit is enforced starting with the R11B-4 release; in earlier releases,
171
operations on too large binaries would in general either fail or give incorrect
173
In future releases of Erlang/OTP, other operations that create binaries (such as
174
<c>list_to_binary/1</c>) will probably also enforce the same limit.</item>
175
<tag><em>Total amount of data allocated by an Erlang node</em></tag>
176
<item>The Erlang runtime system can use the complete 32 (or 64) bit address space,
177
but the operating system often limits a single process to use less than that.</item>
178
<tag><em>length of a node name</em></tag>
179
<item>An Erlang node name has the form host@shortname or host@longname. The node name is
180
used as an atom within the system so the maximum size of 255 holds for the node name too.</item>
181
<tag><em>Open ports</em></tag>
183
<marker id="ports"></marker>
184
<p>The maximum number of simultaneously open Erlang ports is
185
by default 1024. This limit can be raised up to at most 268435456
186
at startup (see environment variable
187
<seealso marker="erts:erlang#ERL_MAX_PORTS">ERL_MAX_PORTS</seealso>
188
in <seealso marker="erts:erlang">erlang(3)</seealso>)
189
The maximum limit of 268435456 open ports will at least on a 32-bit
190
architecture be impossible to reach due to memory shortage.</p>
192
<tag><em>Open files, and sockets</em></tag>
193
<item> <marker id="files_sockets"></marker>
195
The maximum number of simultaneously open files and sockets
197
<seealso marker="#ports">the maximum number of Erlang ports</seealso>
198
available, and operating system specific settings and limits.</item>
199
<tag><em>Number of arguments to a function or fun</em></tag>