-
Notifications
You must be signed in to change notification settings - Fork 61
[COST] add MigrateTimeCost
#1665
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
Open
qoo332001
wants to merge
38
commits into
opensource4you:main
Choose a base branch
from
qoo332001:addPartitionMigrateTimeCost
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5b5d00f
add PartitionMigrateTimeCost and revise MetricSensor#fetch
qoo332001 05b838e
fix issues
qoo332001 1b1a18a
fix conflict
qoo332001 43b1a5f
fix bug
qoo332001 749b63b
fix issues
qoo332001 f39ad51
fix issues
qoo332001 262a407
update docs
qoo332001 33967dd
fix issues
qoo332001 81439fe
fix conflict
qoo332001 e4e5981
fix issue
qoo332001 0bd88b1
Merge branch 'main' of https://github.com/skiptests/astraea into addP…
qoo332001 efb3216
fix issues
qoo332001 7452921
update
qoo332001 23e7f3f
fix conflict
qoo332001 ea28b65
fix issue
qoo332001 c74cf56
fix conflict
qoo332001 1ad7892
fix issues
qoo332001 60a62be
Merge branch 'main' of https://github.com/skiptests/astraea into addP…
qoo332001 e4ac803
update docs
qoo332001 311a48e
fix conflict
qoo332001 f4e1297
fix issues
1eca3ea
Merge branch 'main' of github.com:skiptests/astraea into addPartition…
9257e72
move brokerMaxRate() to MigrationCost
c27fe29
fix conflict
qoo332001 6df0a15
fix conflict
qoo332001 848f4e9
fix tests
qoo332001 e3dd72e
fix issue
qoo332001 38031ee
Merge branch 'main' of https://github.com/skiptests/astraea into addP…
qoo332001 dbae033
merge main
qoo332001 ebbc82b
remove reduant code
qoo332001 85ce98d
fix bugs
qoo332001 00a6fc7
fix bugs
qoo332001 5298769
fix issues
qoo332001 3731482
fix bugs
qoo332001 c04bdb8
fix conflict
qoo332001 a7e2515
Merge branch 'main' of https://github.com/skiptests/astraea into addP…
qoo332001 3e006c6
fix bug and merge main
qoo332001 bd59c89
fix issue
qoo332001 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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
109 changes: 109 additions & 0 deletions
109
common/src/main/java/org/astraea/common/cost/PartitionMigrateTimeCost.java
This file contains hidden or 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,109 @@ | ||
| /* | ||
| * 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.astraea.common.cost; | ||
|
|
||
| import static org.astraea.common.cost.MigrationCost.brokerMaxRate; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import org.astraea.common.Configuration; | ||
| import org.astraea.common.admin.ClusterInfo; | ||
| import org.astraea.common.metrics.BeanObject; | ||
| import org.astraea.common.metrics.ClusterBean; | ||
| import org.astraea.common.metrics.Sensor; | ||
| import org.astraea.common.metrics.broker.HasMaxRate; | ||
| import org.astraea.common.metrics.broker.ServerMetrics; | ||
| import org.astraea.common.metrics.collector.MetricSensor; | ||
| import org.astraea.common.metrics.stats.Max; | ||
|
|
||
| /** MoveCost: more max write rate change -> higher migrate cost. */ | ||
| public class PartitionMigrateTimeCost implements HasMoveCost { | ||
| private static final String REPLICATION_IN_RATE = "replication_in_rate"; | ||
| private static final String REPLICATION_OUT_RATE = "replication_out_rate"; | ||
| static final String MAX_MIGRATE_TIME_KEY = "max.migrated.time.limit"; | ||
| public static final String STATISTICS_RATE_KEY = "statistics.rate.key"; | ||
qoo332001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // metrics windows size | ||
| private final Duration maxMigrateTime; | ||
|
|
||
| public PartitionMigrateTimeCost(Configuration config) { | ||
| this.maxMigrateTime = | ||
| config.duration(MAX_MIGRATE_TIME_KEY).orElse(Duration.ofSeconds(Long.MAX_VALUE)); | ||
| } | ||
|
|
||
| @Override | ||
| public MetricSensor metricSensor() { | ||
| return (client, clusterBean) -> { | ||
| var oldInRate = | ||
| brokerMaxRate( | ||
| client.identity(), | ||
| clusterBean, | ||
| PartitionMigrateTimeCost.MaxReplicationInRateBean.class); | ||
| var oldOutRate = | ||
| brokerMaxRate( | ||
| client.identity(), | ||
| clusterBean, | ||
| PartitionMigrateTimeCost.MaxReplicationOutRateBean.class); | ||
| var newInMetrics = ServerMetrics.BrokerTopic.REPLICATION_BYTES_IN_PER_SEC.fetch(client); | ||
| var newOutMetrics = ServerMetrics.BrokerTopic.REPLICATION_BYTES_OUT_PER_SEC.fetch(client); | ||
| var current = Duration.ofMillis(System.currentTimeMillis()); | ||
| var maxRateSensor = | ||
| Sensor.builder() | ||
| .addStats( | ||
| Map.of( | ||
| REPLICATION_IN_RATE, Max.<Double>of(), | ||
| REPLICATION_OUT_RATE, Max.of())) | ||
| .build(); | ||
| maxRateSensor.record(REPLICATION_IN_RATE, newInMetrics.oneMinuteRate()); | ||
qoo332001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| maxRateSensor.record(REPLICATION_OUT_RATE, newOutMetrics.oneMinuteRate()); | ||
| var inRate = maxRateSensor.measure(REPLICATION_IN_RATE); | ||
| var outRate = maxRateSensor.measure(REPLICATION_OUT_RATE); | ||
| return List.of( | ||
| (MaxReplicationInRateBean) | ||
| () -> | ||
| new BeanObject( | ||
| newInMetrics.beanObject().domainName(), | ||
| newInMetrics.beanObject().properties(), | ||
| Map.of(STATISTICS_RATE_KEY, Math.max(oldInRate.orElse(0), inRate)), | ||
| current.toMillis()), | ||
| (MaxReplicationOutRateBean) | ||
| () -> | ||
| new BeanObject( | ||
| newOutMetrics.beanObject().domainName(), | ||
| newOutMetrics.beanObject().properties(), | ||
| Map.of(STATISTICS_RATE_KEY, Math.max(oldOutRate.orElse(0), outRate)), | ||
| current.toMillis())); | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public MoveCost moveCost(ClusterInfo before, ClusterInfo after, ClusterBean clusterBean) { | ||
| var brokerMigrateSecond = MigrationCost.brokerMigrationSecond(before, after, clusterBean); | ||
| var planMigrateSecond = | ||
| brokerMigrateSecond.values().stream() | ||
| .max(Comparator.comparing(Function.identity())) | ||
| .orElse(Long.MAX_VALUE); | ||
| return () -> planMigrateSecond > this.maxMigrateTime.getSeconds(); | ||
| } | ||
|
|
||
| public interface MaxReplicationInRateBean extends HasMaxRate {} | ||
qoo332001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public interface MaxReplicationOutRateBean extends HasMaxRate {} | ||
qoo332001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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
25 changes: 25 additions & 0 deletions
25
common/src/main/java/org/astraea/common/metrics/broker/HasMaxRate.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * 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.astraea.common.metrics.broker; | ||
|
|
||
| import org.astraea.common.metrics.HasBeanObject; | ||
|
|
||
| public interface HasMaxRate extends HasBeanObject { | ||
| default double maxRate() { | ||
| return (double) beanObject().attributes().get("statistics.rate.key"); | ||
| } | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.