forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize CostBalancerStrategy (apache#2910)
* Optimize CostBalancerStrategy Ignore benchmark test in normal run fix test review comments fix compilation fix test * review comments * review comment
- Loading branch information
1 parent
b489f63
commit a2dd57c
Showing
11 changed files
with
272 additions
and
91 deletions.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
server/src/test/java/io/druid/server/coordination/CostBalancerStrategyBenchmark.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.coordination; | ||
|
||
import com.carrotsearch.junitbenchmarks.AbstractBenchmark; | ||
import com.carrotsearch.junitbenchmarks.BenchmarkOptions; | ||
import io.druid.server.coordinator.CostBalancerStrategy; | ||
import io.druid.server.coordinator.CostBalancerStrategyFactory; | ||
import io.druid.server.coordinator.ServerHolder; | ||
import io.druid.timeline.DataSegment; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.Interval; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Ignore | ||
@RunWith(Parameterized.class) | ||
public class CostBalancerStrategyBenchmark extends AbstractBenchmark | ||
{ | ||
@Parameterized.Parameters | ||
public static List<CostBalancerStrategyFactory[]> factoryClasses() | ||
{ | ||
return Arrays.asList( | ||
(CostBalancerStrategyFactory[]) Arrays.asList( | ||
new CostBalancerStrategyFactory(1) | ||
).toArray(), | ||
(CostBalancerStrategyFactory[]) Arrays.asList( | ||
new CostBalancerStrategyFactory(4) | ||
).toArray() | ||
); | ||
} | ||
|
||
private final CostBalancerStrategy strategy; | ||
|
||
public CostBalancerStrategyBenchmark(CostBalancerStrategyFactory factory) | ||
{ | ||
this.strategy = (CostBalancerStrategy) factory.createBalancerStrategy(DateTime.now()); | ||
} | ||
|
||
private static List<ServerHolder> serverHolderList; | ||
volatile ServerHolder selected; | ||
|
||
@BeforeClass | ||
public static void setup() | ||
{ | ||
serverHolderList = CostBalancerStrategyTest.setupDummyCluster(5, 20000); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown(){ | ||
serverHolderList = null; | ||
} | ||
|
||
@Test | ||
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000) | ||
public void testBenchmark() throws InterruptedException | ||
{ | ||
DataSegment segment = CostBalancerStrategyTest.getSegment(1000, "testds", interval1); | ||
selected = strategy.findNewSegmentHomeReplicator(segment, serverHolderList); | ||
} | ||
|
||
|
||
// Benchmark Joda Interval Gap impl vs CostBalancer.gapMillis | ||
private final Interval interval1 = new Interval("2015-01-01T01:00:00Z/2015-01-01T02:00:00Z"); | ||
private final Interval interval2 = new Interval("2015-02-01T01:00:00Z/2015-02-01T02:00:00Z"); | ||
volatile Long sum; | ||
|
||
@BenchmarkOptions(warmupRounds = 1000, benchmarkRounds = 1000000) | ||
@Test | ||
public void testJodaGap() | ||
{ | ||
long diff = 0; | ||
for (int i = 0; i < 1000; i++) { | ||
diff = diff + interval1.gap(interval2).toDurationMillis(); | ||
} | ||
sum = diff; | ||
} | ||
|
||
@BenchmarkOptions(warmupRounds = 1000, benchmarkRounds = 1000000) | ||
@Test | ||
public void testBalancerGapMillis() | ||
{ | ||
long diff = 0; | ||
for (int i = 0; i < 1000; i++) { | ||
diff = diff + CostBalancerStrategy.gapMillis(interval1, interval2); | ||
} | ||
sum = diff; | ||
} | ||
|
||
} |
Oops, something went wrong.