[New] Adding bulk performance test

This commit is contained in:
Robert von Burg 2018-03-12 09:10:04 +01:00
parent 1845630578
commit 68c3814f1f
7 changed files with 110 additions and 55 deletions

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch> * Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -44,11 +44,16 @@ public class PerformancePostgreSqlTest extends PerformanceTest {
@Test @Test
public void runPerformanceTestCached() { public void runPerformanceTestCached() {
runPerformanceTest("cached"); runPerformanceTest("cached", 1);
}
@Test
public void runPerformanceTestBulk() {
runPerformanceTest("cached", 20);
} }
@Test @Test
public void runParallelPerformanceTest() { public void runParallelPerformanceTest() {
runParallelPerformanceTest("cached"); runParallelPerformanceTest("cached", 1);
} }
} }

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch> * Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -45,12 +45,17 @@ public class PerformancePostgreVersioningSqlTest extends PerformanceTest {
@Test @Test
public void runPerformanceTestCached() { public void runPerformanceTestCached() {
runPerformanceTest("cached"); runPerformanceTest("cached", 1);
}
@Test
public void runPerformanceTestBulk() {
runPerformanceTest("cached", 20);
} }
@Test @Test
@Ignore @Ignore
public void runParallelPerformanceTest() { public void runParallelPerformanceTest() {
runParallelPerformanceTest("cached"); runParallelPerformanceTest("cached", 1);
} }
} }

View File

@ -31,8 +31,10 @@ public abstract class PerformanceTest {
return runtimeMock; return runtimeMock;
} }
protected PerformanceTestArgument argInstance() { protected PerformanceTestArgument argInstance(int nrOfElements) {
return new PerformanceTestArgument(); PerformanceTestArgument arg = new PerformanceTestArgument();
arg.nrOfElements = nrOfElements;
return arg;
} }
public static void buildRuntime(String sourcePath, String targetPath) { public static void buildRuntime(String sourcePath, String targetPath) {
@ -73,13 +75,16 @@ public abstract class PerformanceTest {
Driver.deregister(); Driver.deregister();
} }
protected void runPerformanceTest(String username) { protected void runPerformanceTest(String username, int nrOfElements) {
Certificate certificate = runtime().getPrivilegeHandler().authenticate(username, username.toCharArray()); Certificate certificate = runtime().getPrivilegeHandler().authenticate(username, username.toCharArray());
ServiceHandler svcHandler = runtime().getServiceHandler(); ServiceHandler svcHandler = runtime().getServiceHandler();
svcHandler.doService(certificate, new PerformanceTestService(), argInstance()); PerformanceTestResult svcResult = svcHandler
.doService(certificate, new PerformanceTestService(), argInstance(nrOfElements));
if (svcResult.isNok())
throw new IllegalStateException("Performance test failed", svcResult.getThrowable());
} }
protected void runParallelPerformanceTest(String username) { protected void runParallelPerformanceTest(String username, int nrOfElements) {
int nrOfTasks = 5; int nrOfTasks = 5;
@ -88,7 +93,7 @@ public abstract class PerformanceTest {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<ForkJoinTask<Long>> tasks = new ArrayList<>(); List<ForkJoinTask<Long>> tasks = new ArrayList<>();
for (int i = 0; i < nrOfTasks; i++) { for (int i = 0; i < nrOfTasks; i++) {
PerformanceTask task = new PerformanceTask(username); PerformanceTask task = new PerformanceTask(username, nrOfElements);
tasks.add(task); tasks.add(task);
commonPool.execute(task); commonPool.execute(task);
} }
@ -113,15 +118,20 @@ public abstract class PerformanceTest {
public class PerformanceTask extends ForkJoinTask<Long> { public class PerformanceTask extends ForkJoinTask<Long> {
private String username; private String username;
private long nrOfTxs; private int nrOfElements;
private PerformanceTestResult svcResult;
public PerformanceTask(String username) { public PerformanceTask(String username, int nrOfElements) {
this.username = username; this.username = username;
this.nrOfElements = nrOfElements;
} }
@Override @Override
public Long getRawResult() { public Long getRawResult() {
return this.nrOfTxs; if (this.svcResult == null)
return 0L;
else
return this.svcResult.getNrOfTxs();
} }
@Override @Override
@ -135,11 +145,11 @@ public abstract class PerformanceTest {
Certificate certificate = runtime().getPrivilegeHandler() Certificate certificate = runtime().getPrivilegeHandler()
.authenticate(username, this.username.toCharArray()); .authenticate(username, this.username.toCharArray());
ServiceHandler svcHandler = runtime().getServiceHandler(); ServiceHandler svcHandler = runtime().getServiceHandler();
PerformanceTestResult svcResult = svcHandler this.svcResult = svcHandler.doService(certificate, new PerformanceTestService(), argInstance(nrOfElements));
.doService(certificate, new PerformanceTestService(), new PerformanceTestArgument());
runtime().getPrivilegeHandler().invalidate(certificate); runtime().getPrivilegeHandler().invalidate(certificate);
this.nrOfTxs = svcResult.getNrOfTxs(); if (this.svcResult.isNok())
throw new IllegalStateException("Task failed!", this.svcResult.getThrowable());
return true; return true;
} }

View File

@ -8,4 +8,5 @@ public class PerformanceTestArgument extends ServiceArgument {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public long duration = 15; public long duration = 15;
public TimeUnit unit = TimeUnit.SECONDS; public TimeUnit unit = TimeUnit.SECONDS;
public int nrOfElements = 1;
} }

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch> * Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,13 +15,18 @@
*/ */
package li.strolch.performance; package li.strolch.performance;
import static li.strolch.model.ModelGenerator.BAG_ID;
import static li.strolch.model.ModelGenerator.PARAM_STRING_ID;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import li.strolch.agent.api.StrolchAgent; import li.strolch.agent.api.StrolchAgent;
import li.strolch.model.ModelGenerator; import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource; import li.strolch.model.Resource;
import li.strolch.persistence.api.AddResourceCommand; import li.strolch.model.parameter.StringParameter;
import li.strolch.persistence.api.RemoveResourceCommand;
import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService; import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceResultState; import li.strolch.service.api.ServiceResultState;
@ -61,17 +66,50 @@ public class PerformanceTestService extends AbstractService<PerformanceTestArgum
long allTx = 0; long allTx = 0;
long nrOfTx = 0; long nrOfTx = 0;
String resId = null; List<String> resourceIds = new ArrayList<>();
while (run(start)) { while (run(start)) {
try (StrolchTransaction tx = openUserTx()) { try (StrolchTransaction tx = openUserTx()) {
if (resId != null) { if (resourceIds.isEmpty()) {
Resource toDelete = queryResource(tx, resId); for (int i = 0; i < arg.nrOfElements; i++) {
deleteResource(tx, toDelete); resourceIds.add(createResource(tx));
}
} else {
if (resourceIds.size() > 10) {
int removeTo = resourceIds.size() / 3;
int updateTo = (resourceIds.size() / 3) * 2;
// we have many, so update some, change some, create some
List<String> toRemove = new ArrayList<>(resourceIds.subList(0, removeTo));
List<String> toUpdate = new ArrayList<>(resourceIds.subList(removeTo, updateTo));
resourceIds.removeAll(toRemove);
for (String resourceId : toRemove) {
tx.remove(tx.getResourceBy(MY_TYPE, resourceId, true));
}
for (String resourceId : toUpdate) {
Resource resource = tx.getResourceBy(MY_TYPE, resourceId, true);
StringParameter stringP = resource.getParameter(BAG_ID, PARAM_STRING_ID);
stringP.setValue("Yellow!");
tx.update(resource);
}
for (int i = 0; i < removeTo; i++) {
resourceIds.add(createResource(tx));
}
} else {
for (Iterator<String> iterator = resourceIds.iterator(); iterator.hasNext(); ) {
String resourceId = iterator.next();
tx.remove(tx.getResourceBy(MY_TYPE, resourceId, true));
iterator.remove();
}
}
} }
resId = createResource(tx);
tx.commitOnClose(); tx.commitOnClose();
} }
@ -101,24 +139,10 @@ public class PerformanceTestService extends AbstractService<PerformanceTestArgum
return System.currentTimeMillis() < start + this.arg.unit.toMillis(this.arg.duration); return System.currentTimeMillis() < start + this.arg.unit.toMillis(this.arg.duration);
} }
private void deleteResource(StrolchTransaction tx, Resource toDelete) {
RemoveResourceCommand cmd = new RemoveResourceCommand(getContainer(), tx);
cmd.setResource(toDelete);
tx.addCommand(cmd);
}
private Resource queryResource(StrolchTransaction tx, String resId) {
return tx.getResourceBy(MY_TYPE, resId);
}
private String createResource(StrolchTransaction tx) { private String createResource(StrolchTransaction tx) {
String id = StrolchAgent.getUniqueId(); String id = StrolchAgent.getUniqueId();
Resource resource = ModelGenerator.createResource(id, id, MY_TYPE); Resource resource = ModelGenerator.createResource(id, id, MY_TYPE);
tx.add(resource);
AddResourceCommand cmd = new AddResourceCommand(getContainer(), tx); return resource.getId();
cmd.setResource(resource);
tx.addCommand(cmd);
return id;
} }
} }

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch> * Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -39,11 +39,16 @@ public class PerformanceTransientTest extends PerformanceTest {
@Test @Test
public void runPerformanceTest() { public void runPerformanceTest() {
runPerformanceTest("transient"); runPerformanceTest("transient", 1);
}
@Test
public void runPerformanceTestBulk() {
runPerformanceTest("transient", 20);
} }
@Test @Test
public void runParallelPerformanceTest() { public void runParallelPerformanceTest() {
runParallelPerformanceTest("transient"); runParallelPerformanceTest("transient", 1);
} }
} }

View File

@ -39,11 +39,16 @@ public class PerformanceXmlTest extends PerformanceTest {
@Test @Test
public void runPerformanceTestCached() { public void runPerformanceTestCached() {
runPerformanceTest("cached"); runPerformanceTest("cached", 1);
}
@Test
public void runPerformanceTestBulk() {
runPerformanceTest("cached", 20);
} }
@Test @Test
public void runParallelPerformanceTest() { public void runParallelPerformanceTest() {
runParallelPerformanceTest("cached"); runParallelPerformanceTest("cached", 1);
} }
} }