Skip to content

Commit

Permalink
Fix rate inaccurate when print progress (#205)
Browse files Browse the repository at this point in the history
Change-Id: I7806987d76affb416f6f7daabd45a3999027c47c
  • Loading branch information
Linary authored Apr 26, 2021
1 parent 9b2bb32 commit e6915d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/baidu/hugegraph/loader/HugeGraphLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ private void loadInputs() {
// Waiting for async worker threads finish
this.manager.waitFinished();
} finally {
summary.stopFlowRangeTimer(ElemType.VERTEX);
summary.stopFlowRangeTimer(ElemType.EDGE);
summary.calculateTotalTime(ElemType.VERTEX);
summary.calculateTotalTime(ElemType.EDGE);
summary.stopTotalTimer();
}
Printer.printFinalProgress(this.context);
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/baidu/hugegraph/loader/metrics/LoadSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

import org.apache.commons.lang3.time.StopWatch;
Expand All @@ -34,8 +35,8 @@ public final class LoadSummary {
private final LongAdder vertexLoaded;
private final LongAdder edgeLoaded;
private final StopWatch totalTimer;
private final LongAdder vertexTime;
private final LongAdder edgeTime;
private final AtomicLong vertexTime;
private final AtomicLong edgeTime;
private final RangesTimer vertexRangesTimer;
private final RangesTimer edgeRangesTimer;
// Every input struct has a metric
Expand All @@ -45,8 +46,8 @@ public LoadSummary() {
this.vertexLoaded = new LongAdder();
this.edgeLoaded = new LongAdder();
this.totalTimer = new StopWatch();
this.vertexTime = new LongAdder();
this.edgeTime = new LongAdder();
this.vertexTime = new AtomicLong();
this.edgeTime = new AtomicLong();
this.vertexRangesTimer = new RangesTimer(10000);
this.edgeRangesTimer = new RangesTimer(10000);
this.inputMetricsMap = InsertionOrderUtil.newMap();
Expand Down Expand Up @@ -117,11 +118,11 @@ public void addTimeRange(ElemType type, long start, long end) {
timer.addTimeRange(start, end);
}

public void stopFlowRangeTimer(ElemType type) {
public void calculateTotalTime(ElemType type) {
RangesTimer timer = type.isVertex() ? this.vertexRangesTimer :
this.edgeRangesTimer;
LongAdder elemTime = type.isVertex() ? this.vertexTime : this.edgeTime;
elemTime.add(timer.totalTime());
AtomicLong elemTime = type.isVertex() ? this.vertexTime : this.edgeTime;
elemTime.set(timer.totalTime());
}

public long totalTime() {
Expand Down Expand Up @@ -149,6 +150,9 @@ public void stopTotalTimer() {
}

public long loadRate(ElemType type) {
// Ensure vetex time and edge time has been set
this.calculateTotalTime(type);

boolean isVertex = type.isVertex();
long totalTime = isVertex ? this.vertexTime() : this.edgeTime();
if (totalTime == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public RangesTimer(int capacity) {

public synchronized long totalTime() {
if (!this.ranges.isEmpty()) {
long time = this.caculate();
this.totalTime += time;
long incrTime = this.caculate();
this.totalTime += incrTime;
this.ranges.clear();
}
return this.totalTime;
}

public synchronized void addTimeRange(long start, long end) {
if (this.ranges.size() >= this.capacity) {
long time = this.caculate();
this.totalTime += time;
long incrTime = this.caculate();
this.totalTime += incrTime;
this.ranges.clear();
}
this.ranges.add(new TimeRange(start, end));
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/baidu/hugegraph/loader/util/Printer.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ private static void printCountReport(LoadReport report) {
}

private static void printMeterReport(LoadSummary summary) {
long totalTime = summary.totalTime();
long vertexTime = summary.vertexTime();
long edgeTime = summary.edgeTime();
long readTime = totalTime - vertexTime - edgeTime;

printAndLog("meter metrics");
printAndLog("total time", TimeUtil.readableTime(summary.totalTime()));
printAndLog("vertex time", TimeUtil.readableTime(summary.vertexTime()));
printAndLog("total time", TimeUtil.readableTime(totalTime));
printAndLog("read time", TimeUtil.readableTime(readTime));
printAndLog("vertex load time", TimeUtil.readableTime(vertexTime));
printAndLog("vertex load rate(vertices/s)",
summary.loadRate(ElemType.VERTEX));
printAndLog("edge time", TimeUtil.readableTime(summary.edgeTime()));
printAndLog("edge load time", TimeUtil.readableTime(edgeTime));
printAndLog("edge load rate(edges/s)", summary.loadRate(ElemType.EDGE));
}

Expand Down

0 comments on commit e6915d8

Please sign in to comment.