aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomSearchTuningBuilderTest.java
blob: 14c36ef271ddfcb96ed66442b936a28320efc510 (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
278
279
280
281
282
283
284
// Copyright 2017 Yahoo Holdings. 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.config.ConfigInstance;
import com.yahoo.vespa.config.search.core.ProtonConfig;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.text.StringUtilities;
import com.yahoo.vespa.model.search.Tuning;
import org.junit.Test;
import org.w3c.dom.Element;

import java.util.Arrays;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
 * @author geirst
 */
public class DomSearchTuningBuilderTest 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 newTuning(String xml) {
        return createTuning(parse(xml));
    }

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

    String getProtonCfg(Tuning tuning) {
        ProtonConfig.Builder pb = new ProtonConfig.Builder();
        tuning.getConfig(pb);
        return StringUtilities.implode(ConfigInstance.serialize(new ProtonConfig(pb)).toArray(new String[0]), "\n");
    }

    @Test
    public void requireThatNullDispatchIsSafe() {
        Tuning tuning = newTuning("<tuning />");
        assertNull(tuning.dispatch);
    }

    @Test
    public void requireThatEmptyDispatchIsSafe() {
        Tuning tuning = newTuning("<tuning><dispatch/></tuning>");
        Tuning.Dispatch dispatch = tuning.dispatch;
        assertNotNull(dispatch);
        assertNull(dispatch.maxHitsPerPartition);
    }

    @Test
    public void requireThatDispatchSettingsAreParsed() {
        Tuning tuning = createTuning(parse("<tuning>" +
                                           "  <dispatch>" +
                                           "    <max-hits-per-partition>69</max-hits-per-partition>" +
                                           "  </dispatch>" +
                                           "</tuning>"));
        Tuning.Dispatch dispatch = tuning.dispatch;
        assertNotNull(dispatch);
        assertNotNull(dispatch.maxHitsPerPartition);
        assertEquals(69, dispatch.maxHitsPerPartition.intValue());
    }

    @Test
    public 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());
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("numsearcherthreads 123"));
        assertThat(cfg, containsString("numthreadspersearch 34"));
        assertThat(cfg, containsString("numsummarythreads 456"));
     }

    @Test
    public 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.doubleValue(), DELTA);
        assertEquals(600, t.searchNode.strategy.componentMaxMemoryGain.longValue());
        assertEquals(5.4, t.searchNode.strategy.componentDiskBloatFactor.doubleValue(), DELTA);
        assertEquals(300, t.searchNode.strategy.componentMaxage.doubleValue(), DELTA);
        assertEquals(1024, t.searchNode.strategy.transactionLogMaxSize.longValue());
        assertEquals(0.6, t.searchNode.strategy.conservativeMemoryLimitFactor.doubleValue(), DELTA);
        assertEquals(0.7, t.searchNode.strategy.conservativeDiskLimitFactor.doubleValue(), DELTA);
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("flush.memory.maxmemory 900"));
        assertThat(cfg, containsString("flush.memory.diskbloatfactor 8.7"));
        assertThat(cfg, containsString("flush.memory.each.maxmemory 600"));
        assertThat(cfg, containsString("flush.memory.each.diskbloatfactor 5.4"));
        assertThat(cfg, containsString("flush.memory.maxage.time 300"));
        assertThat(cfg, containsString("flush.memory.maxtlssize 1024"));
        assertThat(cfg, containsString("flush.memory.conservative.memorylimitfactor 0.6"));
        assertThat(cfg, containsString("flush.memory.conservative.disklimitfactor 0.7"));
    }

    @Test
    public void requireThatWeCanParseResizingTag() {
        Tuning t = createTuning(parseXml("<resizing>",
                "<initialdocumentcount>128</initialdocumentcount>",
                "</resizing>"));
        assertEquals(128, t.searchNode.resizing.initialDocumentCount.intValue());
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("grow.initial 128"));
    }

    @Test
    public void requireThatWeCanParseIndexTag() {
        Tuning t = createTuning(parseXml("<index>", "<io>",
                "<write>directio</write>",
                "<read>normal</read>",
                "<search>mmap</search>",
                "</io>",
                "<warmup>" +
                "<time>178</time>",
                "<unpack>true</unpack>",
                "</warmup>",
                "</index>"));
        assertEquals(Tuning.SearchNode.IoType.DIRECTIO, t.searchNode.index.io.write);
        assertEquals(Tuning.SearchNode.IoType.NORMAL, t.searchNode.index.io.read);
        assertEquals(Tuning.SearchNode.IoType.MMAP, t.searchNode.index.io.search);
        assertEquals(178, t.searchNode.index.warmup.time, DELTA);
        assertTrue(t.searchNode.index.warmup.unpack);
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("indexing.write.io DIRECTIO"));
        assertThat(cfg, containsString("indexing.read.io NORMAL"));
        assertThat(cfg, containsString("index.warmup.time 178"));
        assertThat(cfg, containsString("index.warmup.unpack true"));
    }

    @Test
    public 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);
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("pruneremoveddocumentsinterval 193"));
        assertThat(cfg, containsString("pruneremoveddocumentsage 19388"));
    }

    @Test
    public void requireThatWeCanParseAttributeTag() {
        Tuning t = createTuning(parseXml("<attribute>", "<io>",
                "<write>directio</write>",
                "</io>", "</attribute>"));
        assertEquals(Tuning.SearchNode.IoType.DIRECTIO, t.searchNode.attribute.io.write);
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("attribute.write.io DIRECTIO"));
    }

    @Test
    public 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.write);
        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.doubleValue(), 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());
        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("summary.write.io DIRECTIO"));
        assertThat(cfg, containsString("summary.read.io DIRECTIO"));
        assertThat(cfg, containsString("summary.cache.maxbytes 128"));
        assertThat(cfg, containsString("summary.cache.initialentries 64"));
        assertThat(cfg, containsString("summary.cache.compression.type NONE"));
        assertThat(cfg, containsString("summary.cache.compression.level 3"));
        assertThat(cfg, containsString("summary.log.maxfilesize 512"));
        assertThat(cfg, containsString("summary.log.minfilesizefactor 0.3"));
        assertThat(cfg, containsString("summary.log.chunk.maxbytes 256"));
        assertThat(cfg, containsString("summary.log.chunk.compression.type LZ4"));
        assertThat(cfg, containsString("summary.log.chunk.compression.level 5"));
    }

    @Test
    public 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.doubleValue(),DELTA);

        String cfg = getProtonCfg(t);
        assertThat(cfg, containsString("summary.cache.maxbytes -30"));
    }


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

    @Test
    public void requireThatWeCanParseFeedingTag() {
        Tuning t = createTuning(parseXml("<feeding>",
                "<concurrency>0.7</concurrency>",
                "</feeding>"));
        assertEquals(0.7, t.searchNode.feeding.concurrency.doubleValue(), DELTA);
        assertThat(getProtonCfg(t), containsString("feeding.concurrency 0.35"));
    }

}