forked from apache/doris
-
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.
[Refactor](StmtExecutor)(step-1) Extract profile logic from StmtExecu…
…tor and Coordinator (apache#19219) Previously, we use RuntimeProfile class directly, and because there are multiple level in profile, so you can see there may be several RuntimeProfile instances be to maintain. I created several new classes for profile: class Profile: The root profile of a execution task(query or load) class SummaryProfile: The profile that contains summary info of a execution task, such as start time, end time, query id. etc. class ExecutionProfile: The profile for a single Coordinator. Each Coordinator will have a ExecutionProfile. The profile structure is as following: Profile: SummaryProfile: ExecutionProfile 1: Fragment 0: Instance 0: Instance 1: ... Fragment 1: ... ExecutionProfile 2: ... You can see, each Profile has a SummaryProfile and one or more ExecutionProfile. For most kinds of job, such as query/insert, there is only one ExecutionProfile. But for broker load job, will may be more than one ExecutionProfile, corresponding to each sub task of the load job. How to use For query/insert, etc: Each StmtExcutor will have a Profile instance. Each Coordinator will have a ExecutionProfile instance. StmtExcutor is responsible for the SummaryProfile, it will update the SummaryProfile during the execution. Coordinator is responsible for the ExecutionProfile, it will first add ExecutionProfile to the child of Profile, and update the ExecutionProfile periodically during the execution. For Load/Export, etc: Each job will hava a Profile instance. For each Coordinator of this job, add its ExecutionProfile to the children of job's Profile. Behavior Change The columns of show load profile/show query profile and QueryProfile Web UI has changed to: | Profile ID | Task Type | Start Time | End Time | Total | Task State | User | Default Db| Sql Statement | Is Cached | Total Instances Num | Instances Num Per BE | Parallel Fragment Exec Instance Num | Trace ID | The Query Id and Job Id is removed and using Profile ID instead. For load job, the profile id is job id, for query/insert, is query id.
- Loading branch information
1 parent
166086a
commit ae2c4af
Showing
28 changed files
with
689 additions
and
626 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
150 changes: 150 additions & 0 deletions
150
fe/fe-core/src/main/java/org/apache/doris/common/profile/ExecutionProfile.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,150 @@ | ||
// 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.apache.doris.common.profile; | ||
|
||
import org.apache.doris.common.MarkedCountDownLatch; | ||
import org.apache.doris.common.Status; | ||
import org.apache.doris.common.util.DebugUtil; | ||
import org.apache.doris.common.util.RuntimeProfile; | ||
import org.apache.doris.common.util.TimeUtils; | ||
import org.apache.doris.thrift.TUniqueId; | ||
import org.apache.doris.thrift.TUnit; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Lists; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
|
||
/** | ||
* ExecutionProfile is used to collect profile of a complete query plan(including query or load). | ||
* Need to call addToProfileAsChild() to add it to the root profile. | ||
* It has the following structure: | ||
* Execution Profile: | ||
* Fragment 0: | ||
* Instance 0: | ||
* ... | ||
* Fragment 1: | ||
* Instance 0: | ||
* ... | ||
* ... | ||
* LoadChannels: // only for load job | ||
*/ | ||
public class ExecutionProfile { | ||
private static final Logger LOG = LogManager.getLogger(ExecutionProfile.class); | ||
|
||
// The root profile of this execution task | ||
private RuntimeProfile executionProfile; | ||
// Profiles for each fragment. And the InstanceProfile is the child of fragment profile. | ||
// Which will be added to fragment profile when calling Coordinator::sendFragment() | ||
private List<RuntimeProfile> fragmentProfiles; | ||
// Profile for load channels. Only for load job. | ||
private RuntimeProfile loadChannelProfile; | ||
// A countdown latch to mark the completion of each instance. | ||
// instance id -> dummy value | ||
private MarkedCountDownLatch<TUniqueId, Long> profileDoneSignal; | ||
|
||
public ExecutionProfile(TUniqueId queryId, int fragmentNum) { | ||
executionProfile = new RuntimeProfile("Execution Profile " + DebugUtil.printId(queryId)); | ||
RuntimeProfile fragmentsProfile = new RuntimeProfile("Fragments"); | ||
executionProfile.addChild(fragmentsProfile); | ||
fragmentProfiles = Lists.newArrayList(); | ||
for (int i = 0; i < fragmentNum; i++) { | ||
fragmentProfiles.add(new RuntimeProfile("Fragment " + i)); | ||
fragmentsProfile.addChild(fragmentProfiles.get(i)); | ||
} | ||
loadChannelProfile = new RuntimeProfile("LoadChannels"); | ||
executionProfile.addChild(loadChannelProfile); | ||
} | ||
|
||
public RuntimeProfile getExecutionProfile() { | ||
return executionProfile; | ||
} | ||
|
||
public RuntimeProfile getLoadChannelProfile() { | ||
return loadChannelProfile; | ||
} | ||
|
||
public void addToProfileAsChild(RuntimeProfile rootProfile) { | ||
rootProfile.addChild(executionProfile); | ||
} | ||
|
||
public void markInstances(Set<TUniqueId> instanceIds) { | ||
profileDoneSignal = new MarkedCountDownLatch<>(instanceIds.size()); | ||
for (TUniqueId instanceId : instanceIds) { | ||
profileDoneSignal.addMark(instanceId, -1L /* value is meaningless */); | ||
} | ||
} | ||
|
||
public void update(long startTime, boolean isFinished) { | ||
if (startTime > 0) { | ||
executionProfile.getCounterTotalTime().setValue(TUnit.TIME_MS, TimeUtils.getElapsedTimeMs(startTime)); | ||
} | ||
// Wait for all backends to finish reporting when writing profile last time. | ||
if (isFinished && profileDoneSignal != null) { | ||
try { | ||
profileDoneSignal.await(2, TimeUnit.SECONDS); | ||
} catch (InterruptedException e1) { | ||
LOG.warn("signal await error", e1); | ||
} | ||
} | ||
|
||
for (RuntimeProfile fragmentProfile : fragmentProfiles) { | ||
fragmentProfile.sortChildren(); | ||
} | ||
} | ||
|
||
public void onCancel() { | ||
if (profileDoneSignal != null) { | ||
// count down to zero to notify all objects waiting for this | ||
profileDoneSignal.countDownToZero(new Status()); | ||
LOG.info("unfinished instance: {}", profileDoneSignal.getLeftMarks() | ||
.stream().map(e -> DebugUtil.printId(e.getKey())).toArray()); | ||
} | ||
} | ||
|
||
public void markOneInstanceDone(TUniqueId fragmentInstanceId) { | ||
if (profileDoneSignal != null) { | ||
profileDoneSignal.markedCountDown(fragmentInstanceId, -1L); | ||
} | ||
} | ||
|
||
public boolean awaitAllInstancesDone(long waitTimeS) throws InterruptedException { | ||
if (profileDoneSignal == null) { | ||
return true; | ||
} | ||
return profileDoneSignal.await(waitTimeS, TimeUnit.SECONDS); | ||
} | ||
|
||
public boolean isAllInstancesDone() { | ||
if (profileDoneSignal == null) { | ||
return true; | ||
} | ||
return profileDoneSignal.getCount() == 0; | ||
} | ||
|
||
public void addInstanceProfile(int instanceIdx, RuntimeProfile instanceProfile) { | ||
Preconditions.checkArgument(instanceIdx < fragmentProfiles.size(), | ||
instanceIdx + " vs. " + fragmentProfiles.size()); | ||
fragmentProfiles.get(instanceIdx).addChild(instanceProfile); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
fe/fe-core/src/main/java/org/apache/doris/common/profile/Profile.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,80 @@ | ||
// 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.apache.doris.common.profile; | ||
|
||
import org.apache.doris.common.util.ProfileManager; | ||
import org.apache.doris.common.util.RuntimeProfile; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Profile is a class to record the execution time of a query. | ||
* It has the following structure: | ||
* root profile: | ||
* // summary of this profile, such as start time, end time, query id, etc. | ||
* [SummaryProfile] | ||
* // each execution profile is a complete execution of a query, a job may contain multiple queries. | ||
* [List<ExecutionProfile>] | ||
* | ||
* SummaryProfile: | ||
* Summary: | ||
* Execution Summary: | ||
* | ||
* ExecutionProfile: | ||
* Fragment 0: | ||
* Fragment 1: | ||
* ... | ||
*/ | ||
public class Profile { | ||
private RuntimeProfile rootProfile; | ||
private SummaryProfile summaryProfile; | ||
private List<ExecutionProfile> executionProfiles = Lists.newArrayList(); | ||
private boolean isFinished; | ||
|
||
public Profile(String name, boolean isEnable) { | ||
this.rootProfile = new RuntimeProfile(name); | ||
this.summaryProfile = new SummaryProfile(rootProfile); | ||
// if disabled, just set isFinished to true, so that update() will do nothing | ||
this.isFinished = !isEnable; | ||
} | ||
|
||
public void addExecutionProfile(ExecutionProfile executionProfile) { | ||
this.executionProfiles.add(executionProfile); | ||
executionProfile.addToProfileAsChild(rootProfile); | ||
} | ||
|
||
public synchronized void update(long startTime, Map<String, String> summaryInfo, boolean isFinished) { | ||
if (this.isFinished) { | ||
return; | ||
} | ||
summaryProfile.update(summaryInfo); | ||
for (ExecutionProfile executionProfile : executionProfiles) { | ||
executionProfile.update(startTime, isFinished); | ||
} | ||
rootProfile.computeTimeInProfile(); | ||
ProfileManager.getInstance().pushProfile(rootProfile); | ||
this.isFinished = isFinished; | ||
} | ||
|
||
public SummaryProfile getSummaryProfile() { | ||
return summaryProfile; | ||
} | ||
} |
Oops, something went wrong.