Mercurial > hg > nginx-site
annotate xml/ru/docs/njs/preload_objects.xml @ 3005:8b8f94802f41
Fixed lang attribute, added module closing tag.
author | Ryan Davis <ry.davis@f5.com> |
---|---|
date | Thu, 31 Aug 2023 15:14:39 -0400 |
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="Предзагруженные объекты" |
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" |
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 Для каждого входящего запроса в 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 или осуществить изоляцию запросов. |
3002
48f245493600
Slightly updated text in Preload Objects in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
2984
diff
changeset
|
21 Однако поскольку все запросы являются изолированными, то |
2984
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 ему нужно сначала их прочитать самому. |
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 </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 Это ограничение можно обойти |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
29 при помощи разделяемого предзагруженного объекта. |
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 у них нет возможности |
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 </para> |
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 </section> |
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 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
38 <section id="working_with_preload_objects" |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
39 name="Работа с предзагруженными объектами"> |
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 <para> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
42 Примеры работы с предзагруженными объектами в njs: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
43 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
44 <list type="bullet"> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
45 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
46 <listitem> |
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 <programlisting> |
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 preloaded_object[prop_name] |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
51 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
52 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
53 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
54 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
55 перечисление свойств: |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
56 <programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
57 for (i in preloaded_object_name) { |
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 } |
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 </listitem> |
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 <listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
64 применение встроенных методов, не изменяющих состояние, |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
65 при помощи <literal>call()</literal>: |
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 Array.prototype.filter.call(preloaded_object_name, ...) |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
68 </programlisting> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
69 </listitem> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
70 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
71 </list> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
72 </para> |
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 </section> |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
75 |
cc475ba7d406
Added Preload Objects article in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
76 </article> |