Mercurial > hg > nginx-site
annotate xml/en/docs/njs/preload_objects.xml @ 3029:27008cb3fb27
Updated docs for the upcoming NGINX Plus release.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 19 Dec 2023 12:58:01 +0000 |
parents | 48f245493600 |
children |
rev | line source |
---|---|
2984
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
1 <?xml version="1.0"?> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
2 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
3 <!-- |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
4 Copyright (C) Nginx, Inc. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
5 --> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
6 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
8 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
9 <article name="Understanding preloaded objects" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
10 link="/en/docs/njs/preload_objects.html" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
11 lang="en" |
3002
48f245493600
Slightly updated text in Preload Objects in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
2984
diff
changeset
|
12 rev="2" |
2984
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
13 toc="no"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
14 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
15 <section id="summary"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
16 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
17 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
18 For each incoming request njs creates a separate virtual machine. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
19 This brings a lot of benefits such as predictable memory consumption |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
20 or requests isolation. |
3002
48f245493600
Slightly updated text in Preload Objects in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
2984
diff
changeset
|
21 However, as all requests are isolated, |
2984
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
22 if a request handler needs to access some data, |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
23 it has to read it by itself. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
24 This is not efficient especially when the amount of data is large. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
25 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
26 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
27 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
28 To address this limitation, |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
29 a preloaded shared object was introduced. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
30 Such objects are created immutable and do not have prototype chains: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
31 their values cannot be changed, properties cannot be added or removed. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
32 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
33 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
34 </section> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
35 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
36 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
37 <section id="working_with_preload_objects" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
38 name="Working with preload objects"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
39 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
40 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
41 Here are some examples of how to work with a preload object in njs: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
42 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
43 <list type="bullet"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
44 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
45 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
46 access properties by name: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
47 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
48 preloaded_object.prop_name |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
49 preloaded_object[prop_name] |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
50 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
51 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
52 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
53 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
54 enumerate properties: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
55 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
56 for (i in preloaded_object_name) { |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
57 ... |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
58 } |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
59 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
60 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
61 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
62 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
63 apply non-modifying built-in methods using <literal>call()</literal>: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
64 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
65 Array.prototype.filter.call(preloaded_object_name, ...) |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
66 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
67 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
68 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
69 </list> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
70 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
71 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
72 </section> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
73 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
74 </article> |