//
// Create records using put
//
startExecutor();
final JsonNodeFactory factory = JsonNodeFactory.instance;
final long now = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
ObjectNode recordNode = factory.objectNode();
recordNode.put("type", "n$recordType");
ObjectNode fieldsNode = recordNode.putObject("fields");
for (int f = 1; f <= 5; f++) {
fieldsNode.put("n$field" + f, Words.get());
}
ObjectNode namespaces = recordNode.putObject("namespaces");
namespaces.put("org.lilyproject.rest-perftest", "n");
byte[] recordBytes = JsonFormat.serializeAsBytes(recordNode);
String recordId = "USER." + now + "_" + seqnr;
recordIds.add(recordId);
long before = System.nanoTime();
put("/record/" + recordId, recordBytes, 201);
double duration = System.nanoTime() - before;
metrics.increment("Create record using put", "C", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Create records using post
//
startExecutor();
for (int i = 0; i < iterations; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
ObjectNode actionNode = factory.objectNode();
actionNode.put("action", "create");
ObjectNode recordNode = actionNode.putObject("record");
recordNode.put("type", "n$recordType");
ObjectNode fieldsNode = recordNode.putObject("fields");
for (int f = 1; f <= 5; f++) {
fieldsNode.put("n$field" + f, Words.get());
}
ObjectNode namespaces = recordNode.putObject("namespaces");
namespaces.put("org.lilyproject.rest-perftest", "n");
byte[] recordBytes = JsonFormat.serializeAsBytes(actionNode);
long before = System.nanoTime();
Result result = post("/record", recordBytes, 201);
double duration = System.nanoTime() - before;
metrics.increment("Create record using post", "E", duration / 1e6d);
// ID is assigned by the server, read it out
ObjectNode createdRecord = (ObjectNode)JsonFormat.deserialize(result.data);
recordIds.add(createdRecord.get("id").getValueAsText());
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Read records
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
long before = System.nanoTime();
get("/record/" + recordIds.get(seqnr), 200);
double duration = System.nanoTime() - before;
metrics.increment("Record read", "R", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Read records using vtag
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
long before = System.nanoTime();
get("/record/" + recordIds.get(seqnr) + "/vtag/last", 200);
double duration = System.nanoTime() - before;
metrics.increment("Record read via last vtag", "T", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Read records using version
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
long before = System.nanoTime();
get("/record/" + recordIds.get(seqnr) + "/version/1", 200);
double duration = System.nanoTime() - before;
metrics.increment("Record read specific version", "V", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Read list of versions
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
long before = System.nanoTime();
get("/record/" + recordIds.get(seqnr) + "/version", 200);
double duration = System.nanoTime() - before;
metrics.increment("Read list of versions", "L", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Read list of variants
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
long before = System.nanoTime();
get("/record/" + recordIds.get(seqnr) + "/variant", 200);
double duration = System.nanoTime() - before;
metrics.increment("Read list of variants", "M", duration / 1e6d);
} catch (Throwable t) {
t.printStackTrace();
}
}
});
}
stopExecutor();
//
// Update records using PUT
//
startExecutor();
for (int i = 0; i < recordIds.size(); i++) {
final int seqnr = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
ObjectNode recordNode = factory.objectNode();
ObjectNode fieldsNode = recordNode.putObject("fields");
for (int f = 1; f <= 5; f++) {
fieldsNode.put("n$field" + f, Words.get());
}