return null;
}
public void runLoad() throws ExecutionException, InterruptedException {
final Mean recommendedBecause = new Mean();
final Mean setPreference = new Mean();
final Mean removePreference = new Mean();
final Mean setTag = new Mean();
final Mean ingest = new Mean();
final Mean refresh = new Mean();
final Mean estimatePreference = new Mean();
final Mean mostSimilarItems = new Mean();
final Mean similarityToItem = new Mean();
final Mean mostPopularItems = new Mean();
final Mean recommendToMany = new Mean();
final Mean recommend = new Mean();
Processor<Integer> processor = new Processor<Integer>() {
private final RandomGenerator random = RandomManager.getRandom();
@Override
public void process(Integer step, long count) {
double r;
long userID;
long itemID;
long itemID2;
float value;
synchronized (random) {
r = random.nextDouble();
userID = uniqueUserIDs[random.nextInt(uniqueUserIDs.length)];
itemID = uniqueItemIDs[random.nextInt(uniqueItemIDs.length)];
itemID2 = uniqueItemIDs[random.nextInt(uniqueItemIDs.length)];
value = random.nextInt(10);
}
long stepStart = System.currentTimeMillis();
try {
if (r < 0.05) {
client.recommendedBecause(userID, itemID, 10);
recommendedBecause.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.07) {
client.setPreference(userID, itemID);
setPreference.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.08) {
client.setPreference(userID, itemID, value);
setPreference.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.09) {
client.setUserTag(userID, Long.toString(itemID));
setTag.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.10) {
client.setItemTag(Long.toString(userID), itemID);
setTag.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.11) {
client.removePreference(userID, itemID);
removePreference.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.12) {
StringReader reader = new StringReader(userID + "," + itemID + ',' + value + '\n');
client.ingest(reader);
ingest.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.13) {
client.refresh();
refresh.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.14) {
client.similarityToItem(itemID, itemID2);
similarityToItem.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.15) {
client.mostPopularItems(10);
mostPopularItems.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.19) {
client.estimatePreference(userID, itemID);
estimatePreference.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.20) {
client.estimateForAnonymous(itemID, new long[] {itemID2});
estimatePreference.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.25) {
client.mostSimilarItems(new long[]{itemID}, 10);
mostSimilarItems.increment(System.currentTimeMillis() - stepStart);
} else if (r < 0.30) {
client.recommendToMany(new long[] { userID, userID }, 10, true, null);
recommendToMany.increment(System.currentTimeMillis() - stepStart);
} else {
client.recommend(userID, 10);
recommend.increment(System.currentTimeMillis() - stepStart);
}
} catch (TasteException te) {
log.warn("Error during request", te);
}
if (count % 1000 == 0) {
log.info("Finished {} load steps", count);
}
}
};
log.info("Starting load test...");
long start = System.currentTimeMillis();
new Paralleler<Integer>(new CountingIterator(steps), processor, "Load").runInParallel();
long end = System.currentTimeMillis();
log.info("Finished {} steps in {}ms", steps, end - start);
log.info("recommendedBecause: {}", recommendedBecause.getResult());
log.info("setPreference: {}", setPreference.getResult());
log.info("removePreference: {}", removePreference.getResult());
log.info("setTag: {}", setTag.getResult());
log.info("ingest: {}", ingest.getResult());
log.info("refresh: {}", refresh.getResult());
log.info("estimatePreference: {}", estimatePreference.getResult());
log.info("mostSimilarItems: {}", mostSimilarItems.getResult());
log.info("similarityToItem: {}", similarityToItem.getResult());
log.info("mostPopularItems: {}", mostPopularItems.getResult());
log.info("recommendToMany: {}", recommendToMany.getResult());
log.info("recommend: {}", recommend.getResult());
}