Skip to content

Commit c05fbe7

Browse files
authored
ext/yac: Add a Memory Management chapter and improve the examples (#5822)
Add a Memory Management chapter that explains the two independent shared-memory pools: - the key pool: a fixed-size slot table; expired and deleted slots are reused for free, and only a probe path of four live entries triggers an eviction (the least recently used, then the least hit), counted in the kicks counter - the value pool: 4M segments with a wrap-around allocator whose recycles overwrite the oldest values, detected by a CRC integrity guard and turned into misses Document how to size both pools and how to read the Yac::info counters (interval hit rate, kicks, recycles, fails) so each number maps to a concrete action. Also improve the examples: - split the combined add/set/get/delete examples into one runnable example per parameter form (single key, TTL, array form, default value, delayed deletion), each self-contained - fix the Yac::dump paging example, which returned an empty array on an empty cache while claiming int(100), and correct the per-entry hits reset semantics (reset on overwrite, not on delete or expiry) Further fixes: - fill the empty constant descriptions (YAC_VERSION, YAC_MAX_VALUE_RAW_LEN, YAC_MAX_RAW_COMPRESSED_LEN) and fix typos - align the synopsis parameter names with the arginfo ($keys -> $key) - document compress_threshold clamping (1024..1M, -1 disables) and the 1 MB stored-size / 64 MB raw-size limits - drop the stale configure.xml template (duplicated the installation section of setup.xml)
1 parent 30b010f commit c05fbe7

11 files changed

Lines changed: 413 additions & 107 deletions

File tree

reference/yac/book.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
path, a read is essentially a hash lookup in shared memory. As a
2626
result, Yac is extremely fast, with microsecond-level read
2727
latency, and its throughput can scale with the number of
28-
workers as long as writes are spread across keys.
28+
workers as long as writes are spread across keys; see the
29+
<link xlink:href="&url.git.hub;laruence/yac/blob/master/README.md#benchmarks">benchmarks</link>.
2930
</simpara>
3031
<simpara>
3132
Because Yac trades correctness guarantees for speed and throughput,
@@ -36,8 +37,9 @@
3637
</simpara>
3738
<simpara>
3839
As of yac 2.4.0, small scalar values —
39-
<constant>NULL</constant>, booleans, integers, short strings of up to
40-
7 bytes and empty arrays — are stored directly inside the hash slot
40+
<constant>NULL</constant>, booleans, most integers (those that fit in
41+
60 signed bits on 64-bit builds), strings of up to 7 bytes and empty
42+
arrays — are stored directly inside the hash slot
4143
instead of in a separate value block ("embedded values"), which
4244
removes the value-memory allocation and block copy on every access
4345
and significantly improves performance while reducing memory usage.
@@ -54,6 +56,7 @@
5456
</preface>
5557

5658
&reference.yac.setup;
59+
&reference.yac.memory;
5760
&reference.yac.constants;
5861
<!-- &reference.yac.examples; -->
5962
&reference.yac.yac;

reference/yac/configure.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.

reference/yac/constants.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</term>
1414
<listitem>
1515
<simpara>
16+
The version of the extension as a string.
1617
</simpara>
1718
</listitem>
1819
</varlistentry>
@@ -23,7 +24,8 @@
2324
</term>
2425
<listitem>
2526
<simpara>
26-
Max length of a key could be, it is 48 bytes.
27+
Maximum length of a key in bytes: 48. An instance prefix counts
28+
against this limit.
2729
</simpara>
2830
</listitem>
2931
</varlistentry>
@@ -34,6 +36,9 @@
3436
</term>
3537
<listitem>
3638
<simpara>
39+
Maximum length of a value before serialization, in bytes:
40+
67,108,863 (<literal>(1 &lt;&lt; 26) - 1</literal>). Larger values
41+
are rejected.
3742
</simpara>
3843
</listitem>
3944
</varlistentry>
@@ -44,6 +49,8 @@
4449
</term>
4550
<listitem>
4651
<simpara>
52+
Maximum size of a stored entry, in bytes: 1,048,576 (1M). Values
53+
that do not fit even after compression are rejected.
4754
</simpara>
4855
</listitem>
4956
</varlistentry>
@@ -54,7 +61,7 @@
5461
</term>
5562
<listitem>
5663
<simpara>
57-
Use php serialize as serializer
64+
Use the PHP serialize format as serializer (the default).
5865
</simpara>
5966
</listitem>
6067
</varlistentry>
@@ -65,7 +72,8 @@
6572
</term>
6673
<listitem>
6774
<simpara>
68-
Use json as serializer(requrie --enable-json)
75+
Use JSON as the serializer. Requires the extension to be built with
76+
<option role="configure">--enable-json</option>.
6977
</simpara>
7078
</listitem>
7179
</varlistentry>
@@ -76,7 +84,8 @@
7684
</term>
7785
<listitem>
7886
<simpara>
79-
Use igbinary as serializer(require --enable-igbinary)
87+
Use igbinary as the serializer. Requires the extension to be built
88+
with <option role="configure">--enable-igbinary</option>.
8089
</simpara>
8190
</listitem>
8291
</varlistentry>
@@ -87,7 +96,8 @@
8796
</term>
8897
<listitem>
8998
<simpara>
90-
Use msgpack as serializer(require --enable-msgpack)
99+
Use msgpack as the serializer. Requires the extension to be built
100+
with <option role="configure">--enable-msgpack</option>.
91101
</simpara>
92102
</listitem>
93103
</varlistentry>
@@ -98,7 +108,7 @@
98108
</term>
99109
<listitem>
100110
<simpara>
101-
Which serialzier is yac used
111+
The serializer currently used by the extension.
102112
</simpara>
103113
</listitem>
104114
</varlistentry>

reference/yac/ini.xml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<tbody>
2020
<row>
2121
<entry><link linkend="ini.yac.compress-threshold">yac.compress_threshold</link></entry>
22-
<entry>-1</entry>
22+
<entry>4K</entry>
2323
<entry><constant>INI_SYSTEM</constant></entry>
2424
<entry><!-- leave empty, this will be filled by an automatic script --></entry>
2525
</row>
@@ -43,7 +43,7 @@
4343
</row>
4444
<row>
4545
<entry><link linkend="ini.yac.keys-memory-size">yac.keys_memory_size</link></entry>
46-
<entry>4M</entry>
46+
<entry>8M</entry>
4747
<entry><constant>INI_SYSTEM</constant></entry>
4848
<entry><!-- leave empty, this will be filled by an automatic script --></entry>
4949
</row>
@@ -76,10 +76,17 @@
7676
<listitem>
7777
<simpara>
7878
Serialized values larger than this number of bytes are
79-
compressed before being stored (currently with LZ4). Set it to
80-
<literal>-1</literal> (the default) to disable compression
81-
entirely. Compressing large values saves shared memory at the cost
82-
of some CPU on both store and retrieve.
79+
compressed (with LZ4, since Yac 2.4.0) before being stored.
80+
Values above the <literal>1M</literal> stored entry limit
81+
(<constant>YAC_MAX_RAW_COMPRESSED_LEN</constant>) are always
82+
compressed regardless of this setting, because they cannot be
83+
stored uncompressed. The default of <literal>4K</literal>
84+
enables compression; <literal>-1</literal> disables it for
85+
values below the stored entry limit, and other positive values
86+
are clamped to the
87+
<literal>1024</literal>..<literal>1M</literal> range.
88+
Compressing large values saves shared memory at the cost of
89+
some CPU on both store and retrieve.
8390
</simpara>
8491
</listitem>
8592
</varlistentry>
@@ -128,12 +135,30 @@
128135
</term>
129136
<listitem>
130137
<simpara>
131-
Amount of shared memory used for the hash slots that hold keys
132-
and bookkeeping. Each slot is a fixed-size structure, so this value
133-
determines how many items can be tracked at once. Defaults to
134-
<literal>4M</literal>. Yac splits this area into segments; the
135-
segment size is 4M, so this value must be a multiple of
136-
<literal>4M</literal>.
138+
Amount of shared memory for the table of keys. It caps how many
139+
entries can exist at once — the default of
140+
<literal>8M</literal> gives around 65,536 entries. Raise this
141+
when the hit rate drops and <literal>kicks</literal> climb; see
142+
<xref linkend="yac.memory-management"/> for how a full table
143+
behaves and when that actually matters.
144+
</simpara>
145+
</listitem>
146+
</varlistentry>
147+
<varlistentry xml:id="ini.yac.values-memory-size">
148+
<term>
149+
<parameter>yac.values_memory_size</parameter>
150+
<type>string</type>
151+
</term>
152+
<listitem>
153+
<simpara>
154+
Amount of shared memory for storing values. Values are allocated
155+
in a bump allocator over segments of 4M each; when no segment has
156+
room for a new value, an allocator cursor wraps and the oldest
157+
values are silently overwritten ("recycled"). Their reads then
158+
degrade to misses, detected by an integrity guard. Enlarge this
159+
if <literal>recycles</literal> climb while slots still have room,
160+
or enable <link linkend="ini.yac.compress-threshold">yac.compress_threshold</link>
161+
to shrink large payloads. See <xref linkend="yac.memory-management"/>.
137162
</simpara>
138163
</listitem>
139164
</varlistentry>
@@ -155,21 +180,6 @@
155180
</simpara>
156181
</listitem>
157182
</varlistentry>
158-
<varlistentry xml:id="ini.yac.values-memory-size">
159-
<term>
160-
<parameter>yac.values_memory_size</parameter>
161-
<type>string</type>
162-
</term>
163-
<listitem>
164-
<simpara>
165-
Amount of shared memory used to store the actual values.
166-
Defaults to <literal>64M</literal>. Yac allocates this area in
167-
segments of 4M each, so this value must be a multiple of
168-
<literal>4M</literal>. When the area is full, least recently used
169-
entries are kicked to make room for new ones.
170-
</simpara>
171-
</listitem>
172-
</varlistentry>
173183

174184
</variablelist>
175185
</para>

0 commit comments

Comments
 (0)