Skip to content
Snippets Groups Projects
Commit 97988747 authored by Fuentes Serna  Juan Mariano (ID SIS)'s avatar Fuentes Serna Juan Mariano (ID SIS)
Browse files

SSDM-6064 - load testing

parent d28147a6
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@
## Introduction ##
It benchmarks openBIS, please create a sample type as show in benchmark-sample.png
\ No newline at end of file
openbis_benchmark/benchmark-sample.png

85.3 KiB

[{
"className" : "ch.ethz.sis.benchmark.impl.CreateSpacesBenchmark",
"className" : "ch.ethz.sis.benchmark.impl.GeneralBenchmark",
"user" : "admin",
"password" : "test",
"openbisURL" : "http://localhost:8888/openbis/openbis/rmi-application-server-v3",
......@@ -7,6 +7,7 @@
"datastoreURL" : "http://localhost:8889/datastore_server/rmi-data-store-server-v3",
"datastoreTimeout" : "3600000",
"parameters" : {
"SPACES_TO_CREATE" : 5000
"SPACES_TO_CREATE" : 5000,
"SAMPLES_TO_CREATE" : 50000
}
}]
\ No newline at end of file
......@@ -5,16 +5,17 @@ import ch.ethz.sis.logging.Logger;
public abstract class Benchmark
{
private BenchmarkConfig benchmarkConfig;
private static Logger logger = LogManager.getLogger(Benchmark.class);
protected BenchmarkConfig benchmarkConfig;
protected Logger logger;
public void start() {
logger = LogManager.getLogger(this.getClass());
long start = System.currentTimeMillis();
logger.traceAccess("Starting Benchmark:", benchmarkConfig);
logger.traceAccess(null, benchmarkConfig);
startInternal();
logger.traceExit(benchmarkConfig);
long end = System.currentTimeMillis();
logger.info("Benchmark took: " + (end-start) + " millis", null);
logger.info("Benchmark took: " + (end-start) + " millis");
}
public abstract void startInternal();
......
package ch.ethz.sis.benchmark.impl;
import java.util.ArrayList;
import java.util.List;
import ch.ethz.sis.benchmark.Benchmark;
import ch.ethz.sis.benchmark.util.RandomWord;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation;
import ch.systemsx.cisd.common.spring.HttpInvokerUtils;
public class CreateSpacesBenchmark extends Benchmark {
private enum Parameters { SPACES_TO_CREATE }
@Override
public void startInternal() {
IApplicationServerApi v3 = HttpInvokerUtils.createServiceStub(IApplicationServerApi.class, getConfiguration().getOpenbisURL(), getConfiguration().getOpenbisTimeout());
String sessionToken = v3.login(getConfiguration().getUser(), getConfiguration().getPassword());
int spacesToCreate = Integer.parseInt(this.getConfiguration().getParameters().get(Parameters.SPACES_TO_CREATE.name()));
List<SpaceCreation> spaceCreations = new ArrayList<SpaceCreation>();
for(int i = 0; i < spacesToCreate; i++) {
SpaceCreation spaceCreation = new SpaceCreation();
String spaceCode = "SPACE_" + RandomWord.getRandomWord() + "_" + RandomWord.getRandomWord();
spaceCreation.setCode(spaceCode);
spaceCreations.add(spaceCreation);
}
v3.createSpaces(sessionToken, spaceCreations);
}
}
package ch.ethz.sis.benchmark.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import ch.ethz.sis.benchmark.Benchmark;
import ch.ethz.sis.benchmark.util.RandomValueGenerator;
import ch.ethz.sis.benchmark.util.RandomWord;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create.SampleCreation;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create.SampleTypeCreation;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id.SpacePermId;
import ch.systemsx.cisd.common.spring.HttpInvokerUtils;
public class GeneralBenchmark extends Benchmark {
private enum Parameters { SPACES_TO_CREATE, SAMPLES_TO_CREATE }
@Override
public void startInternal() {
IApplicationServerApi v3 = HttpInvokerUtils.createServiceStub(IApplicationServerApi.class, getConfiguration().getOpenbisURL(), getConfiguration().getOpenbisTimeout());
String sessionToken = v3.login(getConfiguration().getUser(), getConfiguration().getPassword());
//
// Setup - Create Type
//
EntityTypePermId sampleTypeCode = new EntityTypePermId("BENCHMARK_OBJECT");
SampleTypeCreation sampleTypeCreation = new SampleTypeCreation();
sampleTypeCreation.setCode(sampleTypeCode.getPermId());
v3.createSampleTypes(sessionToken, Arrays.asList(sampleTypeCreation));
//
// Part 1 - Creating Spaces
//
long start1 = System.currentTimeMillis();
RandomValueGenerator<String> spaceCodes = new RandomValueGenerator<String>();
int spacesToCreate = Integer.parseInt(this.getConfiguration().getParameters().get(Parameters.SPACES_TO_CREATE.name()));
List<SpaceCreation> spaceCreations = new ArrayList<SpaceCreation>();
for(int i = 0; i < spacesToCreate; i++) {
SpaceCreation spaceCreation = new SpaceCreation();
String spaceCode = null;
while(spaceCode == null || spaceCodes.contains(spaceCode)) {
spaceCode = "SPACE_" + RandomWord.getRandomWord() + "_" + RandomWord.getRandomWord();
}
spaceCodes.add(spaceCode);
spaceCreation.setCode(spaceCode);
spaceCreations.add(spaceCreation);
}
v3.createSpaces(sessionToken, spaceCreations);
long end1 = System.currentTimeMillis();
logger.info("Create " + spacesToCreate + " Spaces took: " + (end1-start1) + " millis - " + ((end1-start1)/spacesToCreate) + " millis/space");
//
// Part 2 - Creating Samples
//
long start2 = System.currentTimeMillis();
long lapStart2 = System.currentTimeMillis();
Set<String> sampleCodes = new HashSet<String>();
int sampleBatchSize = 5000;
int samplesToCreate = Integer.parseInt(this.getConfiguration().getParameters().get(Parameters.SAMPLES_TO_CREATE.name()));
List<SampleCreation> sampleCreations = new ArrayList<SampleCreation>();
for(int i = 0; i < samplesToCreate; i++) {
SampleCreation sampleCreation = new SampleCreation();
String sampleCode = null;
while(sampleCode == null || sampleCodes.contains(sampleCode)) {
sampleCode = "SAMPLE_" + RandomWord.getRandomWord() + "_" + RandomWord.getRandomWord() + "_" + RandomWord.getRandomWord();
}
sampleCreation.setTypeId(sampleTypeCode);
sampleCreation.setCode(sampleCode);
sampleCreation.setSpaceId(new SpacePermId(spaceCodes.getRandom())); // Spaces are distributed randomly
sampleCreations.add(sampleCreation);
if(i % sampleBatchSize == 0) { // Every 5000, send to openBIS
v3.createSamples(sessionToken, sampleCreations);
long lapEnd2 = System.currentTimeMillis();
logger.info("Create " + sampleCreations.size() + " Samples took: " + (lapEnd2 - lapStart2) + " millis - " + ((lapEnd2-lapStart2)/sampleCreations.size()) + " millis/sample");
sampleCreations.clear();
lapStart2 = System.currentTimeMillis();
}
}
long end2 = System.currentTimeMillis();
logger.info("Create " + samplesToCreate + " Samples took: " + (end2-start2) + " millis - " + ((end2-start2)/samplesToCreate) + " millis/sample");
}
}
package ch.ethz.sis.benchmark.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
public class RandomValueGenerator<V> {
public List<V> valuesAsList = new ArrayList<>();
public Set<V> valuesAsMap = new HashSet<>();
public void add(V value) {
if(!valuesAsMap.contains(value)) {
valuesAsMap.add(value);
valuesAsList.add(value);
}
}
public boolean contains(V value) {
return valuesAsMap.contains(value);
}
public V getRandom() {
return valuesAsList.get(ThreadLocalRandom.current().nextInt(0, valuesAsList.size()));
}
}
......@@ -4,13 +4,10 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class RandomWord {
private static final List<String> words = new ArrayList<String>();
private static final RandomValueGenerator<String> words = new RandomValueGenerator<>();
static {
InputStream in = RandomWord.class.getResourceAsStream("google-10000-english.txt");
......@@ -28,6 +25,6 @@ public class RandomWord {
private RandomWord() {}
public static String getRandomWord() {
return words.get(ThreadLocalRandom.current().nextInt(0, words.size()));
return words.getRandom();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment