Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 39F28200BC1 for ; Wed, 2 Nov 2016 06:28:42 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 38758160B0A; Wed, 2 Nov 2016 05:28:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 57EF3160B02 for ; Wed, 2 Nov 2016 06:28:41 +0100 (CET) Received: (qmail 30272 invoked by uid 500); 2 Nov 2016 05:28:40 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 30250 invoked by uid 99); 2 Nov 2016 05:28:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Nov 2016 05:28:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1154FE07EF; Wed, 2 Nov 2016 05:28:40 +0000 (UTC) From: sudheeshkatkam To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #639: DRILL-4706: Fragment planning causes Drillbits to r... Content-Type: text/plain Message-Id: <20161102052840.1154FE07EF@git1-us-west.apache.org> Date: Wed, 2 Nov 2016 05:28:40 +0000 (UTC) archived-at: Wed, 02 Nov 2016 05:28:42 -0000 Github user sudheeshkatkam commented on a diff in the pull request: https://github.com/apache/drill/pull/639#discussion_r86073971 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/LocalAffinityFragmentParallelizer.java --- @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.planner.fragment; + +import com.google.common.collect.Lists; +import org.apache.drill.exec.physical.EndpointAffinity; +import org.apache.drill.exec.physical.PhysicalOperatorSetupException; +import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; + +import java.util.Map; +import java.util.List; +import java.util.Collection; +import java.util.HashMap; + + +/** + * Implementation of {@link FragmentParallelizer} where fragment has zero or more endpoints. + * This is for Parquet Scan Fragments only. Fragment placement is done preferring strict + * data locality. + */ +public class LocalAffinityFragmentParallelizer implements FragmentParallelizer { + public static final LocalAffinityFragmentParallelizer INSTANCE = new LocalAffinityFragmentParallelizer(); + + @Override + public void parallelizeFragment(final Wrapper fragmentWrapper, final ParallelizationParameters parameters, final Collection activeEndpoints) throws PhysicalOperatorSetupException { + + // Find the parallelization width of fragment + final Stats stats = fragmentWrapper.getStats(); + final ParallelizationInfo parallelizationInfo = stats.getParallelizationInfo(); + + // 1. Find the parallelization based on cost. Use max cost of all operators in this fragment; this is consistent + // with the calculation that ExcessiveExchangeRemover uses. + int width = (int) Math.ceil(stats.getMaxCost() / parameters.getSliceTarget()); + + // 2. Cap the parallelization width by fragment level width limit and system level per query width limit + width = Math.min(width, Math.min(parallelizationInfo.getMaxWidth(), parameters.getMaxGlobalWidth())); + + // 3. Cap the parallelization width by system level per node width limit + width = Math.min(width, parameters.getMaxWidthPerNode() * activeEndpoints.size()); + + // 4. Make sure width is at least the min width enforced by operators + width = Math.max(parallelizationInfo.getMinWidth(), width); + + // 5. Make sure width is at most the max width enforced by operators + width = Math.min(parallelizationInfo.getMaxWidth(), width); + + // 6: Finally make sure the width is at least one + width = Math.max(1, width); + + List endpointPool = Lists.newArrayList(); + List assignedEndPoints = Lists.newArrayList(); + + Map endpointAffinityMap = + fragmentWrapper.getStats().getParallelizationInfo().getEndpointAffinityMap(); + + int totalAssigned = 0; + int totalWorkUnits = 0; + + // Get the total number of work units and list of endPoints to schedule fragments on + for (Map.Entry epAff : endpointAffinityMap.entrySet()) { + if (epAff.getValue().getNumLocalWorkUnits() > 0) { + totalWorkUnits += epAff.getValue().getNumLocalWorkUnits(); + endpointPool.add(epAff.getKey()); + } + } + + // Keep track of number of fragments allocated to each endpoint. + Map endpointAssignments = new HashMap<>(); + + // Keep track of how many more to assign to each endpoint. + Map remainingEndpointAssignments = new HashMap<>(); + + // Calculate the target allocation for each endPoint based on work it has to do + // Assign one fragment (minimum) to all the endPoints in the pool. + for (DrillbitEndpoint ep : endpointPool) { + int targetAllocation = (int) Math.ceil(endpointAffinityMap.get(ep).getNumLocalWorkUnits() * width / parallelizationInfo.getMaxWidth()); + assignedEndPoints.add(ep); + totalAssigned++; + remainingEndpointAssignments.put(ep, targetAllocation-1); + endpointAssignments.put(ep, 1); + } + + // Keep allocating from endpoints in a round robin fashion upto + // max(targetAllocation, maxwidthPerNode) for each endpoint and + // upto width for all together. + while(totalAssigned < width) { + int assignedThisRound = 0; + for (DrillbitEndpoint ep : endpointPool) { + if (remainingEndpointAssignments.get(ep) > 0 && --- End diff -- get value once into local var (and reuse) --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---