File: advanced.html

package info (click to toggle)
erlang-doc-html 1%3A11.b.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,284 kB
  • ctags: 10,724
  • sloc: erlang: 505; ansic: 323; makefile: 62; perl: 61; sh: 45
file content (381 lines) | stat: -rw-r--r-- 9,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
  <TITLE>Advanced</TITLE>
  <SCRIPT type="text/javascript" src="../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="7"><!-- Empty --></A>
<H2>7 Advanced</H2>
<A NAME="7.1"><!-- Empty --></A>
<H3>7.1 Memory</H3>

<P>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.
<P>
<CENTER>
<TABLE CELLSPACING=0 CELLPADDING=2 BORDER=1>
  <CAPTION ALIGN=BOTTOM><EM>Memory size of different data types</EM></CAPTION>
  <TR>
    <TD ALIGN="CENTER" VALIGN="MIDDLE">
Data type
    </TD>
    <TD ALIGN="CENTER" VALIGN="MIDDLE">
Memory size
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Integer (-16#7FFFFFF &#60; i &#60;16#7FFFFFF)
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
1 word
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Integer (big numbers)
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
3..N words
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Atom
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
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
         <STRONG>not</STRONG> garbage collected.
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Float
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
         On 32-bit architectures: 4 words
         <BR>

         On 64-bit architectures: 3 words
         
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Binary
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
3..6 + data (can be shared)
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
List
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
1 words per element + the size of each element
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
String (is the same as a List of Integers)
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
2 words per character
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Tuple
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
2 words + the size of each element
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Pid
    </TD>
    <TD 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.
         
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Port
    </TD>
    <TD 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.
         
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Reference
    </TD>
    <TD 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>

         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.
         
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Fun
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
9..13 words + size of environment. Note, a
         fun refers into a code table which also consumes memory.
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Ets table
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Initially 768 words + the size of each element (6 words
         + size of Erlang data). The table will grow when necessary.
    </TD>

  </TR>
  <TR>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
Erlang process
    </TD>
    <TD ALIGN="LEFT" VALIGN="MIDDLE">
327 words when spawned including a heap of 233 words.
    </TD>

  </TR>

</TABLE>
</CENTER>
<A NAME="7.2"><!-- Empty --></A>
<H3>7.2 System limits</H3>

<P>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.
<P>
<DL>

<DT>
<STRONG>Processes</STRONG>
</DT>

<DD>
        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
        <A HREF="javascript:erlhref('../../', 'erts', 'erl.html#max_processes');">+P</A> in the
        <A HREF="javascript:erlhref('../../', 'erts', 'erl.html');">erl(1)</A> documentation).
        The maximum limit of 268435456 processes will at least on a 32-bit
        architecture be impossible to reach due to memory shortage.
        <BR>

        
</DD>

<DT>
<STRONG>Distributed nodes</STRONG>
</DT>

<DD>
         
<DL>

<DT>
Known nodes
</DT>

<DD>
         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
         <A HREF="#atoms">maximum number of atoms</A>
         available for node names. All data concerning remote nodes,
         except for the node name atom, are garbage collected.
         <BR>

         
</DD>

<DT>
Connected nodes
</DT>

<DD>
         The maximum number of simultaneously connected nodes is limited by
         either the maximum number of simultaneously known remote nodes,
         <A HREF="#ports">the maximum number of (Erlang) ports</A>
         available, or
         <A HREF="#files_sockets">the maximum number of sockets</A>
         available.
         
</DD>

</DL>

        
</DD>

<DT>
<STRONG>Characters in an atom</STRONG>
</DT>

<DD>
255
        
</DD>

<DT>
<STRONG>Atoms </STRONG>
</DT>

<DD>
<A NAME="atoms"><!-- Empty --></A>The maximum number of atoms is 1048576. 
        
</DD>

<DT>
<STRONG>Ets-tables</STRONG>
</DT>

<DD>
default=1400, can be changed with the environment variable <CODE>ERL_MAX_ETS_TABLES</CODE>.
        
</DD>

<DT>
<STRONG>Elements in a tuple</STRONG>
</DT>

<DD>
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. 

</DD>

<DT>
<STRONG>Length of binary</STRONG>
</DT>

<DD>
Unsigned

</DD>

<DT>
<STRONG>Total amount of data allocated by an Erlang node</STRONG>
</DT>

<DD>
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. 

</DD>

<DT>
<STRONG>length of a node name</STRONG>
</DT>

<DD>
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.

</DD>

<DT>
<STRONG>Open ports</STRONG>
</DT>

<DD>
<A NAME="ports"><!-- Empty --></A>
        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
        <A HREF="javascript:erlhref('../../', 'kernel', 'erlang.html#ERL_MAX_PORTS');">ERL_MAX_PORTS</A>
        in <A HREF="javascript:erlhref('../../', 'kernel', 'erlang.html');">erlang(3)</A>)
        The maximum limit of 268435456 open ports will at least on a 32-bit
        architecture be impossible to reach due to memory shortage.
        <BR>


</DD>

<DT>
<STRONG>Open files, and sockets</STRONG>
</DT>

<DD>
<A NAME="files_sockets"><!-- Empty --></A>
        The maximum number of simultaneously open files and sockets
        depend on
        <A HREF="#ports">the maximum number of Erlang ports</A>
        available, and operating system specific settings and limits.

</DD>

<DT>
<STRONG>Number of arguments to a function or fun</STRONG>
</DT>

<DD>
 256

</DD>

</DL>
<CENTER>
<HR>
<SMALL>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>