Skip to content
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

[Improve][Zeta] Add sleep for Task to reduce CPU cost #5117

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public void init() throws Exception {
}

@NonNull @Override
public ProgressState call() throws Exception {
return progress.toState();
}
public abstract ProgressState call() throws Exception;

public TaskLocation getTaskLocation() {
return this.taskLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SeaTunnelSourceCollector<T> implements Collector<T> {

private final Meter sourceReceivedQPS;

private volatile long rowCountThisPollNext;
private volatile boolean emptyThisPollNext;

public SeaTunnelSourceCollector(
Object checkpointLock,
Expand All @@ -56,7 +56,7 @@ public SeaTunnelSourceCollector(
public void collect(T row) {
try {
sendRecordToNext(new Record<>(row));
rowCountThisPollNext++;
emptyThisPollNext = false;
sourceReceivedCount.inc();
sourceReceivedQPS.markEvent();
} catch (IOException e) {
Expand All @@ -69,12 +69,12 @@ public Object getCheckpointLock() {
return checkpointLock;
}

public long getRowCountThisPollNext() {
return this.rowCountThisPollNext;
public boolean isEmptyThisPollNext() {
return emptyThisPollNext;
}

public void resetRowCountThisPollNext() {
this.rowCountThisPollNext = 0;
public void resetEmptyThisPollNext() {
this.emptyThisPollNext = true;
}

public void sendRecordToNext(Record<?> record) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SinkAggregatedCommitterTask<CommandInfoT, AggregatedCommitInfoT>

private static final long serialVersionUID = 5906594537520393503L;

private SeaTunnelTaskState currState;
private volatile SeaTunnelTaskState currState;
private final SinkAction<?, ?, CommandInfoT, AggregatedCommitInfoT> sink;
private final int maxWriterSize;

Expand Down Expand Up @@ -138,16 +138,22 @@ protected void stateProcess() throws Exception {
if (restoreComplete.isDone()) {
currState = READY_START;
reportTaskStatus(READY_START);
} else {
Thread.sleep(100);
}
break;
case READY_START:
if (startCalled) {
currState = STARTING;
} else {
Thread.sleep(100);
}
break;
case STARTING:
if (receivedSinkWriter) {
currState = RUNNING;
} else {
Thread.sleep(100);
}
break;
case RUNNING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ public void close() throws IOException {
public void collect() throws Exception {
if (!prepareClose) {
reader.pollNext(collector);
if (collector.getRowCountThisPollNext() == 0) {
if (collector.isEmptyThisPollNext()) {
Thread.sleep(100);
} else {
collector.resetRowCountThisPollNext();
collector.resetEmptyThisPollNext();
}
} else {
Thread.sleep(100);
}
}

Expand Down
Loading