Commit 9545daf
authored
Modest memory savings in date_histogram>terms (#68592)
This saves 16 bytes of memory per bucket for some aggregations.
Specifically, it kicks in when there is a parent bucket and we have a good
estimate on its upper bound cardinality, and we have good estimate on the
per-bucket cardinality of this aggregation, and both those upper bounds
will fit into a single `long`.
That sounds unlikely, but there is a fairly common case where we have it:
a `date_histogram` followed by a `terms` aggregation powered by global
ordinals. This is common enough that we already had at least two rally
operations for it:
* `date-histo-string-terms-via-global-ords`
* `filtered-date-histo-string-terms-via-global-ords`
Running those rally tracks shows that the space savings yields a small
but statistically significant perform bump. The 90th percentile service
time drops by about 4% in the unfiltered case and 1% for the filtered
case. That's not great but it good to know saving 16 bytes doesn't slow
us down.
```
| 50th percentile latency | date-histo | 3185.77 | 3028.65 | -157.118 | ms |
| 90th percentile latency | date-histo | 3237.07 | 3101.32 | -135.752 | ms |
| 100th percentile latency | date-histo | 3270.53 | 3178.7 | -91.8319 | ms |
| 50th percentile service time | date-histo | 3181.55 | 3024.32 | -157.238 | ms |
| 90th percentile service time | date-histo | 3232.91 | 3097.67 | -135.238 | ms |
| 100th percentile service time | date-histo | 3266.63 | 3175.08 | -91.5494 | ms |
| 50th percentile latency | filtered-date-histo | 1349.22 | 1331.94 | -17.2717 | ms |
| 90th percentile latency | filtered-date-histo | 1402.71 | 1383.7 | -19.0131 | ms |
| 100th percentile latency | filtered-date-histo | 1412.41 | 1397.7 | -14.7139 | ms |
| 50th percentile service time | filtered-date-histo | 1345.18 | 1326.2 | -18.9806 | ms |
| 90th percentile service time | filtered-date-histo | 1397.24 | 1378.14 | -19.1031 | ms |
| 100th percentile service time | filtered-date-histo | 1406.69 | 1391.63 | -15.0529 | ms |
```
The microbenchmarks for `LongKeyedBucketOrds`, the interface we're
targeting, show a performance boost on the method in the path of about
13%. This is obvious not the entire hot path, given that th 13% savings
translated to a 4% performance savings over the whole agg. But its
something.
```
Benchmark Mode Cnt Score Error Units
multiBucketMany avgt 5 10.038 ± 0.009 ns/op
multiBucketManySmall avgt 5 8.738 ± 0.029 ns/op
singleBucketIntoMulti avgt 5 7.701 ± 0.073 ns/op
singleBucketIntoSingleImmutableBimorphicInvocation avgt 5 6.160 ± 0.029 ns/op
singleBucketIntoSingleImmutableMonmorphicInvocation avgt 5 6.571 ± 0.043 ns/op
singleBucketIntoSingleMutableBimorphicInvocation avgt 5 7.714 ± 0.010 ns/op
singleBucketIntoSingleMutableMonmorphicInvocation avgt 5 7.459 ± 0.017 ns/op
```
While I was touching the JMH benchmarks for `LongKeyedBucketOrds` I took
the opportunity to try and make the runs that collect from a single
bucket more comparable to the ones that collect from many buckets. It
only seemed fair.1 parent 5f676ec commit 9545daf
File tree
6 files changed
+391
-80
lines changed- benchmarks/src/main/java/org/elasticsearch/benchmark/search/aggregations/bucket/terms
- server/src
- internalClusterTest/java/org/elasticsearch/search/profile/aggregation
- main/java/org/elasticsearch/search/aggregations/bucket/terms
- test/java/org/elasticsearch/search/aggregations/bucket/terms
6 files changed
+391
-80
lines changedLines changed: 72 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| 70 | + | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
| |||
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| |||
83 | 91 | | |
84 | 92 | | |
85 | 93 | | |
86 | | - | |
| 94 | + | |
87 | 95 | | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
91 | 102 | | |
92 | 103 | | |
93 | 104 | | |
| |||
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
109 | 124 | | |
110 | 125 | | |
111 | 126 | | |
| |||
116 | 131 | | |
117 | 132 | | |
118 | 133 | | |
119 | | - | |
| 134 | + | |
120 | 135 | | |
121 | 136 | | |
122 | 137 | | |
| |||
125 | 140 | | |
126 | 141 | | |
127 | 142 | | |
128 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
| |||
134 | 151 | | |
135 | 152 | | |
136 | 153 | | |
137 | | - | |
| 154 | + | |
| 155 | + | |
138 | 156 | | |
139 | 157 | | |
140 | 158 | | |
141 | 159 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 160 | + | |
145 | 161 | | |
146 | 162 | | |
147 | 163 | | |
148 | 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 | + | |
149 | 199 | | |
150 | 200 | | |
151 | 201 | | |
152 | 202 | | |
153 | | - | |
| 203 | + | |
154 | 204 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 205 | + | |
159 | 206 | | |
160 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
161 | 218 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
472 | | - | |
| 472 | + | |
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| |||
0 commit comments