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

Testing performance of external graph usage - performance patch #377

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9234b50
Adding the variable display
michel-heon Feb 22, 2023
50d0595
Change project.version to 1.14.1-SNAPSHOT
michel-heon Feb 22, 2023
3a43423
Adding an echo mechanism for properties
michel-heon Feb 22, 2023
59fa166
This code segment is compatible with Java 11 and not compatible with
michel-heon Feb 22, 2023
def3890
""
michel-heon Feb 22, 2023
7896a33
Replacing
michel-heon Feb 22, 2023
453006c
Add code to install (wget) samples-i18n in /vivo/home/rdf/abox/filegraph
michel-heon Feb 23, 2023
a3d03cb
Added jena version management mechanism and owl-api
michel-heon Feb 23, 2023
9fc52e7
Update pom.xml
michel-heon Feb 25, 2023
1c7dde2
Update pom.xml
michel-heon Feb 25, 2023
8ebc531
Update pom.xml
michel-heon Feb 25, 2023
85d558e
Update pom.xml
michel-heon Feb 25, 2023
46a5149
Update pom.xml
michel-heon Feb 25, 2023
ef11d69
Update pom.xml
michel-heon Feb 25, 2023
271978b
Update pom.xml
michel-heon Feb 25, 2023
1c2564d
Update pom.xml
michel-heon Feb 25, 2023
42f31dd
Update pom.xml
michel-heon Feb 25, 2023
27725b0
Update pom.xml
michel-heon Feb 25, 2023
dbd162e
Update pom.xml
michel-heon Feb 25, 2023
3d5b754
Updated enforcer-version to (3.2.1) to be compatible with VIVO pom's -
michel-heon Feb 27, 2023
71cd81f
Merge remote-tracking branch 'origin/infrastructure-improvements' into
michel-heon Feb 27, 2023
40cc22a
Replacing tab by spaces
michel-heon Mar 2, 2023
a4cd53d
Replace tab with spaces
michel-heon Mar 2, 2023
823416e
Reformat tab to spaces
michel-heon Mar 3, 2023
a18e39e
Cleaning code
michel-heon Mar 3, 2023
7dae837
Makes the query more generic
michel-heon Mar 4, 2023
2380734
Added multi-threaded processing and reduced number of individuals to
michel-heon Mar 4, 2023
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
41 changes: 35 additions & 6 deletions api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand All @@ -18,9 +15,41 @@
</parent>

<name>Vitro API</name>

<build>
<plugins>
<plugin>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General note: please remove changes not specific to this PR. There are a lot of modifications from other PR that aren't necessary here.

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>echo-properties</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<skip>false</skip>
<target>
<echo message="###################################################################" />
<echo message="Displaying value of '${project.artifactId}' properties" />
<echo message="###################################################################" />
<echo message="[vitro-version] ${vitro-version}" />
<echo message="[vivo-version] ${vivo-version}" />
<echo message="[vivo-dir] ${vivo-dir}" />
<echo message="[project.version] ${project.version}" />
<echo message="[java.vendor.version] ${java.vendor.version}" />
<echo message="[java.version] ${java.version}" />
<echo message="[java.specification.version] ${java.specification.version}" />
<echo message="[maven.compiler.release] ${maven.compiler.release}" />
<echo message="[skip-samples-install] ${skip-samples-install}" />
<echo message="###################################################################" />
<echo message="###################################################################" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -108,4 +137,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -20,70 +23,118 @@
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup;

/**
* Does a search for individuals, and uses the short view to render each of
* the results.
* Does a search for individuals, and uses the short view to render each of the
* results.
*/
public class GetRenderedSearchIndividualsByVClass extends GetSearchIndividualsByVClasses {
private static final Log log = LogFactory
.getLog(GetRenderedSearchIndividualsByVClass.class);
private static final Log log = LogFactory.getLog(GetRenderedSearchIndividualsByVClass.class);

protected GetRenderedSearchIndividualsByVClass(VitroRequest vreq) {
super(vreq);
}
protected GetRenderedSearchIndividualsByVClass(VitroRequest vreq) {
super(vreq);
}

/**
* Search for individuals by VClass or VClasses in the case of multiple parameters. The class URI(s) and the paging
* information are in the request parameters.
*/
@Override
protected ObjectNode process() throws Exception {
ObjectNode rObj = null;
/**
* Search for individuals by VClass or VClasses in the case of multiple
* parameters. The class URI(s) and the paging information are in the request
* parameters.
*/
@Override
protected ObjectNode process() throws Exception {
ObjectNode rObj = null;

//This gets the first vclass value and sets that as display type
List<String> vclassIds = super.getVclassIds(vreq);
String vclassId = null;
if(vclassIds.size() > 1) {
//This ensures the second class instead of the first
//This is a temporary fix in cases where institutional internal classes are being sent in
//and thus the second class is the actual class with display information associated
vclassId = vclassIds.get(1);
} else {
vclassId = vclassIds.get(0);
}
vreq.setAttribute("displayType", vclassId);
// This gets the first vclass value and sets that as display type
List<String> vclassIds = super.getVclassIds(vreq);
String vclassId = null;
if (vclassIds.size() > 1) {
// This ensures the second class instead of the first
// This is a temporary fix in cases where institutional internal classes are
// being sent in
// and thus the second class is the actual class with display information
// associated
vclassId = vclassIds.get(1);
} else {
vclassId = vclassIds.get(0);
}
vreq.setAttribute("displayType", vclassId);

//This will get all the solr individuals by VClass (if one value) or the intersection
//i.e. individuals that have all the types for the different vclasses entered
rObj = super.process();
addShortViewRenderings(rObj);
return rObj;
}
// This will get all the solr individuals by VClass (if one value) or the
// intersection
// i.e. individuals that have all the types for the different vclasses entered
rObj = super.process();
addShortViewRenderings(rObj);
return rObj;
}

/**
* Look through the return object. For each individual, render the short
* view and insert the resulting HTML into the object.
*/
private void addShortViewRenderings(ObjectNode rObj) {
ArrayNode individuals = (ArrayNode) rObj.get("individuals");
String vclassName = rObj.get("vclass").get("name").asText();
for (int i = 0; i < individuals.size(); i++) {
ObjectNode individual = (ObjectNode) individuals.get(i);
individual.put("shortViewHtml",
renderShortView(individual.get("URI").asText(), vclassName));
}
}
/**
* Look through the return object. For each individual, render the short view
* and insert the resulting HTML into the object.
* ORIGINAL CODE
* This code segment is never called.
* It is kept for the time being for performance comparison tests.
* It should be deleted when PR is accepted.
*/
private void addShortViewRenderings_ORIG(ObjectNode rObj) {
ArrayNode individuals = (ArrayNode) rObj.get("individuals");
String vclassName = rObj.get("vclass").get("name").asText();
for (int i = 0; i < individuals.size(); i++) {
ObjectNode individual = (ObjectNode) individuals.get(i);
individual.put("shortViewHtml", renderShortView(individual.get("URI").asText(), vclassName));
}
}

private String renderShortView(String individualUri, String vclassName) {
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
Individual individual = iDao.getIndividualByURI(individualUri);
/**
* Look through the return object. For each individual, render the short view
* and insert the resulting HTML into the object.
* The use of multi treading allows to submit the requests and the processing in
* parallel of the necessary elements to the html objects of the page.
* Parallel processing allows to use the network bandwidth to the maximum
*/
private void addShortViewRenderings(ObjectNode rObj) {

Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("individual",
IndividualTemplateModelBuilder.build(individual, vreq));
modelMap.put("vclass", vclassName);
ArrayNode individuals = (ArrayNode) rObj.get("individuals");
String vclassName = rObj.get("vclass").get("name").asText();
int indvSize = individuals.size();
ExecutorService es = Executors.newFixedThreadPool(indvSize);
for (int i = 0; i < indvSize; i++) {
ObjectNode individual = (ObjectNode) individuals.get(i);
ProcessIndividual pi = new ProcessIndividual();
pi.setIndividual(individual);
pi.setVclassName(vclassName);
es.execute(pi);
}
es.shutdown();
try {
while(!es.awaitTermination(250, TimeUnit.MILLISECONDS)){
}
} catch (InterruptedException e1) {
}
}
private class ProcessIndividual implements Runnable {
private ObjectNode individual = null;
private String vclassName;
public String getVclassName() {
return vclassName;
}
public void setVclassName(String vclassName) {
this.vclassName = vclassName;
}
// Method
public void run() {
individual.put("shortViewHtml", renderShortView(individual.get("URI").asText(), vclassName));
}
public void setIndividual(ObjectNode individual) {
this.individual = individual;
}
}
private String renderShortView(String individualUri, String vclassName) {
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
Individual individual = iDao.getIndividualByURI(individualUri);

ShortViewService svs = ShortViewServiceSetup.getService(ctx);
return svs.renderShortView(individual, ShortViewContext.BROWSE,
modelMap, vreq);
}
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("individual", IndividualTemplateModelBuilder.build(individual, vreq));
modelMap.put("vclass", vclassName);

ShortViewService svs = ShortViewServiceSetup.getService(ctx);
return svs.renderShortView(individual, ShortViewContext.BROWSE, modelMap, vreq);
}
}
Loading