Commit 9b8a0f49 authored by adamk's avatar adamk
Browse files

commit that was used for performance testing

parent d10dccf1
package cz.muni.fi.lasaris.sbms.semantics.logic;
import java.util.ArrayList;
import java.util.List;
import org.apache.jena.graph.NodeFactory;
......@@ -25,7 +26,7 @@ import cz.muni.fi.lasaris.sbms.semantics.api.request.GroupableRequest;
import cz.muni.fi.lasaris.sbms.semantics.api.request.TrendsRequest;
public class BodyBuilders {
/*
private static class TypeClauseContainer {
public String f1;
public String f2;
......@@ -39,7 +40,7 @@ public class BodyBuilders {
this.f4 = f4;
}
}
*/
public static ElementGroup getQueryBody(DataPointsRequest request) {
return getQueryBody(request.getDataPoint(), request);
}
......@@ -50,14 +51,28 @@ public class BodyBuilders {
// https://gregheartsfield.com/2012/08/26/jena-arq-query-performance.html
// type clauses moved to the end of the query as it significantly decreases performance
//List<TypeClauseContainer> tcc = new LinkedList<TypeClauseContainer>();
List<TypeClauseContainer> tcc = new ArrayList<TypeClauseContainer>(10);
List<String> fields = request.getResponseFields();
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
NodeFactory.createURI(NS.sbms + "hasBMSId"),
Var.alloc(gsv("bmsId"))));
// moved at the and, as it is the most expensive query part
if(fields.contains("type")) {
//setTypeClause(body, "datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint");
tcc.add(new TypeClauseContainer("datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint"));
}
if(dp.getType() != null) {
// body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
// NodeFactory.createURI(NS.rdf + "type"),
// NodeFactory.createURI(NS.sbms + dp.getType())));
//
tcc.add(new TypeClauseContainer(null, null, "datapoint", NS.sbms + dp.getType()));
}
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
NodeFactory.createURI(NS.sbms + "expressesObservation"),
Var.alloc("obs")));
......@@ -93,16 +108,16 @@ public class BodyBuilders {
if(dp.getSource() != null && dp.getSource().getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("source"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbim + dp.getSource().getType())));
//tcc.add(new TypeClauseContainer(null, null, "source", NS.sbim + dp.getSource().getType()));
// body.addTriplePattern(Triple.create(Var.alloc("source"),
// NodeFactory.createURI(NS.rdf + "type"),
// NodeFactory.createURI(NS.sbim + dp.getSource().getType())));
//
tcc.add(new TypeClauseContainer(null, null, "source", NS.sbim + dp.getSource().getType()));
}
if(fields.contains("source.type")) {
setTypeClause(body, "source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "SensingDevice");
//tcc.add(new TypeClauseContainer("source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "Source"));
// setTypeClause(body, "source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "SensingDevice");
tcc.add(new TypeClauseContainer("source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "SensingDevice"));
}
if((dp.getSource() != null && dp.getSource().getLocation() != null)) {
......@@ -156,16 +171,16 @@ public class BodyBuilders {
if(dp.getScope() != null && dp.getScope().getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("scope"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbim + dp.getScope().getType())));
// body.addTriplePattern(Triple.create(Var.alloc("scope"),
// NodeFactory.createURI(NS.rdf + "type"),
// NodeFactory.createURI(NS.sbim + dp.getScope().getType())));
//tcc.add(new TypeClauseContainer(null, null, "scope", NS.sbim + dp.getScope().getType()));
tcc.add(new TypeClauseContainer(null, null, "scope", NS.sbim + dp.getScope().getType()));
}
if(fields.contains("scope.type")) {
setTypeClause(body, "scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbms + "FeatureOfInterest");
//tcc.add(new TypeClauseContainer("scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbms + "Scope"));
// setTypeClause(body, "scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbms + "FeatureOfInterest");
tcc.add(new TypeClauseContainer("scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbim + "Facility"));
}
// scopeLoc
......@@ -195,10 +210,10 @@ public class BodyBuilders {
Var.alloc("sensing")));
if(dp.getSensing() != null && dp.getSensing().getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("sensing"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbms + dp.getSensing().getType())));
//tcc.add(new TypeClauseContainer(null, null, "sensing", NS.sbim + NS.sbms + dp.getSensing().getType()));
// body.addTriplePattern(Triple.create(Var.alloc("sensing"),
// NodeFactory.createURI(NS.rdf + "type"),
// NodeFactory.createURI(NS.sbms + dp.getSensing().getType())));
tcc.add(new TypeClauseContainer(null, null, "sensing", NS.sbms + dp.getSensing().getType()));
}
if(dp.getSensing() != null && dp.getSensing().getWindow() != null) {
......@@ -209,8 +224,8 @@ public class BodyBuilders {
}
if(fields.contains("sensing.type")) {
setTypeClause(body, "sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing");
//tcc.add(new TypeClauseContainer("sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing"));
// setTypeClause(body, "sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing");
tcc.add(new TypeClauseContainer("sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing"));
}
if(fields.contains("sensing.window")) {
......@@ -304,29 +319,21 @@ public class BodyBuilders {
}
// optimization - placing type clauses at the end
/*for(TypeClauseContainer c : tcc) {
if(c.f1 == null) {
body.addTriplePattern(Triple.create(Var.alloc(c.f3),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(c.f4)));
} else {
setTypeClause(body, c.f1, c.f2, c.f3, c.f4);
}
}*/
// GROUPING
if(request.getGrouping() != null && Fields.GROUPINGS.contains(request.getGrouping())) {
switch(request.getGrouping()) {
case "dataPoint.type":
setTypeClause(body, "datapoint", "group", NS.sbms + "DataPoint", NS.sbms + "DataPoint");
//setTypeClause(body, "datapoint", "group", NS.sbms + "DataPoint", NS.sbms + "DataPoint");
tcc.add(new TypeClauseContainer("datapoint", "group", NS.sbms + "DataPoint", NS.sbms + "DataPoint"));
break;
case "source.type":
setTypeClause(body, "source", "group", NS.sbim + "Device", NS.sbms + "SensingDevice");
//setTypeClause(body, "source", "group", NS.sbim + "Device", NS.sbms + "SensingDevice");
tcc.add(new TypeClauseContainer("source", "group", NS.sbim + "Device", NS.sbms + "SensingDevice"));
break;
case "scope.type":
//setTypeClause(body, "scope", "group", NS.dul + "PhysicalObject", NS.sbms + "Scope");
setTypeClause(body, "scope", "group", NS.sbim + "Facility", NS.sbms + "FeatureOfInterest");
//setTypeClause(body, "scope", "group", NS.sbim + "Facility", NS.sbms + "FeatureOfInterest");
tcc.add(new TypeClauseContainer("scope", "group", NS.sbim + "Facility", NS.sbms + "FeatureOfInterest"));
break;
case "scope.room":
case "scope.floor":
......@@ -341,10 +348,11 @@ public class BodyBuilders {
NodeFactory.createURI(NS.sbim + "isPartOf"),
Var.alloc("groupR")));
// group rdf:type grouping
body.addTriplePattern(Triple.create(Var.alloc("groupR"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbim + request.getGrouping(1))));
// body.addTriplePattern(Triple.create(Var.alloc("groupR"),
// NodeFactory.createURI(NS.rdf + "type"),
// NodeFactory.createURI(NS.sbim + request.getGrouping(1))));
tcc.add(new TypeClauseContainer(null, null, "groupR", NS.sbim + request.getGrouping(1)));
body.addTriplePattern(Triple.create(Var.alloc("groupR"),
NodeFactory.createURI(NS.sbim + "hasBIMId"),
Var.alloc("group")));
......@@ -356,18 +364,17 @@ public class BodyBuilders {
}
// moved at the and, as it is the most expensive query part
if(fields.contains("type")) {
setTypeClause(body, "datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint");
//tcc.add(new TypeClauseContainer("datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint"));
}
if(dp.getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbms + dp.getType())));
//tcc.add(new TypeClauseContainer(null, null, "datapoint", NS.sbms + dp.getType()));
// optimization - placing type clauses at the end
// better performance is reached when the datapoint type is the last - thus adding from the end
for(int i = 0; i < tcc.size(); i++) {
TypeClauseContainer c = tcc.get(tcc.size() - i - 1);
if(c.f1 == null) {
body.addTriplePattern(Triple.create(Var.alloc(c.f3),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(c.f4)));
} else {
setTypeClause(body, c.f1, c.f2, c.f3, c.f4);
}
}
return body;
......@@ -550,6 +557,58 @@ public class BodyBuilders {
private static void setTypeClause(ElementGroup body, String fieldName, String fieldTypeName,
String rootClass, String ignoredClass) {
/* THE WHOLE QUERY:
?dataPoint rdf:type ?dataPointClass.
?dataPointClass rdfs:subClassOf sbms:DataPoint.
FILTER (not exists { ?subtype rdfs:subClassOf ?dataPointClass.
FILTER (?subtype != ?dataPointClass && ?subtype != owl:Nothing) }
).
*/
// ?dataPoint rdf:type ?dataPointClass.
body.addTriplePattern(Triple.create(Var.alloc(fieldName),
NodeFactory.createURI(NS.rdf + "type"),
Var.alloc(fieldTypeName)));
// ?dataPointClass rdfs:subClassOf sbms:DataPoint.
Triple tp = Triple.create(Var.alloc(fieldTypeName),
NodeFactory.createURI(NS.rdfs + "subClassOf"),
NodeFactory.createURI(rootClass));
body.addTriplePattern(tp);
// ?subtype rdfs:subClassOf ?dataPointClass.
// FILTER (?subtype != ?dataPointClass && ?subtype != sbms:DataPoint && ?subtype != owl:Nothing)
ElementGroup b = new ElementGroup();
b.addTriplePattern(Triple.create(Var.alloc("subtype"),
NodeFactory.createURI(NS.rdfs + "subClassOf"),
Var.alloc(fieldTypeName)));
// FILTER (?subtype != ?dataPointClass && ?subtype != sbms:DataPoint && ?subtype != owl:Nothing)
b.addElement(new ElementFilter(
new E_LogicalAnd(
// ?subtype != ?dataPointClass
new E_NotEquals(new ExprVar("subtype"), new ExprVar(fieldTypeName)),
// ?subtype != owl:Nothing
new E_NotEquals(new ExprVar("subtype"), new NodeValueNode(NodeFactory.createURI(NS.owl+"Nothing")))
)
)
);
//FILTER (?dataPointClass != sbms:DataPoint
//&& not exists { ?subtype rdfs:subClassOf ?dataPointClass.
// FILTER (?subtype != ?dataPointClass && ?subtype != sbms:DataPoint && ?subtype != owl:Nothing) }
// ).
body.addElementFilter(new ElementFilter(
// not exists { ?subtype rdfs:subClassOf ?dataPointClass.
// FILTER (?subtype != ?dataPointClass && ?subtype != owl:Nothing) }
new E_NotExists(b)));
}
private static void setTypeClauseOld(ElementGroup body, String fieldName, String fieldTypeName,
String rootClass, String ignoredClass) {
/* THE WHOLE QUERY:
?dataPoint rdf:type ?dataPointClass.
......
[CmdletBinding()]
[CmdletBinding()]
Param(
[String]$InFolder = ".\CSV-Data",
[String]$OutFile = ".\NT-Data\data.nt"
......
......@@ -3,7 +3,7 @@ Param([String]$Csv="datapoints.csv")
. ((split-path -parent $MyInvocation.MyCommand.Definition) + "\Namespaces.ps1")
import-csv -Delimiter ";" $Csv | ForEach-Object {
$dpId= $dpId= "DataPoint" + $_.dpId.Replace("/","-").Replace(".","-").Replace(":","-")
$dpId= "DataPoint" + $_.dpId.Replace("/","-").Replace(".","-").Replace(":","-")
$obsId = $dpId + "Obs"
($pref["sbmsd"] + $dpId + "> " + $pref["rdf"] + "type" + "> " + $pref["sbms"] + $_.dpType + "> .")
($pref["sbmsd"] + $obsId + "> " + $pref["rdf"] + "type" + "> " + $pref["sbms"] + "Observation> .")
......
......@@ -3,8 +3,8 @@ Param([String]$Csv="trends.csv")
. ((split-path -parent $MyInvocation.MyCommand.Definition) + "\Namespaces.ps1")
import-csv -Delimiter ";" $Csv | ForEach-Object {
$dpId= "DataPoint" + $_.dpId.Replace("[:/.]","-")
$trendId= "Trend" + $_.trendId.Replace("[:/.]","-")
$dpId = "DataPoint" + $_.dpId.Replace("/","-").Replace(".","-").Replace(":","-")
$trendId= "Trend" + $_.trendId.Replace("/","-").Replace(".","-").Replace(":","-")
($pref["sbmsd"] + $trendId + "> " + $pref["rdf"] + "type" + "> " + $pref["sbms"] + "Trend> .")
($pref["sbmsd"] + $trendId + "> " + $pref["sbms"]+ "hasBMSId" + "> " + "`"" + $_.trendId + "`"" + " .")
($pref["sbmsd"] + $trendId + "> " + $pref["sbms"]+ "trends" + "> " + $pref["sbmsd"] + $dpId + "> .")
......
......@@ -3,13 +3,13 @@ Param([switch]$ManageTomcat,
[String]$TomcatHome = "\apache-tomcat",
[String]$User = "admin",
[String]$Pass = "nimda",
[String]$Server = "http://localhost:8080",
[String]$TestsToRun = "1,2,3,4,5"
[String]$Server = "http://localhost:8080/sbms/semantics/",
[String]$TestsToRun = "1,2,3,4,5",
[Int]$Repeat = 1,
[switch]$PrintHeaders
)
#Measure-Command { Invoke-WebRequest -URI http://loca$Server:8080/sbms/semantics/types/type } Select-Object TotalSeconds
Function Get-Auth($user, $pass) {
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
......@@ -18,10 +18,10 @@ Function Get-Auth($user, $pass) {
return @{ Authorization = $basicAuthValue }
}
Function Request($testName, $auth, $url) {
Function Request($testId, $testName, $auth, $url) {
#"Sending..." + [System.DateTime]::Now
$start = [System.DateTime]::Now
$r = Invoke-WebRequest -Method Get -URI $url -Headers $auth | Select-Object StatusCode, Content
$r = Invoke-WebRequest -Method Get -URI $url -Headers $auth
$end = [System.DateTime]::Now.Subtract($start) #| Select-Object TotalSeconds
$dur = $end.TotalSeconds
$c = ConvertFrom-Json $r.Content
......@@ -32,7 +32,7 @@ Function Request($testName, $auth, $url) {
$count += $c.results.$g.Count
}
}
[System.String]::Format("{0:00.00}",$dur) + ";" + $testName + ";" + $r.StatusCode + ";" + $count
[System.String]::Format("{0:00.00}",$dur) + ";" + $testId + ";" + $testName + ";" + $r.StatusCode + ";" + $count
}
if($ManageTomcat) {
......@@ -45,40 +45,43 @@ if($ManageTomcat) {
Pause
}
"duration;testName;statusCode;dataPoints"
if($PrintHeaders) {
"duration;id;testDesc;statusCode;dataPoints"
}
#initial request -- to init the tdb and mode
Request "0: Init" $auth ($Server + "/sbms/semantics/types/type")
Request "0" "Init" $auth ($Server + "types/type")
$auth = Get-Auth $User $Pass
$tArray = $TestsToRun.Split(",")
Request "UC:Trend" $auth ($Server + "/sbms/semantics/trends/?fields=bmsId,dataPoint.bmsId&grouping=scope.building&type=Input&source.type=TemperatureSensor&source.location=S01&scope.type=Room&property.domain=Air&property.quality=temperature&sensing.type=StatelessDirectSensing")
Request "UC:DP" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId,source.type&grouping=scope.room&type=Input&source.type=Sensor&source.location=S01B04&scope.type=Room&property.domain=Air&sensing.type=StatelessDirectSensing")
for($i=0; $i -lt $Repeat; $i++){
if($tArray.Contains("UC")) {
Request "UC1" "Trends - Average room temperatures" $auth ($Server + "trends/?fields=bmsId%2CdataPoint.bmsId&grouping=scope.building&dataPoint.type=Input&dataPoint.source.type=TemperatureSensor&dataPoint.source.location=S01&dataPoint.scope.type=Room&dataPoint.sensing.type=StatelessDirectSensing&dataPoint.property.domain=Air&dataPoint.property.quality=temperature")
Request "UC2" "DP" $auth ($Server + "datapoints/?fields=bmsId,source.type&grouping=source.room&type=Input&source.type=Sensor&source.location=S01B04&scope.type=Room&property.domain=Air&sensing.type=StatelessDirectSensing")
}
if($tArray.Contains("1")) {
Request "1: All information about a DP" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId%2Ctype%2Csource.bimId%2Csource.type%2Csource.location%2Cscope.bimId%2Cscope.type%2Cscope.location%2Csensing.type%2Csensing.window%2Cproperty.domain%2Cproperty.quality%2Cpublisher.bimId&bmsId=bacnet%3A%2F%2F04010306.AV1")
Request "1" "All information about a DP" $auth ($Server + "datapoints/?fields=bmsId%2Ctype%2Csource.bimId%2Csource.type%2Csource.location%2Cscope.bimId%2Cscope.type%2Cscope.location%2Csensing.type%2Csensing.window%2Cproperty.domain%2Cproperty.quality%2Cpublisher.bimId&bmsId=bacnet%3A%2F%2F04010306.AV1")
}
if($tArray.Contains("2")) {
Request "2a: All DPs according to strict criteria + grouping" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId&grouping=scope.floor&type=Input&source.type=TemperatureSensor&source.location=S01B04&scope.type=Room&property.domain=Air&property.quality=temperature")
Request "2b: The same query as above, different building" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId&grouping=scope.floor&type=Input&source.type=TemperatureSensor&source.location=S02B04&scope.type=Room&property.domain=Air&property.quality=temperature")
Request "2" "All DPs according to strict criteria + grouping" $auth ($Server + "datapoints/?fields=bmsId&grouping=scope.floor&type=Input&source.type=TemperatureSensor&source.location=S01B04&scope.type=Room&property.domain=Air&property.quality=temperature")
Request "2" "The same query as above, different building" $auth ($Server + "datapoints/?fields=bmsId&grouping=scope.floor&type=Input&source.type=TemperatureSensor&source.location=S02B04&scope.type=Room&property.domain=Air&property.quality=temperature")
}
if($tArray.Contains("3")) {
Request "3: Generic query with large number of results + grouping" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId&grouping=scope.building&source.type=HumiditySensor&property.domain=Air")
Request "3" "Generic query with large number of results + grouping" $auth ($Server + "datapoints/?fields=bmsId&grouping=scope.building&source.type=HumiditySensor&property.domain=Air")
}
if($tArray.Contains("4")) {
Request "4: Generic query with large number of results + datapoint type + grouping" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId%2Ctype%2Cscope.bimId&grouping=scope.building&source.type=TemperatureSensor&property.domain=Air&property.quality=temperature")
Request "4" "Generic query with large number of results + datapoint type + grouping" $auth ($Server + "datapoints/?fields=bmsId%2Ctype%2Cscope.bimId&grouping=scope.building&source.type=TemperatureSensor&property.domain=Air&property.quality=temperature")
}
if($tArray.Contains("5")) {
Request "5: Generic query with large number of results + all available information + grouping" $auth ($Server + "/sbms/semantics/datapoints/?fields=bmsId%2Ctype%2Csource.bimId%2Csource.type%2Csource.location%2Cscope.bimId%2Cscope.type%2Cscope.location%2Csensing.type%2Csensing.window%2Cproperty.domain%2Cproperty.quality%2Cpublisher.bimId&grouping=scope.building&source.type=TemperatureSensor&property.domain=Air&property.quality=temperature")
Request "5" "Generic query with large number of results + all available information + grouping" $auth ($Server + "datapoints/?fields=bmsId%2Ctype%2Csource.bimId%2Csource.type%2Csource.location%2Cscope.bimId%2Cscope.type%2Cscope.location%2Csensing.type%2Csensing.window%2Cproperty.domain%2Cproperty.quality%2Cpublisher.bimId&grouping=scope.building&source.type=TemperatureSensor&property.domain=Air&property.quality=temperature")
}
}
if($ManageTomcat) {
Pause
& $TomcatHome\bin\shutdown.bat
......
[CmdletBinding()]
Param([switch]$ManageTomcat,
[String]$TomcatHome = "\apache-tomcat",
[String]$User = "admin",
[String]$Pass = "nimda",
[String]$Server = "http://localhost:8080/sbms/semantics/",
[String]$Query = "types/type"
)
Function Get-Auth($user, $pass) {
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
return @{ Authorization = $basicAuthValue }
}
$r = Invoke-WebRequest -Method Get -URI ($Server + $Query) -Headers (Get-Auth $User $Pass)
$r.StatusCode
$r.Content
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment