Flush executor

This commit is contained in:
Andrea Cavalli 2019-04-20 22:19:07 +02:00
parent debe1f70bb
commit b34af24e33
2 changed files with 207 additions and 170 deletions

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
public class Performance { public class Performance {
private static boolean FAST_TESTS; private static int DIVISOR;
private static Path rootDirectory; private static Path rootDirectory;
private static Path dbDataFile; private static Path dbDataFile;
@ -32,6 +32,21 @@ public class Performance {
private static Path dbReferencesFile; private static Path dbReferencesFile;
private static DatabaseJava db; private static DatabaseJava db;
private static boolean tempDirectory; private static boolean tempDirectory;
private static final int BASE_WIDTH = 35;
private static final int SPACE_WIDTH = BASE_WIDTH + 35;
private static String spaces = "";
private static String bars = "";
private static boolean doFillTests;
private static boolean doLoadTests;
private static boolean doQueryTests;
private static boolean doInstantiationTests;
static {
for (int i = 0; i < SPACE_WIDTH; i++) {
spaces += " ";
bars += "-";
}
}
/** /**
* *
@ -40,13 +55,27 @@ public class Performance {
* @throws InterruptedException * @throws InterruptedException
*/ */
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
FAST_TESTS = args.length > 0 && args[0].equalsIgnoreCase("true"); DIVISOR = args.length > 0 ? Integer.parseInt(args[0]) : 1;
if (args.length >= 2) { if (args.length >= 2) {
rootDirectory = Paths.get(args[1]); doQueryTests =
try { args[1].contains("query");
doFillTests =
args[1].contains("fill");
doLoadTests =
args[1].contains("load");
doInstantiationTests =
args[1].contains("new");
if (args[1].contains("all")) {
doQueryTests = true;
doFillTests = true;
doLoadTests = true;
doInstantiationTests = true;
}
}
if (args.length >= 3) {
rootDirectory = Paths.get(args[2]);
if (Files.notExists(rootDirectory)) {
Files.createDirectory(rootDirectory); Files.createDirectory(rootDirectory);
} catch (Exception ex) {
} }
tempDirectory = false; tempDirectory = false;
} else { } else {
@ -55,166 +84,176 @@ public class Performance {
} }
generateDb(); generateDb();
System.out.println("Performance test started."); System.out.println("Performance test started.");
System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); System.out.println(bars + "---------------+-----------------------------------------------------------------");
System.out.println("Test name Total Time | Time at 1 Time at 10 Time at 100 Time at 1K Time at 10K"); System.out.println("Test name" + spaces.substring(0, spaces.length() - 5) + "Total Time | Time at 1 Time at 10 Time at 100 Time at 1K Time at 10K");
System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); System.out.println(bars + "---------------+-----------------------------------------------------------------");
testS("DatabaseCore creation", 300, Performance::deleteDb, Performance::generateDb, () -> {}); if (doInstantiationTests) {
testS("DatabaseCore root creation", 300, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer::new), () -> {}); testS("DatabaseCore creation", 300, Performance::deleteDb, Performance::generateDb, () -> {});
testS("DatabaseCore root creation", 300, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer::new), () -> {});
}
final VariableWrapper<PreloadedListContainer> preloadedListContainer = new VariableWrapper<>(null); final VariableWrapper<PreloadedListContainer> preloadedListContainer = new VariableWrapper<>(null);
final VariableWrapper<SimpleEnhancedObject> simpleEnhancedObjectContainer = new VariableWrapper<>(null); final VariableWrapper<SimpleEnhancedObject> simpleEnhancedObjectContainer = new VariableWrapper<>(null);
testS("ObjectStrangeDbList<Int> creation", 3000, () -> { if (doInstantiationTests) {
regenDb(); testS("ObjectStrangeDbList<Int> creation", 1000, () -> {
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
}, () -> preloadedListContainer.var.list = new ObjectStrangeDbList<>(db), () -> {});
testS("ObjectStrangeDbList<Int>: Filling with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
}, () -> {
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: Filling with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
}, () -> {
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {});
testS("ObjectStrangeDbList<Int>: Filling with 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
}, () -> {
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectStrangeDbList<Int>: Filling with 100000 items", 1, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
}, () -> {
for (int i = 0; i < 100000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectStrangeDbList<Int>: Loading 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: Loading with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {
preloadedListContainer.var.listOfEnhancedObj.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<Int>: Loading 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<Int>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.getLast();
}, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {
preloadedListContainer.var.listOfEnhancedObj.getLast();
}, () -> {});
testS("ObjectStrangeDbList<Int>: size() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.size();
}, () -> {});
for (int items = 1000; items <= 100000; items *= 10) {
final int itemsF = items;
testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> {
regenDb(); regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfMessages = new EnhancedObjectStrangeDbList<>(db); }, () -> preloadedListContainer.var.list = new ObjectStrangeDbList<>(db), () -> {});
}
Random random = new Random(); if (doFillTests) {
for (int i = 0; i < itemsF; i++) { testS("ObjectStrangeDbList<Int>: Filling with 1000 items", 100, () -> {
EMessageContent content; regenDb();
if (random.nextBoolean()) { preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
List<String> stringList = new ArrayList<>(); preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int j = 0; j < 10; j++) {
stringList.add("[entity]");
}
byte[] stringBytes = new byte[200];
random.nextBytes(stringBytes);
content = new EMessageText(db, new EFormattedText(db, new String(stringBytes, StandardCharsets.UTF_8) + (random.nextBoolean() ? "not found" : " text to find!"), stringList.toArray(new String[0])));
} else {
content = new EMessageOtherContent(db, "EMPTY ABCDEFG");
}
EMessage message = new EMessage(db, content);
preloadedListContainer.var.listOfMessages.add(message);
}
}, () -> { }, () -> {
ListQuery query = ListQuery.create( for (int i = 0; i < 1000; i++) {
ValuePointer.ofField(EMessage.class, "content").field(EMessageText.class, "text").field(EFormattedText.class, "text"), preloadedListContainer.var.list.add(1000);
ContainsIgnoreCase.containsValue("text to find")); }
ArrayList<EMessage> results = preloadedListContainer.var.listOfMessages.query(query).asList(); }, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: Filling with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
}, () -> {
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {});
testS("ObjectStrangeDbList<Int>: Filling with 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
}, () -> {
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectStrangeDbList<Int>: Filling with 100000 items", 1, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
}, () -> {
for (int i = 0; i < 100000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {}); }, () -> {});
} }
System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); if (doLoadTests) {
testS("ObjectStrangeDbList<Int>: Loading 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: Loading with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {
preloadedListContainer.var.listOfEnhancedObj.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<Int>: Loading 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {});
}, () -> {});
testS("ObjectStrangeDbList<Int>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.getLast();
}, () -> {});
testS("ObjectStrangeDbList<EnhancedObject>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
simpleEnhancedObjectContainer.var.object = new ArrayList<>();
simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY");
simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY");
simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv");
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {
preloadedListContainer.var.listOfEnhancedObj.getLast();
}, () -> {});
testS("ObjectStrangeDbList<Int>: size() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectStrangeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.size();
}, () -> {});
}
if (doQueryTests) {
for (int items = 1000; items <= 100000; items *= 10) {
final int itemsF = items;
testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
preloadedListContainer.var.listOfMessages = new EnhancedObjectStrangeDbList<>(db);
Random random = new Random();
for (int i = 0; i < itemsF; i++) {
EMessageContent content;
if (random.nextBoolean()) {
List<String> stringList = new ArrayList<>();
for (int j = 0; j < 10; j++) {
stringList.add("[entity]");
}
byte[] stringBytes = new byte[200];
random.nextBytes(stringBytes);
content = new EMessageText(db, new EFormattedText(db, new String(stringBytes, StandardCharsets.UTF_8) + (random.nextBoolean() ? "not found" : " text to find!"), stringList.toArray(new String[0])));
} else {
content = new EMessageOtherContent(db, "EMPTY ABCDEFG");
}
EMessage message = new EMessage(db, content);
preloadedListContainer.var.listOfMessages.add(message);
}
}, () -> {
ListQuery query = ListQuery.create(
ValuePointer.ofField(EMessage.class, "content").field(EMessageText.class, "text").field(EFormattedText.class, "text"),
ContainsIgnoreCase.containsValue("text to find"));
ArrayList<EMessage> results = preloadedListContainer.var.listOfMessages.query(query).asList();
}, () -> {});
}
}
System.out.println(bars + "---------------+-----------------------------------------------------------------");
System.out.println("Performance test finished."); System.out.println("Performance test finished.");
deleteDb(); deleteDb();
if (tempDirectory) { if (tempDirectory) {
@ -225,21 +264,19 @@ public class Performance {
private static void NtestS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException { private static void NtestS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException {
} }
private static void testS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException { private static void testS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException {
if (FAST_TESTS) {
if (times >= 5) { if (times >= 5 * DIVISOR) {
times /= 5; times /= 5 * DIVISOR;
} else if (times >= 2) { } else if (times >= 2 * DIVISOR) {
times /= 2; times /= 2 * DIVISOR;
}
} }
description = description + " time is"; description = description + " time is";
int spacesCount = 40 - description.length(); int spacesCount = SPACE_WIDTH - description.length();
int cutAt = 0; int cutAt = 0;
if (spacesCount < 0) { if (spacesCount < 0) {
spacesCount = 40 - (description.length() - 40); spacesCount = SPACE_WIDTH - (description.length() - SPACE_WIDTH);
cutAt = 40; cutAt = SPACE_WIDTH;
} }
StringBuilder spaces = new StringBuilder(); StringBuilder spaces = new StringBuilder();
for (int i = 0; i < spacesCount; i++) { for (int i = 0; i < spacesCount; i++) {

@ -1 +0,0 @@
Subproject commit b425e4c12901dd277f944bcf1b0b0f245d8d23b5

1
strangedb-core Symbolic link
View File

@ -0,0 +1 @@
G:/Progetti/Java/Progetti_IntelliJ_Idea/StrangeDb Core