Skip to content

Commit

Permalink
Add start and end-time for each worker.
Browse files Browse the repository at this point in the history
Adjusted the test as well and integrate it in the StresstestResultProcessor and Storages.
  • Loading branch information
nck-mlcnv committed Nov 4, 2023
1 parent 02674bf commit 5bb668a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private static void storeWorkerResults(Resource taskRes, Path file, Model data,

SelectBuilder sb = new SelectBuilder();
sb.addWhere(taskRes, IPROP.workerResult, "?worker");
queryProperties(sb, "?worker", IPROP.workerID, IPROP.workerType, IPROP.noOfQueries, IPROP.timeOut);
queryProperties(sb, "?worker", IPROP.workerID, IPROP.workerType, IPROP.noOfQueries, IPROP.timeOut, IPROP.startDate, IPROP.endDate);
queryMetrics(sb, "?worker", workerMetrics);

executeAndStoreQuery(sb, file, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;

import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.Supplier;

Expand All @@ -24,15 +25,17 @@ public class StresstestResultProcessor {
private final List<Storage> storages;
private final Supplier<Map<LanguageProcessor, List<LanguageProcessor.LanguageProcessingData>>> lpResults;

/**
* This array contains each query execution, grouped by each worker and each query.
*/
/** This array contains each query execution, grouped by each worker and each query. */
private final List<HttpWorker.ExecutionStats>[][] workerQueryExecutions;

/** This map contains each query execution, grouped by each query of the task. */
private final Map<String, List<HttpWorker.ExecutionStats>> taskQueryExecutions;

/**
* This map contains each query execution, grouped by each query of the task.
* Stores for each workerID an array with two items, that contains the start and end time for the respective
* worker. First item in the array is the start time, second item is the end time.
*/
private final Map<String, List<HttpWorker.ExecutionStats>> taskQueryExecutions;
private Map<Long, ZonedDateTime[]> workerStartEndTime;

private final IRES.Factory iresFactory;

Expand Down Expand Up @@ -64,6 +67,7 @@ public StresstestResultProcessor(String suiteID,
}

this.iresFactory = new IRES.Factory(suiteID, taskID);
this.workerStartEndTime = new HashMap<>();
}

/**
Expand All @@ -78,6 +82,7 @@ public void process(Collection<HttpWorker.Result> data) {
String queryID = workers.get((int) result.workerID()).config().queries().getQueryId(stat.queryID());
taskQueryExecutions.get(queryID).add(stat);
}
workerStartEndTime.put(result.workerID(), new ZonedDateTime[]{ result.startTime(), result.endTime() });
}
}

Expand Down Expand Up @@ -157,12 +162,18 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) {
m.add(taskRes, IPROP.query, iresFactory.getTaskQueryResource(queryID));
}

// Worker to queries
for (var worker : workers) {
Resource workerRes = iresFactory.getWorkerResource(worker);

// Worker to queries
for (int i = 0; i < worker.config().queries().getAllQueryIds().length; i++) {
Resource workerRes = iresFactory.getWorkerResource(worker);
m.add(workerRes, IPROP.query, iresFactory.getWorkerQueryResource(worker, i));
}

// start and end times for the workers
final var times = workerStartEndTime.get(worker.getWorkerID());
m.add(workerRes, IPROP.startDate, TimeUtils.createTypedZonedDateTimeLiteral(times[0]));
m.add(workerRes, IPROP.endDate, TimeUtils.createTypedZonedDateTimeLiteral(times[1]));
}

m.add(taskRes, IPROP.startDate, ResourceFactory.createTypedLiteral(start));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/aksw/iguana/cc/worker/HttpWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -119,7 +120,7 @@ public boolean miscellaneousException() {
}
}

public record Result(long workerID, List<ExecutionStats> executionStats) {}
public record Result(long workerID, List<ExecutionStats> executionStats, ZonedDateTime startTime, ZonedDateTime endTime) {}

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -221,6 +222,7 @@ public SPARQLProtocolWorker(long workerId, ResponseBodyProcessor responseBodyPro
*/
public CompletableFuture<Result> start() {
return CompletableFuture.supplyAsync(() -> {
ZonedDateTime startTime = ZonedDateTime.now();
List<ExecutionStats> executionStats = new ArrayList<>();
if (config().completionTarget() instanceof QueryMixes queryMixes) {
for (int i = 0; i < queryMixes.number(); i++) {
Expand All @@ -247,7 +249,8 @@ public CompletableFuture<Result> start() {
}
LOGGER.info("{}\t:: Reached time limit of {}.", this, timeLimit.duration());
}
return new Result(this.workerID, executionStats);
ZonedDateTime endTime = ZonedDateTime.now();
return new Result(this.workerID, executionStats, startTime, endTime);
}, executor);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/aksw/iguana/commons/time/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.jena.datatypes.xsd.XSDDuration;
import org.apache.jena.datatypes.xsd.impl.XSDDateTimeStampType;
import org.apache.jena.datatypes.xsd.impl.XSDDateTimeType;
import org.apache.jena.datatypes.xsd.impl.XSDDurationType;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.ResourceFactory;
Expand All @@ -10,6 +11,8 @@
import java.math.BigInteger;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
* Class related to the conversion of Java time objects to RDF literals.
Expand All @@ -27,4 +30,8 @@ public static Literal createTypedDurationLiteral(Duration duration) {
public static Literal createTypedInstantLiteral(Instant time) {
return ResourceFactory.createTypedLiteral(new XSDDateTimeStampType(null).parse(time.toString()));
}

public static Literal createTypedZonedDateTimeLiteral(ZonedDateTime time) {
return ResourceFactory.createTypedLiteral(new XSDDateTimeStampType(null).parse(time.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)));
}
}
7 changes: 6 additions & 1 deletion src/test/java/org/aksw/iguana/cc/mockup/MockupWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -63,6 +65,9 @@ public CompletableFuture<Result> start() {
}

public static List<Result> createWorkerResults(QueryHandler queries, List<HttpWorker> workers) {
final var startTime = ZonedDateTime.of(2023, 10, 11, 14, 14, 10, 0, ZoneId.of("UTC"));
final var endTime = ZonedDateTime.of(2023, 10, 12, 15, 15, 15, 0, ZoneId.of("UTC"));

final var queryNumber = queries.getQueryCount();

Instant time = Instant.parse("2023-10-21T20:48:06.399Z");
Expand Down Expand Up @@ -97,7 +102,7 @@ public static List<Result> createWorkerResults(QueryHandler queries, List<HttpWo
time = time.plusSeconds(1);
exectutionStats.add(new ExecutionStats(queryID, time, failDuration, failHttpCode, failLength, failResponseBodyHash, Optional.of(failException)));
}
results.add(new Result(worker.getWorkerID(), exectutionStats));
results.add(new Result(worker.getWorkerID(), exectutionStats, startTime, endTime));
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workerID,workerType,noOfQueries,timeOut,AvgQPS,NoQ,NoQPH,PAvgQPS,QMPH
0,MockupWorker,10,PT2S,0.5,10,1800,0.75,180
2,MockupWorker,10,PT2S,0.5,10,1800,0.75,180
3,MockupWorker,10,PT2S,0.5,10,1800,0.75,180
1,MockupWorker,10,PT2S,0.5,10,1800,0.75,180
workerID,workerType,noOfQueries,timeOut,startDate,endDate,AvgQPS,NoQ,NoQPH,PAvgQPS,QMPH
0,MockupWorker,10,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,10,1800,0.75,180
2,MockupWorker,10,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,10,1800,0.75,180
3,MockupWorker,10,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,10,1800,0.75,180
1,MockupWorker,10,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,10,1800,0.75,180
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workerID,workerType,noOfQueries,timeOut,AvgQPS,NoQ,NoQPH,PAvgQPS,QMPH
0,MockupWorker,5,PT2S,0.5,5,1800,0.75,360
2,MockupWorker,5,PT2S,0.5,5,1800,0.75,360
3,MockupWorker,5,PT2S,0.5,5,1800,0.75,360
1,MockupWorker,5,PT2S,0.5,5,1800,0.75,360
workerID,workerType,noOfQueries,timeOut,startDate,endDate,AvgQPS,NoQ,NoQPH,PAvgQPS,QMPH
0,MockupWorker,5,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,5,1800,0.75,360
2,MockupWorker,5,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,5,1800,0.75,360
3,MockupWorker,5,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,5,1800,0.75,360
1,MockupWorker,5,PT2S,2023-10-11T14:14:10Z,2023-10-12T15:15:15Z,0.5,5,1800,0.75,360

0 comments on commit 5bb668a

Please sign in to comment.