Skip to content

Commit

Permalink
further integrate the previous merge
Browse files Browse the repository at this point in the history
* this commit also moved some packages
  • Loading branch information
nck-mlcnv committed Aug 21, 2023
1 parent 61e5e12 commit 4c66cde
Show file tree
Hide file tree
Showing 55 changed files with 901 additions and 914 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.aksw.iguana.cc.config.elements;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.aksw.iguana.cc.worker.impl.SPARQLProtocolWorker;
import org.aksw.iguana.rp.storage.impl.RDFFileStorage;
import org.aksw.iguana.rp.storage.impl.TriplestoreStorage;
import org.aksw.iguana.cc.storage.impl.RDFFileStorage;
import org.aksw.iguana.cc.storage.impl.TriplestoreStorage;

/**
* Storage Configuration class
Expand All @@ -16,7 +14,8 @@
property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = TriplestoreStorage.Config.class, name = "triplestore"),
@JsonSubTypes.Type(value = RDFFileStorage.Config.class, name = "RDF file"),
@JsonSubTypes.Type(value = RDFFileStorage.Config.class, name = "rdf"),
@JsonSubTypes.Type(value = CSVStorage.Config.class, name = "csv")
})
public interface StorageConfig {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void main(String[] argc) throws IOException {
}
// TODO: a bit of error handling
Suite parse = IguanaSuiteParser.parse(args.suitePath);
Suite.Result run = parse.run();
parse.run();
System.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.aksw.iguana.cc.tasks.stresstest.metrics;
package org.aksw.iguana.cc.metrics;

public abstract class Metric {
private final String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.aksw.iguana.cc.tasks.stresstest.metrics;
package org.aksw.iguana.cc.metrics;

import java.util.List;

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/ModelWritingMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.aksw.iguana.cc.metrics;

import org.aksw.iguana.cc.worker.HttpWorker;
import org.aksw.iguana.commons.rdf.IRES;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Map;

public interface ModelWritingMetric {
default @Nonnull Model createMetricModel(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data, IRES.Factory iresFactory) {
return ModelFactory.createDefaultModel();
}

default @Nonnull Model createMetricModel(List<HttpWorker> workers, Map<String, List<HttpWorker.ExecutionStats>> data, IRES.Factory iresFactory) {
return ModelFactory.createDefaultModel();
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/QueryMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.aksw.iguana.cc.metrics;

import org.aksw.iguana.cc.worker.HttpWorker;

import java.util.List;

public interface QueryMetric {
Number calculateQueryMetric(List<HttpWorker.ExecutionStats> data);
}
9 changes: 9 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/TaskMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.aksw.iguana.cc.metrics;

import org.aksw.iguana.cc.worker.HttpWorker;

import java.util.List;

public interface TaskMetric {
Number calculateTaskMetric(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data);
}
9 changes: 9 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/WorkerMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.aksw.iguana.cc.metrics;

import org.aksw.iguana.cc.worker.HttpWorker;

import java.util.List;

public interface WorkerMetric {
Number calculateWorkerMetric(HttpWorker.Config worker, List<HttpWorker.ExecutionStats>[] data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.aksw.iguana.cc.metrics.impl;

import org.aksw.iguana.cc.metrics.Metric;
import org.aksw.iguana.cc.metrics.ModelWritingMetric;
import org.aksw.iguana.cc.worker.HttpWorker;
import org.aksw.iguana.commons.rdf.IONT;
import org.aksw.iguana.commons.rdf.IPROP;
import org.aksw.iguana.commons.rdf.IRES;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.RDF;

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.aksw.iguana.commons.time.TimeUtils.toXSDDurationInSeconds;

public class AggregatedExecutionStatistics extends Metric implements ModelWritingMetric {

public AggregatedExecutionStatistics() {
super("Aggregated Execution Statistics", "AES", "Sums up the statistics of each query execution for each query a worker and task has. The result size only contains the value of the last execution.");
}

@Override
@Nonnull
public Model createMetricModel(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data, IRES.Factory iresFactory) {
Model m = ModelFactory.createDefaultModel();
for (var worker : workers) {
for (int i = 0; i < worker.config().queries().getQueryCount(); i++) {
Resource queryRes = iresFactory.getWorkerQueryResource(worker, i);
m.add(createAggregatedModel(data[(int) worker.getWorkerID()][i], queryRes));
}
}
return m;
}

@Override
@Nonnull
public Model createMetricModel(List<HttpWorker> workers, Map<String, List<HttpWorker.ExecutionStats>> data, IRES.Factory iresFactory) {
Model m = ModelFactory.createDefaultModel();
for (String queryID : data.keySet()) {
Resource queryRes = iresFactory.getTaskQueryResource(queryID);
m.add(createAggregatedModel(data.get(queryID), queryRes));
}
return m;
}

private static Model createAggregatedModel(List<HttpWorker.ExecutionStats> data, Resource queryRes) {
Model m = ModelFactory.createDefaultModel();
BigInteger succeeded = BigInteger.ZERO;
BigInteger failed = BigInteger.ZERO;
Optional<BigInteger> resultSize = Optional.empty();
BigInteger wrongCodes = BigInteger.ZERO;
BigInteger timeOuts = BigInteger.ZERO;
BigInteger unknownExceptions = BigInteger.ZERO;
Duration totalTime = Duration.ZERO;

for (HttpWorker.ExecutionStats exec : data) {
switch (exec.endState()) {
case SUCCESS -> succeeded = succeeded.add(BigInteger.ONE);
case TIMEOUT -> timeOuts = timeOuts.add(BigInteger.ONE);
case HTTP_ERROR -> wrongCodes = wrongCodes.add(BigInteger.ONE);
case MISCELLANEOUS_EXCEPTION -> unknownExceptions = unknownExceptions.add(BigInteger.ONE);
}

if (!exec.successful())
failed = failed.add(BigInteger.ONE);

totalTime = totalTime.plus(exec.duration());
if (exec.contentLength().isPresent())
resultSize = Optional.of(BigInteger.valueOf(exec.contentLength().getAsLong()));
}

m.add(queryRes, IPROP.succeeded, ResourceFactory.createTypedLiteral(succeeded));
m.add(queryRes, IPROP.failed, ResourceFactory.createTypedLiteral(failed));
if (resultSize.isPresent())
m.add(queryRes, IPROP.resultSize, ResourceFactory.createTypedLiteral(resultSize.get()));
m.add(queryRes, IPROP.timeOuts, ResourceFactory.createTypedLiteral(timeOuts));
m.add(queryRes, IPROP.wrongCodes, ResourceFactory.createTypedLiteral(wrongCodes));
m.add(queryRes, IPROP.unknownException, ResourceFactory.createTypedLiteral(unknownExceptions));
m.add(queryRes, IPROP.totalTime, ResourceFactory.createTypedLiteral(toXSDDurationInSeconds(totalTime)));
m.add(queryRes, RDF.type, IONT.executedQuery);

return m;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package org.aksw.iguana.cc.tasks.stresstest.metrics.impl;
package org.aksw.iguana.cc.metrics.impl;

import org.aksw.iguana.cc.model.QueryExecutionStats;
import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata;
import org.aksw.iguana.cc.worker.WorkerMetadata;
import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric;
import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric;
import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric;
import org.aksw.iguana.commons.annotation.Shorthand;
import org.aksw.iguana.cc.metrics.Metric;
import org.aksw.iguana.cc.metrics.TaskMetric;
import org.aksw.iguana.cc.metrics.WorkerMetric;
import org.aksw.iguana.cc.worker.HttpWorker;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@Shorthand("AvgQPS")
public class AvgQPS extends Metric implements TaskMetric, WorkerMetric {

public AvgQPS() {
super("Average Queries per Second", "AvgQPS", "This metric calculates the average QPS between all queries.");
}

@Override
public Number calculateTaskMetric(StresstestMetadata task, List<QueryExecutionStats>[][] data) {
public Number calculateTaskMetric(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data) {
BigDecimal sum = BigDecimal.ZERO;
for (WorkerMetadata worker : task.workers()) {
sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker, data[worker.workerID()]));
for (var worker : workers) {
sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker.config(), data[(int) worker.getWorkerID()]));
}

try {
Expand All @@ -34,10 +30,10 @@ public Number calculateTaskMetric(StresstestMetadata task, List<QueryExecutionSt
}

@Override
public Number calculateWorkerMetric(WorkerMetadata worker, List<QueryExecutionStats>[] data) {
public Number calculateWorkerMetric(HttpWorker.Config worker, List<HttpWorker.ExecutionStats>[] data) {
BigDecimal sum = BigDecimal.ZERO;
QPS qpsmetric = new QPS();
for (List<QueryExecutionStats> datum : data) {
for (List<HttpWorker.ExecutionStats> datum : data) {
sum = sum.add((BigDecimal) qpsmetric.calculateQueryMetric(datum));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.aksw.iguana.cc.metrics.impl;

import org.aksw.iguana.cc.metrics.Metric;
import org.aksw.iguana.cc.metrics.ModelWritingMetric;
import org.aksw.iguana.cc.worker.HttpWorker;
import org.aksw.iguana.commons.rdf.IPROP;
import org.aksw.iguana.commons.rdf.IRES;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.util.List;

public class EachExecutionStatistic extends Metric implements ModelWritingMetric {

public EachExecutionStatistic() {
super("Each Query Execution Statistic", "EachQuery", "This metric saves the statistics of each query execution.");
}

@Override
@Nonnull
public Model createMetricModel(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data, IRES.Factory iresFactory) {
Model m = ModelFactory.createDefaultModel();
for (var worker : workers) {
for (int i = 0; i < worker.config().queries().getQueryCount(); i++) {
Resource workerQueryResource = iresFactory.getWorkerQueryResource(worker, i);
Resource queryRes = IRES.getResource(worker.config().queries().getQueryId(i));
BigInteger run = BigInteger.ONE;
for (HttpWorker.ExecutionStats exec : data[(int) worker.getWorkerID()][i]) {
Resource runRes = iresFactory.getWorkerQueryRunResource(worker, i, run);
m.add(workerQueryResource, IPROP.queryExecution, runRes);
m.add(runRes, IPROP.time, ResourceFactory.createTypedLiteral(exec.duration()));
m.add(runRes, IPROP.success, ResourceFactory.createTypedLiteral(exec.successful()));
m.add(runRes, IPROP.run, ResourceFactory.createTypedLiteral(run));
m.add(runRes, IPROP.code, ResourceFactory.createTypedLiteral(exec.endState().value));
// TODO: maybe add http status code
if (exec.contentLength().isPresent())
m.add(runRes, IPROP.resultSize, ResourceFactory.createTypedLiteral(exec.contentLength().getAsLong()));
m.add(runRes, IPROP.queryID, queryRes);
run = run.add(BigInteger.ONE);
}
}
}
return m;
}
}
38 changes: 38 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/impl/NoQ.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.aksw.iguana.cc.metrics.impl;

import org.aksw.iguana.cc.metrics.Metric;
import org.aksw.iguana.cc.metrics.TaskMetric;
import org.aksw.iguana.cc.metrics.WorkerMetric;
import org.aksw.iguana.cc.worker.HttpWorker;

import java.math.BigInteger;
import java.util.List;

public class NoQ extends Metric implements TaskMetric, WorkerMetric {

public NoQ() {
super("Number of Queries", "NoQ", "This metric calculates the number of successfully executed queries.");
}

@Override
public Number calculateTaskMetric(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data) {
BigInteger sum = BigInteger.ZERO;
for (var worker : workers) {
sum = sum.add((BigInteger) this.calculateWorkerMetric(worker.config(), data[(int) worker.getWorkerID()]));
}
return sum;
}

@Override
public Number calculateWorkerMetric(HttpWorker.Config worker, List<HttpWorker.ExecutionStats>[] data) {
BigInteger sum = BigInteger.ZERO;
for (List<HttpWorker.ExecutionStats> datum : data) {
for (HttpWorker.ExecutionStats exec : datum) {
if (exec.successful()) {
sum = sum.add(BigInteger.ONE);
}
}
}
return sum;
}
}
48 changes: 48 additions & 0 deletions src/main/java/org/aksw/iguana/cc/metrics/impl/NoQPH.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.aksw.iguana.cc.metrics.impl;

import org.aksw.iguana.cc.metrics.Metric;
import org.aksw.iguana.cc.metrics.TaskMetric;
import org.aksw.iguana.cc.metrics.WorkerMetric;
import org.aksw.iguana.cc.worker.HttpWorker;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.time.Duration;
import java.util.List;

public class NoQPH extends Metric implements TaskMetric, WorkerMetric {

public NoQPH() {
super("Number of Queries per Hour", "NoQPH", "This metric calculates the number of successfully executed queries per hour.");
}
@Override
public Number calculateTaskMetric(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data) {
BigDecimal sum = BigDecimal.ZERO;
for (var worker : workers) {
sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker.config(), data[(int) worker.getWorkerID()]));
}
return sum;
}

@Override
public Number calculateWorkerMetric(HttpWorker.Config worker, List<HttpWorker.ExecutionStats>[] data) {
BigDecimal successes = BigDecimal.ZERO;
Duration totalTime = Duration.ZERO;
for (List<HttpWorker.ExecutionStats> datum : data) {
for (HttpWorker.ExecutionStats exec : datum) {
if (exec.successful()) {
successes = successes.add(BigDecimal.ONE);
totalTime = totalTime.plus(exec.duration());
}
}
}
BigDecimal tt = (new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 9)).divide(BigDecimal.valueOf(3600), 20, RoundingMode.HALF_UP);

try {
return successes.divide(tt, 10, RoundingMode.HALF_UP);
} catch (ArithmeticException e) {
return BigDecimal.ZERO;
}
}
}
Loading

0 comments on commit 4c66cde

Please sign in to comment.