drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From laurentgo <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-4446: Support mandatory work assignment ...
Date Thu, 03 Mar 2016 02:41:12 GMT
Github user laurentgo commented on a diff in the pull request:

    https://github.com/apache/drill/pull/403#discussion_r54829264
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/HardAffinityFragmentParallelizer.java
---
    @@ -0,0 +1,119 @@
    +/**
    + * 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
    + * <p/>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p/>
    + * 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 com.google.common.collect.Maps;
    +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.Collection;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +
    +/**
    + * Implementation of {@link FragmentParallelizer} where fragment requires running on
a given set of endpoints. Width
    + * per node is depended on the affinity to the endpoint and total width (calculated using
costs)
    + */
    +public class HardAffinityFragmentParallelizer implements FragmentParallelizer {
    +  public static final HardAffinityFragmentParallelizer INSTANCE = new HardAffinityFragmentParallelizer();
    +
    +  private HardAffinityFragmentParallelizer() { /* singleton */}
    +
    +  @Override
    +  public void parallelizeFragment(final Wrapper fragmentWrapper, final ParallelizationParameters
parameters,
    +      final Collection<DrillbitEndpoint> activeEndpoints) throws PhysicalOperatorSetupException
{
    +
    +    final Stats stats = fragmentWrapper.getStats();
    +    final ParallelizationInfo pInfo = stats.getParallelizationInfo();
    +
    +    // Go through the affinity map and extract the endpoints that have mandatory assignment
requirement
    +    final Map<DrillbitEndpoint, EndpointAffinity> endpointPool = Maps.newHashMap();
    +    for(Entry<DrillbitEndpoint, EndpointAffinity> entry : pInfo.getEndpointAffinityMap().entrySet())
{
    +      if (entry.getValue().isAssignmentRequired()) {
    +        endpointPool.put(entry.getKey(), entry.getValue());
    +      }
    +    }
    +
    +    // Step 1: Find the width taking into various parameters
    +    // 1.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.getParallelizationThreshold());
    +
    +    // 1.2. Make sure the width is at least the number of endpoints that require an assignment
    +    width = Math.max(endpointPool.size(), width);
    +
    +    // 1.3. Cap the parallelization width by fragment level width limit and system level
per query width limit
    +    width = Math.max(1, Math.min(width, pInfo.getMaxWidth()));
    +    checkAndThrow(endpointPool.size() <= width,
    +        "Number of mandatory endpoints that require an assignment is more than the allowed
fragment max width.");
    +
    +    width = Math.max(1, Math.min(width, parameters.getMaxGlobalWidth()));
    +    checkAndThrow(endpointPool.size() <= width,
    +        "Number of mandatory endpoints that require an assignment is more than the allowed
global query width.");
    +
    +    // Step 2: Select the endpoints
    +    final Map<DrillbitEndpoint, Integer> endpoints = Maps.newHashMap();
    +
    +    // 2.1 First add each endpoint from the pool once so that the mandatory assignment
requirement is fulfilled.
    +    int totalAssigned;
    +    for(Entry<DrillbitEndpoint, EndpointAffinity> entry : endpointPool.entrySet())
{
    +      endpoints.put(entry.getKey(), 1);
    +    }
    +    totalAssigned = endpoints.size();
    +
    +    // 2.2 Assign the remaining slots to endpoints proportional to the affinity of each
endpoint
    +    int remainingSlots = width - endpoints.size();
    +    while (remainingSlots > 0) {
    +      for(EndpointAffinity epAf : endpointPool.values()) {
    +        final int moreAllocation = (int) Math.round(epAf.getAffinity() * remainingSlots);
    +        int currentAssignments = endpoints.get(epAf.getEndpoint());
    +        for(int i=0;
    +            i < moreAllocation &&  totalAssigned < width && currentAssignments
< parameters.getMaxWidthPerNode();
    +            i++) {
    +          totalAssigned++;
    +          currentAssignments++;
    +        }
    +        endpoints.put(epAf.getEndpoint(), currentAssignments);
    +      }
    +      final int previousRemainingSlots = remainingSlots;
    +      remainingSlots = width - totalAssigned;
    +      if (previousRemainingSlots == remainingSlots) {
    +        throw new PhysicalOperatorSetupException("Every mandatory node has exhausted
the maximum width per node limit.");
    +      }
    +    }
    +
    +    final List<DrillbitEndpoint> assignedEndpoints = Lists.newArrayList();
    +    for(Entry<DrillbitEndpoint, Integer> entry : endpoints.entrySet()) {
    +      for(int i=0; i < entry.getValue(); i++) {
    +        assignedEndpoints.add(entry.getKey());
    +      }
    +    }
    +
    +    fragmentWrapper.setWidth(width);
    +    fragmentWrapper.assignEndpoints(assignedEndpoints);
    +  }
    +
    +  private void checkAndThrow(boolean expr, String errMsg) throws PhysicalOperatorSetupException
{
    --- End diff --
    
    can be static


---
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.
---

Mime
View raw message