|
9 | 9 |
|
10 | 10 | package org.elasticsearch.common.util.concurrent; |
11 | 11 |
|
12 | | -import org.elasticsearch.common.metrics.ExponentialBucketHistogram; |
13 | 12 | import org.elasticsearch.common.settings.Settings; |
14 | 13 | import org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig; |
15 | | -import org.elasticsearch.telemetry.InstrumentType; |
16 | | -import org.elasticsearch.telemetry.Measurement; |
17 | | -import org.elasticsearch.telemetry.RecordingMeterRegistry; |
18 | 14 | import org.elasticsearch.test.ESTestCase; |
19 | | -import org.elasticsearch.threadpool.ThreadPool; |
20 | 15 |
|
21 | | -import java.util.List; |
22 | 16 | import java.util.concurrent.CountDownLatch; |
23 | | -import java.util.concurrent.CyclicBarrier; |
24 | | -import java.util.concurrent.Future; |
25 | 17 | import java.util.concurrent.TimeUnit; |
26 | 18 | import java.util.function.Function; |
27 | 19 |
|
28 | 20 | import static org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig.DEFAULT_EWMA_ALPHA; |
29 | 21 | import static org.hamcrest.Matchers.equalTo; |
30 | 22 | import static org.hamcrest.Matchers.greaterThan; |
31 | 23 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
32 | | -import static org.hamcrest.Matchers.hasSize; |
33 | 24 |
|
34 | 25 | /** |
35 | 26 | * Tests for the automatic queue resizing of the {@code QueueResizingEsThreadPoolExecutorTests} |
@@ -156,83 +147,6 @@ public void testGetOngoingTasks() throws Exception { |
156 | 147 | executor.awaitTermination(10, TimeUnit.SECONDS); |
157 | 148 | } |
158 | 149 |
|
159 | | - public void testQueueLatencyMetrics() { |
160 | | - RecordingMeterRegistry meterRegistry = new RecordingMeterRegistry(); |
161 | | - final var threadPoolName = randomIdentifier(); |
162 | | - var executor = new TaskExecutionTimeTrackingEsThreadPoolExecutor( |
163 | | - threadPoolName, |
164 | | - 1, |
165 | | - 1, |
166 | | - 1000, |
167 | | - TimeUnit.MILLISECONDS, |
168 | | - ConcurrentCollections.newBlockingQueue(), |
169 | | - TimedRunnable::new, |
170 | | - EsExecutors.daemonThreadFactory("queuetest"), |
171 | | - new EsAbortPolicy(), |
172 | | - new ThreadContext(Settings.EMPTY), |
173 | | - new TaskTrackingConfig(true, DEFAULT_EWMA_ALPHA) |
174 | | - ); |
175 | | - executor.setupMetrics(meterRegistry, threadPoolName); |
176 | | - |
177 | | - try { |
178 | | - final var barrier = new CyclicBarrier(2); |
179 | | - final ExponentialBucketHistogram expectedHistogram = new ExponentialBucketHistogram(); |
180 | | - |
181 | | - /* |
182 | | - * The thread pool has a single thread, so we submit a task that will occupy that thread |
183 | | - * and cause subsequent tasks to be queued |
184 | | - */ |
185 | | - Future<?> runningTask = executor.submit(() -> { |
186 | | - safeAwait(barrier); |
187 | | - safeAwait(barrier); |
188 | | - }); |
189 | | - safeAwait(barrier); // wait till the first task starts |
190 | | - expectedHistogram.addObservation(0L); // the first task should not be delayed |
191 | | - |
192 | | - /* |
193 | | - * On each iteration we submit a task - which will be queued because of the |
194 | | - * currently running task, pause for some random interval, then unblock the |
195 | | - * new task by releasing the currently running task. This gives us a lower |
196 | | - * bound for the real delays (the real delays will be greater than or equal |
197 | | - * to the synthetic delays we add, i.e. each percentile should be >= our |
198 | | - * expected values) |
199 | | - */ |
200 | | - for (int i = 0; i < 10; i++) { |
201 | | - Future<?> waitingTask = executor.submit(() -> { |
202 | | - safeAwait(barrier); |
203 | | - safeAwait(barrier); |
204 | | - }); |
205 | | - final long delayTimeMs = randomLongBetween(1, 50); |
206 | | - safeSleep(delayTimeMs); |
207 | | - safeAwait(barrier); // let the running task complete |
208 | | - safeAwait(barrier); // wait for the next task to start |
209 | | - safeGet(runningTask); // ensure previous task is complete |
210 | | - expectedHistogram.addObservation(delayTimeMs); |
211 | | - runningTask = waitingTask; |
212 | | - } |
213 | | - safeAwait(barrier); // let the last task finish |
214 | | - safeGet(runningTask); |
215 | | - meterRegistry.getRecorder().collect(); |
216 | | - |
217 | | - List<Measurement> measurements = meterRegistry.getRecorder() |
218 | | - .getMeasurements( |
219 | | - InstrumentType.LONG_GAUGE, |
220 | | - ThreadPool.THREAD_POOL_METRIC_PREFIX + threadPoolName + ThreadPool.THREAD_POOL_METRIC_NAME_QUEUE_TIME |
221 | | - ); |
222 | | - assertThat(measurements, hasSize(3)); |
223 | | - // we have to use greater than or equal to because the actual delay might be higher than what we imposed |
224 | | - assertThat(getPercentile(measurements, "99"), greaterThanOrEqualTo(expectedHistogram.getPercentile(0.99f))); |
225 | | - assertThat(getPercentile(measurements, "90"), greaterThanOrEqualTo(expectedHistogram.getPercentile(0.9f))); |
226 | | - assertThat(getPercentile(measurements, "50"), greaterThanOrEqualTo(expectedHistogram.getPercentile(0.5f))); |
227 | | - } finally { |
228 | | - ThreadPool.terminate(executor, 10, TimeUnit.SECONDS); |
229 | | - } |
230 | | - } |
231 | | - |
232 | | - private long getPercentile(List<Measurement> measurements, String percentile) { |
233 | | - return measurements.stream().filter(m -> m.attributes().get("percentile").equals(percentile)).findFirst().orElseThrow().getLong(); |
234 | | - } |
235 | | - |
236 | 150 | /** |
237 | 151 | * The returned function outputs a WrappedRunnabled that simulates the case |
238 | 152 | * where {@link TimedRunnable#getTotalExecutionNanos()} always returns {@code timeTakenNanos}. |
|
0 commit comments