Parallel execution and added core submodule

This commit is contained in:
Andrea Cavalli 2019-04-20 16:03:50 +02:00
parent 641233af3e
commit 78bcb67c67
6 changed files with 43 additions and 22 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "strangedb-core"]
path = strangedb-core
url = ssh://git@git.ignuranza.net:5003/andreacavalli/strangedb-core.git

View File

@ -63,7 +63,7 @@ public abstract class StrangeDbList<T> extends EnhancedObject implements Element
protected void forEachParallelUnsorted_(ConsumerWithIO<T> action) throws IOException {
try {
int size = size();
ExecutorService executorService = Executors.newFixedThreadPool(16, (r) -> new Thread(r, "StrangeDbList.forEachParallelUnsorted worker"));
ExecutorService executorService = ForkJoinPool.commonPool();
VariableWrapper<IOException> exceptionVariableWrapper = new VariableWrapper<>(null);
for (int i = 0; i < size; i++) {
final int index = i;

View File

@ -8,6 +8,7 @@ import it.cavallium.strangedb.java.objects.lists.EnhancedObjectStrangeDbList;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.*;
public class ListContainer extends EnhancedObject {
@ -21,12 +22,15 @@ public class ListContainer extends EnhancedObject {
super(databaseTools);
this.usersList = new EnhancedObjectStrangeDbList<>(databaseTools, User.class);
Random random = new Random();
ExecutorService threadPool = ForkJoinPool.commonPool();
for (int i = 0; i < count; i++) {
threadPool.execute(() -> {
try {
User usr;
int randomInt = random.nextInt(2);
switch (randomInt) {
case 0:
usr = new User(databaseTools, "Rossi" + count + "Mario"+count, "the" + count + "_mariorossi99", "Long long big " + count + " giant bio mario rossi 99 abcdefghijklmnopqrstuvwxyz");
usr = new User(databaseTools, "Rossi" + count + "Mario" + count, "the" + count + "_mariorossi99", "Long long big " + count + " giant bio mario rossi 99 abcdefghijklmnopqrstuvwxyz");
break;
case 1:
usr = new User(databaseTools, QueryTests.constantFirstName, QueryTests.constantUsername, QueryTests.constantBio);
@ -38,6 +42,16 @@ public class ListContainer extends EnhancedObject {
throw new ArrayIndexOutOfBoundsException();
}
this.usersList.add(usr);
} catch (IOException ex) {
throw new CompletionException(ex);
}
});
}
threadPool.shutdown();
try {
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
throw new IOException(e);
}
}

View File

@ -62,7 +62,6 @@ public class Performance {
testS("DatabaseCore root creation", 300, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer::new), () -> {});
final VariableWrapper<PreloadedListContainer> preloadedListContainer = new VariableWrapper<>(null);
final VariableWrapper<SimpleEnhancedObject> simpleEnhancedObjectContainer = new VariableWrapper<>(null);
/*
testS("ObjectStrangeDbList<Int> creation", 3000, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
@ -184,7 +183,6 @@ public class Performance {
}, () -> {
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), () -> {

View File

@ -1,6 +1,7 @@
package it.cavallium.strangedb.tests;
import it.cavallium.strangedb.java.database.DatabaseJava;
import it.cavallium.strangedb.java.objects.lists.ElementsArrayList;
import it.cavallium.strangedb.java.objects.lists.ListQuery;
import it.cavallium.strangedb.java.objects.lists.ValuePointer;
import it.cavallium.strangedb.java.objects.lists.operations.Equals;
@ -31,17 +32,21 @@ public class QueryTests {
path2 = Files.createTempFile("db-tests-blocks-", ".db");
path3 = Files.createTempFile("db-tests-references-", ".db");
db = new DatabaseJava(path1, path2, path3);
int i = 0;
db.getObjectsIO().registerClass(UserFullInfo.class, i++);
db.getObjectsIO().registerClass(User.class, i++);
db.getObjectsIO().registerClass(ListContainer.class, i++);
}
@Test
public void shouldCreateListAndQuery() throws IOException {
ListContainer root = db.loadRoot((db) -> new ListContainer(db, 1000));
ListContainer root = db.loadRoot((db) -> new ListContainer(db, 2000));
ListQuery query = ListQuery.create(ValuePointer.ofField(User.class, "firstName"), Equals.to(constantFirstName))
.and(ValuePointer.ofField(User.class, "username"), Equals.to(constantUsername))
.and(ValuePointer.ofField(User.class, "fullInfo").field(UserFullInfo.class, "bio"), Equals.to(constantBio));
long time1 = System.currentTimeMillis();
ArrayList<User> elements = root.usersList.query(query).asList();
System.out.println("Time elapsed: " + (System.currentTimeMillis() - time1));
ElementsArrayList<User> elements = root.usersList.query(query);
System.out.println("Time elapsed: " + String.format("%.2f", (System.currentTimeMillis() - time1) / 1000d) + " seconds");
System.out.println("Found " + elements.size() + " elements. First 5 items:");
assertNotEquals(elements.size(), 0);
for (int i = 0; i < (elements.size() > 10 ? 10 : elements.size()); i++) {

1
strangedb-core Submodule

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