Mercurial > hg > nginx-site
annotate xml/ru/docs/njs/preload_objects.xml @ 3000:7eafa16bb07c
Replaced "delete" to "del" in js_shared_dict_zone.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Wed, 16 Aug 2023 12:12:22 +0100 |
parents | cc475ba7d406 |
children | 48f245493600 |
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="Предзагруженные объекты" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
10 link="/ru/docs/njs/preload_objects.html" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
11 lang="ru" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
12 rev="1" |
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 Для каждого входящего запроса в njs создаётся отдельная виртуальная машина. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
19 Это позволяет прогнозировать предсказуемое поглощение памяти |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
20 или осуществить изоляцию запросов. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
21 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
22 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
23 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
24 Однако у такого подхода есть недостатки. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
25 Поскольку все запросы являются изолированными, то |
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 ему нужно сначала их прочитать самому. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
28 Это неэффективно, особенно если объём данных большой. |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
29 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
30 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
31 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
32 Это ограничение можно обойти |
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 Такие объекты создаются неизменяемыми и не имеют цепочки прототипов: |
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 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
38 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
39 </section> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
40 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
41 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
42 <section id="working_with_preload_objects" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
43 name="Работа с предзагруженными объектами"> |
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 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
46 Примеры работы с предзагруженными объектами в njs: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
47 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
48 <list type="bullet"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
49 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
50 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
51 доступ к свойствам по имени: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
52 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
53 preloaded_object.prop_name |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
54 preloaded_object[prop_name] |
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 </listitem> |
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 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
59 перечисление свойств: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
60 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
61 for (i in preloaded_object_name) { |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
62 ... |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
63 } |
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 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
66 |
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 при помощи <literal>call()</literal>: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
70 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
71 Array.prototype.filter.call(preloaded_object_name, ...) |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
72 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
73 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
74 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
75 </list> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
76 </para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
77 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
78 </section> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
79 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
80 </article> |