forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CachingCostBalancerStrategy #61
Closed
Closed
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
69d0bbb
Add CachingCostBalancerStrategy
dgolitsyn 108f12a
Fail fast if serverInventoryView is null in CachingCostBalancerStrate…
dgolitsyn fe80785
Fix races in CachingCostBalancerStrategyFactory
dgolitsyn 7a86471
Fix CachingCostBalancerStrategyBenchmark
dgolitsyn 30e6c76
Benchmark fixes
leventov c58ae94
Address review comments
dgolitsyn 2dba9ca
LifecycleLock in CachingCostBalancerStrategyFactory
dgolitsyn 231b232
Fix typo
dgolitsyn 73a716e
Address review comments
dgolitsyn 3bc9376
Rename ServerView.ServerCallback to ServerRemovedCallback for readabi…
leventov eeb7b6c
Use LifecycleLock in CachingCostBalancerStrategyFactory
dgolitsyn 5975448
Use DurationGranularity in SegmentCostCache
dgolitsyn 3f524d1
Add test for CachingCostBalancerStrategy
dgolitsyn 034c56a
Added docs to SegmentsCostCache
dgolitsyn 43ce54b
Include segments that are going to be loaded to total cost in Caching…
dgolitsyn 342a67b
Some refactoring and style
leventov cd27ca4
Typo
leventov 23fa1e8
ValueAndSegment -> SegmentAndValue
leventov 8dfb995
Add docs to SegmentsCostCache and rename SegmentAndValue to SegmentAn…
dgolitsyn 250a7b7
Reduce bucketInterval in SegmentsCostCache from 30 to 15
dgolitsyn 5cdb422
Fix CachingCostBalancerStrategyBenchmark
dgolitsyn 843c462
Add link to plotter
leventov cae5e83
Merge branch '0.10.1-mmx' into caching-cost-balancer
leventov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...marks/src/main/java/io/druid/server/coordinator/CachingCostBalancerStrategyBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.server.coordinator; | ||
|
||
import io.druid.server.coordinator.cost.SegmentsCostCache; | ||
import io.druid.timeline.DataSegment; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.Interval; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@Fork(1) | ||
public class CachingCostBalancerStrategyBenchmark | ||
{ | ||
private static final int NUMBER_OF_SEGMENTS = 100000; | ||
private static final int NUMBER_OF_QUERIES = 500; | ||
|
||
private static final long DAYS_IN_MONTH = 30; | ||
|
||
private final DateTime referenceTime = new DateTime("2014-01-01T00:00:00"); | ||
private final List<DataSegment> segments = new ArrayList<>(); | ||
private final List<DataSegment> segmentQueries = new ArrayList<>(); | ||
private final int seed = ThreadLocalRandom.current().nextInt(); | ||
|
||
private SegmentsCostCache segmentsCostCache; | ||
|
||
@Setup | ||
public void createSegments() | ||
{ | ||
Random random = new Random(seed); | ||
SegmentsCostCache.Builder prototype = SegmentsCostCache.builder(); | ||
for (int i = 0; i < NUMBER_OF_SEGMENTS; ++i) { | ||
DataSegment segment = createSegment(random.nextInt((int)TimeUnit.DAYS.toHours(DAYS_IN_MONTH))); | ||
segments.add(segment); | ||
prototype.addSegment(segment); | ||
} | ||
segmentsCostCache = prototype.build(); | ||
for (int i = 0; i < NUMBER_OF_QUERIES; ++i) { | ||
DataSegment segment = createSegment(random.nextInt((int)TimeUnit.DAYS.toHours(DAYS_IN_MONTH))); | ||
segmentQueries.add(segment); | ||
} | ||
|
||
System.out.println("GENERATING SEGMENTS : " + NUMBER_OF_SEGMENTS + " / " + NUMBER_OF_QUERIES); | ||
} | ||
|
||
@Benchmark | ||
public double measureCostStrategy() throws InterruptedException | ||
{ | ||
double cost = 0.0; | ||
for (DataSegment segment : segmentQueries) { | ||
cost += CostBalancerStrategy.computeJointSegmentsCost(segment, segments); | ||
} | ||
return cost; | ||
} | ||
|
||
@Benchmark | ||
public double measureCachingCostStrategy() throws InterruptedException | ||
{ | ||
double cost = 0.0; | ||
for (DataSegment segment : segmentQueries) { | ||
cost += segmentsCostCache.cost(segment); | ||
} | ||
return cost; | ||
} | ||
|
||
private DataSegment createSegment(int shift) | ||
{ | ||
return new DataSegment( | ||
"dataSource", | ||
new Interval(referenceTime.plusHours(shift), referenceTime.plusHours(shift).plusHours(1)), | ||
"version", | ||
Collections.<String, Object>emptyMap(), | ||
Collections.<String>emptyList(), | ||
Collections.<String>emptyList(), | ||
null, | ||
0, | ||
100 | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
server/src/main/java/io/druid/server/coordinator/CachingCostBalancerStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.server.coordinator; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.util.concurrent.ListeningExecutorService; | ||
import io.druid.server.coordinator.cost.ClusterCostCache; | ||
import io.druid.timeline.DataSegment; | ||
|
||
import java.util.Set; | ||
|
||
|
||
public class CachingCostBalancerStrategy extends CostBalancerStrategy | ||
{ | ||
|
||
private final ClusterCostCache clusterCostCache; | ||
|
||
public CachingCostBalancerStrategy(ClusterCostCache clusterCostCache, ListeningExecutorService exec) | ||
{ | ||
super(exec); | ||
this.clusterCostCache = Preconditions.checkNotNull(clusterCostCache); | ||
} | ||
|
||
@Override | ||
protected double computeCost( | ||
DataSegment proposalSegment, ServerHolder server, boolean includeCurrentServer | ||
) | ||
{ | ||
final long proposalSegmentSize = proposalSegment.getSize(); | ||
|
||
// (optional) Don't include server if it is already serving segment | ||
if (!includeCurrentServer && server.isServingSegment(proposalSegment)) { | ||
return Double.POSITIVE_INFINITY; | ||
} | ||
|
||
// Don't calculate cost if the server doesn't have enough space or is loading the segment | ||
if (proposalSegmentSize > server.getAvailableSize() || server.isLoadingSegment(proposalSegment)) { | ||
return Double.POSITIVE_INFINITY; | ||
} | ||
|
||
final String serverName = server.getServer().getName(); | ||
|
||
double cost = clusterCostCache.computeCost(serverName, proposalSegment); | ||
|
||
// add segments that will be loaded to the cost | ||
cost += costCacheForLoadingSegments(server).computeCost(serverName, proposalSegment); | ||
|
||
return cost; | ||
} | ||
|
||
private ClusterCostCache costCacheForLoadingSegments(ServerHolder server) | ||
{ | ||
final Set<DataSegment> loadingSegments = server.getPeon().getSegmentsToLoad(); | ||
return ClusterCostCache.builder(ImmutableMap.of(server.getServer().getName(), loadingSegments)).build(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CachingCostBalancerStrategy
is the same algorithm asCostBalancerStrategy
, so I suggest just to "add caching" to "CostBalancerStrategy", not introduce another configuration option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only reason to introduce another configuration option is that
CachingCostBalancerStrategy
has bigger memory footprint thatCostBalancerStrategy
. Not sure that all users are ok with such changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much extra memory it would take on coordinator in our prod cluster?