-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Optimize CostBalancerStrategy #2910
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,13 +698,21 @@ public void run() | |
.withEmitter(emitter) | ||
.withBalancerStrategyFactory(factory) | ||
.build(); | ||
|
||
for (DruidCoordinatorHelper helper : helpers) { | ||
// Don't read state and run state in the same helper otherwise racy conditions may exist | ||
if (leader && startingLeaderCounter == leaderCounter) { | ||
params = helper.run(params); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might want to use try with resources with the factory, just in case an exception is thrown earlier. This will also close the factory automatically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
for (DruidCoordinatorHelper helper : helpers) { | ||
// Don't read state and run state in the same helper otherwise racy conditions may exist | ||
if (leader && startingLeaderCounter == leaderCounter) { | ||
params = helper.run(params); | ||
} | ||
} | ||
} | ||
finally { | ||
if (params.getBalancerStrategyFactory() != null) { | ||
params.getBalancerStrategyFactory().close(); | ||
} | ||
} | ||
|
||
|
||
} | ||
catch (Exception e) { | ||
log.makeAlert(e, "Caught exception, ignoring so that schedule keeps going.").emit(); | ||
|
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; | ||
} | ||
|
||
} |
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.
Why not directly make this one a
ListeningExecutorService
?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.
done.