Search in sources :

Example 1 with SubtaskBackPressureInfo

use of org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo in project flink by apache.

the class JobVertexBackPressureHandler method createSubtaskBackPressureInfo.

private List<SubtaskBackPressureInfo> createSubtaskBackPressureInfo(Map<Integer, ComponentMetricStore> subtaskMetricStores) {
    List<SubtaskBackPressureInfo> result = new ArrayList<>(subtaskMetricStores.size());
    for (Map.Entry<Integer, ComponentMetricStore> entry : subtaskMetricStores.entrySet()) {
        int subtaskIndex = entry.getKey();
        ComponentMetricStore subtaskMetricStore = entry.getValue();
        double backPressureRatio = getBackPressureRatio(subtaskMetricStore);
        double idleRatio = getIdleRatio(subtaskMetricStore);
        double busyRatio = getBusyRatio(subtaskMetricStore);
        result.add(new SubtaskBackPressureInfo(subtaskIndex, getBackPressureLevel(backPressureRatio), backPressureRatio, idleRatio, busyRatio));
    }
    result.sort(Comparator.comparingInt(SubtaskBackPressureInfo::getSubtask));
    return result;
}
Also used : ArrayList(java.util.ArrayList) ComponentMetricStore(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore.ComponentMetricStore) SubtaskBackPressureInfo(org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo) Map(java.util.Map)

Example 2 with SubtaskBackPressureInfo

use of org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo in project flink by apache.

the class JobVertexBackPressureHandlerTest method testGetBackPressure.

@Test
public void testGetBackPressure() throws Exception {
    final Map<String, String> pathParameters = new HashMap<>();
    pathParameters.put(JobIDPathParameter.KEY, TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE.toString());
    pathParameters.put(JobVertexIdPathParameter.KEY, TEST_JOB_VERTEX_ID.toString());
    final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new JobVertexMessageParameters(), pathParameters, Collections.emptyMap(), Collections.emptyList());
    final CompletableFuture<JobVertexBackPressureInfo> jobVertexBackPressureInfoCompletableFuture = jobVertexBackPressureHandler.handleRequest(request, restfulGateway);
    final JobVertexBackPressureInfo jobVertexBackPressureInfo = jobVertexBackPressureInfoCompletableFuture.get();
    assertThat(jobVertexBackPressureInfo.getStatus(), equalTo(VertexBackPressureStatus.OK));
    assertThat(jobVertexBackPressureInfo.getBackpressureLevel(), equalTo(HIGH));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBackPressuredRatio).collect(Collectors.toList()), contains(1.0, 0.5, 0.1));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getIdleRatio).collect(Collectors.toList()), contains(0.0, 0.1, 0.2));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBusyRatio).collect(Collectors.toList()), contains(0.0, 0.9, 0.7));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBackpressureLevel).collect(Collectors.toList()), contains(HIGH, LOW, OK));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getSubtask).collect(Collectors.toList()), contains(0, 1, 3));
}
Also used : HashMap(java.util.HashMap) JobVertexBackPressureInfo(org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) SubtaskBackPressureInfo(org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo) JobVertexMessageParameters(org.apache.flink.runtime.rest.messages.JobVertexMessageParameters) Test(org.junit.Test)

Aggregations

SubtaskBackPressureInfo (org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ComponentMetricStore (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore.ComponentMetricStore)1 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)1 JobVertexBackPressureInfo (org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo)1 JobVertexMessageParameters (org.apache.flink.runtime.rest.messages.JobVertexMessageParameters)1 Test (org.junit.Test)1