Commit ff5a6f74 authored by Oleh Astappiev's avatar Oleh Astappiev
Browse files

Update test, add another way to count results. Add another way to retrieve results.

parent 7084bb2a
......@@ -41,7 +41,7 @@ public class DatabaseLogger {
public DatabaseLogger(ProbeType probeType, String comment) throws SQLException {
databaseManager = new DatabaseManager();
databaseManager.getConnection().setAutoCommit(false);
insertStatement = databaseManager.prepareStatement("INSERT INTO request (probe_id, request_type, value, execution_time, results_count) VALUES (?, ?, ?, ?, ?);");
insertStatement = databaseManager.prepareStatement("INSERT INTO request (probe_id, request_type, value, execution_time, count_distinct, count_total) VALUES (?, ?, ?, ?, ?, ?);");
this.probeType = probeType;
this.comment = comment;
......@@ -52,6 +52,10 @@ public class DatabaseLogger {
}
public Integer logRequest(RequestTypes requestTypes, String value, long executionTime, int resultsCount) throws SQLException {
return logRequest(requestTypes, value, executionTime, resultsCount, resultsCount);
}
public Integer logRequest(RequestTypes requestTypes, String value, long executionTime, int distinctResults, int totalResults) throws SQLException {
if (probeId == null) {
createProbe(probeType, comment);
}
......@@ -60,7 +64,8 @@ public class DatabaseLogger {
insertStatement.setString(2, requestTypes.name());
insertStatement.setString(3, truncate(value, 1000));
insertStatement.setLong(4, executionTime);
insertStatement.setInt(5, resultsCount);
insertStatement.setInt(5, distinctResults);
insertStatement.setInt(6, totalResults);
insertStatement.addBatch();
return null;
......
......@@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger;
import java.io.File;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
......@@ -21,7 +22,7 @@ public class Runner {
private static DatabaseLogger databaseLogger;
public static void main(String[] args) throws SQLException {
shsClient = new SHSClient();
shsClient = new SHSClient("node28.ib");
databaseLogger = new DatabaseLogger(DatabaseLogger.ProbeType.shs, null);
logger.info("Starting task...");
......@@ -79,10 +80,10 @@ public class Runner {
if (retUid != null && retUid >= 0) {
// logger.info("Uid for {} retrieved {}", url, retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.uid, url, endTime - startTime);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.uid, url, endTime - startTime, 1);
} else {
// logger.info("Can't get uid for url {}", url);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.uid, url, endTime - startTime, 0);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.uid, url, endTime - startTime, 0, 0);
}
}
......@@ -93,7 +94,7 @@ public class Runner {
if (retUrl != null) {
// logger.info("Url for {} retrieved {}", retUid, retUrl);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.url, retUid.toString(), endTime - startTime);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.url, retUid.toString(), endTime - startTime, 1);
} else {
logger.warn("Can't get url for uid {}", retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.url, retUid.toString(), endTime - startTime, 0);
......@@ -105,23 +106,73 @@ public class Runner {
if (retIn != null) {
// logger.info("Retrieved {} incoming links for {}", retIn.size(), retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.in, retUid.toString(), endTime - startTime, retIn.size());
databaseLogger.logRequest(DatabaseLogger.RequestTypes.in, retUid.toString(), endTime - startTime, retIn.size(), countTotalResults(retIn));
} else {
logger.warn("Can't get incoming for uid {}", retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.in, retUid.toString(), endTime - startTime, 0);
}
startTime = System.nanoTime();
long[][] retInCap = shsClient.getAllCaptures(retUid, Direction.BACKWARD);
endTime = System.nanoTime();
if (retInCap != null) {
// logger.info("Retrieved {} incoming links for {}", retInCap.length, retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.in_cap, retUid.toString(), endTime - startTime, countDistinctResults(retInCap), countTotalResults(retInCap));
} else {
logger.warn("Can't get incoming for uid {}", retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.in_cap, retUid.toString(), endTime - startTime, 0);
}
startTime = System.nanoTime();
long[][] retOutCap = shsClient.getAllCaptures(retUid, Direction.FORWARD);
endTime = System.nanoTime();
if (retOutCap != null) {
// logger.info("Retrieved {} outgoing links for {}", retOutCap.length, retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.out_cap, retUid.toString(), endTime - startTime, countDistinctResults(retOutCap), countTotalResults(retOutCap));
} else {
logger.warn("Can't get outgoing for uid {}", retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.out_cap, retUid.toString(), endTime - startTime, 0);
}
startTime = System.nanoTime();
Map<Long, List<Long>> retOut = shsClient.getAllCapturesGroupByLinks(retUid, Direction.FORWARD);
endTime = System.nanoTime();
if (retOut != null) {
// logger.info("Retrieved {} outgoing links for {}", retOut.size(), retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.out, retUid.toString(), endTime - startTime, retOut.size());
databaseLogger.logRequest(DatabaseLogger.RequestTypes.out, retUid.toString(), endTime - startTime, retOut.size(), countTotalResults(retOut));
} else {
logger.warn("Can't get outgoing for uid {}", retUid);
databaseLogger.logRequest(DatabaseLogger.RequestTypes.out, retUid.toString(), endTime - startTime, 0);
}
}
}
private static int countDistinctResults(long[][] results) {
HashSet<Long> links = new HashSet<>();
for (long[] array : results) {
for (int i = 1, l = array.length; i < l; ++i) {
links.add(array[i]);
}
}
return links.size();
}
private static int countTotalResults(long[][] results) {
int total = 0;
for (long[] array : results) {
total += array.length - 1;
}
return total;
}
private static int countTotalResults(Map<Long, List<Long>> results) {
int total = 0;
for (List<Long> array : results.values()) {
total += array.size();
}
return total;
}
}
Markdown is supported
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