aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSchemaTuningBuilderTest.java
blob: 764e31fe13a293d0a31d2f6f0d61527fcc2d8293 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.builder.xml.dom;

import com.yahoo.collections.CollectionUtil;
import com.yahoo.vespa.config.search.core.ProtonConfig;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.vespa.model.search.Tuning;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author geirst
 */
public class DomSchemaTuningBuilderTest extends DomBuilderTest {

    private static final double DELTA = 0.000001;

    private static Element parseXml(String... xmlLines) {
        return parse("<tuning>",
                "<searchnode>",
                CollectionUtil.mkString(Arrays.asList(xmlLines), "\n"),
                "</searchnode>",
                "</tuning>");
    }

    private Tuning createTuning(Element xml) {
        DomSearchTuningBuilder b = new DomSearchTuningBuilder();
        return b.build(root.getDeployState(), root, xml);
    }

    private ProtonConfig getProtonCfg(Tuning tuning) {
        ProtonConfig.Builder pb = new ProtonConfig.Builder();
        tuning.getConfig(pb);
        return new ProtonConfig(pb);
    }

    @Test
    void requireThatWeCanParseRequestThreadsTag() {
        Tuning t = createTuning(parseXml("<requestthreads>",
                "<search>123</search>",
                "<persearch>34</persearch>",
                "<summary>456</summary>",
                "</requestthreads>"));
        assertEquals(123, t.searchNode.threads.numSearchThreads.longValue());
        assertEquals(456, t.searchNode.threads.numSummaryThreads.longValue());
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.numsearcherthreads(), 123);
        assertEquals(cfg.numthreadspersearch(), 34);
        assertEquals(cfg.numsummarythreads(), 456);
    }

    @Test
    void requireThatWeCanParseLidSpaceTag() {
        Tuning t = createTuning(parseXml("<lidspace>",
                "<max-bloat-factor>0.5</max-bloat-factor>",
                "</lidspace>"));
        assertEquals(0.5, t.searchNode.lidSpace.bloatFactor.doubleValue());
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.lidspacecompaction().allowedlidbloatfactor(), 0.5);
    }

    @Test
    void requireThatWeCanParseFlushStrategyTag() {
        Tuning t = createTuning(parseXml("<flushstrategy>", "<native>",
                "<total>",
                "<maxmemorygain>900</maxmemorygain>",
                "<diskbloatfactor>8.7</diskbloatfactor>",
                "</total>",
                "<component>",
                "<maxmemorygain>600</maxmemorygain>",
                "<diskbloatfactor>5.4</diskbloatfactor>",
                "<maxage>300</maxage>",
                "</component>",
                "<transactionlog>",
                "<maxsize>1024</maxsize>",
                "</transactionlog>",
                "<conservative>",
                "<memory-limit-factor>0.6</memory-limit-factor>",
                "<disk-limit-factor>0.7</disk-limit-factor>",
                "</conservative>",
                "</native>", "</flushstrategy>"));
        assertEquals(900, t.searchNode.strategy.totalMaxMemoryGain.longValue());
        assertEquals(8.7, t.searchNode.strategy.totalDiskBloatFactor, DELTA);
        assertEquals(600, t.searchNode.strategy.componentMaxMemoryGain.longValue());
        assertEquals(5.4, t.searchNode.strategy.componentDiskBloatFactor, DELTA);
        assertEquals(300, t.searchNode.strategy.componentMaxage, DELTA);
        assertEquals(1024, t.searchNode.strategy.transactionLogMaxSize.longValue());
        assertEquals(0.6, t.searchNode.strategy.conservativeMemoryLimitFactor, DELTA);
        assertEquals(0.7, t.searchNode.strategy.conservativeDiskLimitFactor, DELTA);
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.flush().memory().maxmemory(), 900);
        assertEquals(cfg.flush().memory().diskbloatfactor(),  8.7, DELTA);
        assertEquals(cfg.flush().memory().each().maxmemory(), 600);
        assertEquals(cfg.flush().memory().each().diskbloatfactor(), 5.4, DELTA);
        assertEquals(cfg.flush().memory().maxage().time(), 300, DELTA);
        assertEquals(cfg.flush().memory().maxtlssize(), 1024);
        assertEquals(cfg.flush().memory().conservative().memorylimitfactor(), 0.6, DELTA);
        assertEquals(cfg.flush().memory().conservative().disklimitfactor(), 0.7, DELTA);
    }

    @Test
    void requireThatWeCanParseIndexTag() {
        Tuning t = createTuning(parseXml("<index>", "<io>",
                "<search>mmap</search>",
                "</io>",
                "<warmup>" +
                        "<time>178</time>",
                "<unpack>true</unpack>",
                "</warmup>",
                "</index>"));
        assertEquals(Tuning.SearchNode.IoType.MMAP, t.searchNode.index.io.search);
        assertEquals(178, t.searchNode.index.warmup.time, DELTA);
        assertTrue(t.searchNode.index.warmup.unpack);
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.indexing().write().io(), ProtonConfig.Indexing.Write.Io.DIRECTIO);
        assertEquals(cfg.indexing().read().io(), ProtonConfig.Indexing.Read.Io.DIRECTIO);
        assertEquals(cfg.index().warmup().time(), 178, DELTA);
        assertTrue(cfg.index().warmup().unpack());
    }

    @Test
    void requireThatWeCanPopulateIndex() {
        Tuning t = createTuning(parseXml("<index>", "<io>",
                "<search>populate</search>",
                "</io>",
                "</index>"));
        assertEquals(Tuning.SearchNode.IoType.POPULATE, t.searchNode.index.io.search);

        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.indexing().write().io(), ProtonConfig.Indexing.Write.Io.DIRECTIO);
        assertEquals(cfg.indexing().read().io(), ProtonConfig.Indexing.Read.Io.DIRECTIO);
        assertEquals(cfg.search().mmap().options().size(), 1);
        assertEquals(cfg.search().mmap().options().get(0), ProtonConfig.Search.Mmap.Options.POPULATE);
    }


    @Test
    void requireThatWeCanParseRemovedDBTag() {
        Tuning t = createTuning(parseXml("<removed-db>", "<prune>",
                "<age>19388</age>",
                "<interval>193</interval>",
                "</prune>", "</removed-db>"));
        assertEquals(19388, t.searchNode.removedDB.prune.age, DELTA);
        assertEquals(193, t.searchNode.removedDB.prune.interval, DELTA);
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.pruneremoveddocumentsinterval(), 193, DELTA);
        assertEquals(cfg.pruneremoveddocumentsage(), 19388, DELTA);
    }

    @Test
    void requireThatWeCanParseAttributeTag() {
        Tuning t = createTuning(parseXml("<attribute>", "<io>",
                "<write>normal</write>",
                "</io>", "</attribute>"));
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.attribute().write().io(), ProtonConfig.Attribute.Write.Io.DIRECTIO);
    }

    @Test
    void requireThatWeCanParseSummaryTag() {
        Tuning t = createTuning(parseXml("<summary>",
                "<io>",
                "<write>directio</write>",
                "<read>directio</read>",
                "</io>",
                "<store>",
                "<cache>",
                "<maxsize>128</maxsize>",
                "<maxsize-percent>30.7</maxsize-percent>",
                "<initialentries>64</initialentries>",
                "<compression>",
                "<type>none</type>",
                "<level>3</level>",
                "</compression>",
                "</cache>",
                "<logstore>",
                "<maxfilesize>512</maxfilesize>",
                "<minfilesizefactor>0.3</minfilesizefactor>",
                "<chunk>",
                "<maxsize>256</maxsize>",
                "<compression>",
                "<type>lz4</type>",
                "<level>5</level>",
                "</compression>",
                "</chunk>",
                "</logstore>",
                "</store>",
                "</summary>"));
        assertEquals(Tuning.SearchNode.IoType.DIRECTIO, t.searchNode.summary.io.read);
        assertEquals(128, t.searchNode.summary.store.cache.maxSize.longValue());
        assertEquals(30.7, t.searchNode.summary.store.cache.maxSizePercent, DELTA);
        assertEquals(Tuning.SearchNode.Summary.Store.Compression.Type.NONE,
                t.searchNode.summary.store.cache.compression.type);
        assertEquals(3, t.searchNode.summary.store.cache.compression.level.intValue());
        assertEquals(512, t.searchNode.summary.store.logStore.maxFileSize.longValue());
        assertEquals(0.3, t.searchNode.summary.store.logStore.minFileSizeFactor, DELTA);
        assertEquals(256, t.searchNode.summary.store.logStore.chunk.maxSize.intValue());
        assertEquals(Tuning.SearchNode.Summary.Store.Compression.Type.LZ4,
                t.searchNode.summary.store.logStore.chunk.compression.type);
        assertEquals(5, t.searchNode.summary.store.logStore.chunk.compression.level.intValue());
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.summary().write().io(), ProtonConfig.Summary.Write.Io.DIRECTIO);
        assertEquals(cfg.summary().read().io(), ProtonConfig.Summary.Read.Io.DIRECTIO);
        assertEquals(cfg.summary().cache().maxbytes(), 128);
        assertEquals(cfg.summary().cache().initialentries(), 64);
        assertEquals(cfg.summary().cache().compression().type(), ProtonConfig.Summary.Cache.Compression.Type.NONE);
        assertEquals(cfg.summary().cache().compression().level(), 3);
        assertEquals(cfg.summary().log().maxfilesize(), 512);
        assertEquals(cfg.summary().log().minfilesizefactor(), 0.3, DELTA);
        assertEquals(cfg.summary().log().chunk().maxbytes(), 256);
        assertEquals(cfg.summary().log().chunk().compression().type(), ProtonConfig.Summary.Log.Chunk.Compression.Type.LZ4);
        assertEquals(cfg.summary().log().chunk().compression().level(), 5);
        assertEquals(cfg.summary().log().compact().compression().type(), ProtonConfig.Summary.Log.Compact.Compression.Type.LZ4);
        assertEquals(cfg.summary().log().compact().compression().level(), 5);
    }

    @Test
    void requireThatWeCanGiveSummaryCacheSizeInPercentage() {
        Tuning t = createTuning(parseXml("<summary>",
                "<store>",
                "<cache>",
                "<maxsize-percent>30.7</maxsize-percent>",
                "</cache>",
                "</store>",
                "</summary>"));

        assertNull(t.searchNode.summary.store.cache.maxSize);
        assertEquals(30.7, t.searchNode.summary.store.cache.maxSizePercent, DELTA);

        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.summary().cache().maxbytes(), -30);
    }

    @Test
    void requireThatWeCanPopulateSummary() {
        Tuning t = createTuning(parseXml("<summary>",
                "<io>",
                "<read>populate</read>",
                "</io>",
                "</summary>"));

        assertEquals(Tuning.SearchNode.IoType.POPULATE, t.searchNode.summary.io.read);

        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(ProtonConfig.Summary.Read.Io.MMAP, cfg.summary().read().io());
        assertEquals(ProtonConfig.Summary.Read.Mmap.Options.POPULATE, cfg.summary().read().mmap().options().get(0));
    }


    @Test
    void requireThatWeCanParseInitializeTag() {
        Tuning t = createTuning(parseXml("<initialize>",
                "<threads>7</threads>",
                "</initialize>"));
        assertEquals(7, t.searchNode.initialize.threads.intValue());
        ProtonConfig cfg = getProtonCfg(t);
        assertEquals(cfg.initialize().threads(), 7);
    }

    @Test
    void requireThatWeCanParseFeedingTag() {
        Tuning t = createTuning(parseXml("<feeding>",
                "<concurrency>0.7</concurrency>",
                "<niceness>0.3</niceness>",
                "</feeding>"));
        assertEquals(0.7, t.searchNode.feeding.concurrency, DELTA);
        assertEquals(0.3, t.searchNode.feeding.niceness, DELTA);
        var cfg = getProtonCfg(t);
        assertEquals(cfg.feeding().concurrency(), 0.7, DELTA);
        assertEquals(cfg.feeding().niceness(), 0.3, DELTA);
    }

}