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 { protected void forEachParallelUnsorted_(ConsumerWithIO<T> action) throws IOException {
try { try {
int size = size(); 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); VariableWrapper<IOException> exceptionVariableWrapper = new VariableWrapper<>(null);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final int index = 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.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.*;
public class ListContainer extends EnhancedObject { public class ListContainer extends EnhancedObject {
@ -21,23 +22,36 @@ public class ListContainer extends EnhancedObject {
super(databaseTools); super(databaseTools);
this.usersList = new EnhancedObjectStrangeDbList<>(databaseTools, User.class); this.usersList = new EnhancedObjectStrangeDbList<>(databaseTools, User.class);
Random random = new Random(); Random random = new Random();
ExecutorService threadPool = ForkJoinPool.commonPool();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
User usr; threadPool.execute(() -> {
int randomInt = random.nextInt(2); try {
switch (randomInt) { User usr;
case 0: int randomInt = random.nextInt(2);
usr = new User(databaseTools, "Rossi" + count + "Mario"+count, "the" + count + "_mariorossi99", "Long long big " + count + " giant bio mario rossi 99 abcdefghijklmnopqrstuvwxyz"); switch (randomInt) {
break; case 0:
case 1: 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, QueryTests.constantFirstName, QueryTests.constantUsername, QueryTests.constantBio); break;
break; case 1:
case 2: usr = new User(databaseTools, QueryTests.constantFirstName, QueryTests.constantUsername, QueryTests.constantBio);
usr = new User(databaseTools, QueryTests.constantFirstName, "b" + count + "a", QueryTests.constantBio); break;
break; case 2:
default: usr = new User(databaseTools, QueryTests.constantFirstName, "b" + count + "a", QueryTests.constantBio);
throw new ArrayIndexOutOfBoundsException(); break;
} default:
this.usersList.add(usr); 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), () -> {}); 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, () -> { testS("ObjectStrangeDbList<Int> creation", 3000, () -> {
regenDb(); regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new);
@ -184,7 +183,6 @@ public class Performance {
}, () -> { }, () -> {
preloadedListContainer.var.list.size(); preloadedListContainer.var.list.size();
}, () -> {}); }, () -> {});
*/
for (int items = 1000; items <= 100000; items *= 10) { for (int items = 1000; items <= 100000; items *= 10) {
final int itemsF = items; final int itemsF = items;
testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> { testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> {

View File

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

1
strangedb-core Submodule

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