Skip to content

Instantly share code, notes, and snippets.

@pilshchikov
Created October 9, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilshchikov/08096c78b425e00166a2ffa2aa5f49ce to your computer and use it in GitHub Desktop.
Save pilshchikov/08096c78b425e00166a2ffa2aa5f49ce to your computer and use it in GitHub Desktop.
Ignite Java thin client bench
package org.bench;
import org.apache.ignite.Ignition;
import org.apache.ignite.client.ClientCache;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.client.ClientException;
import org.joda.time.DateTime;
import java.util.Date;
public class Run {
public static void main(String[] args) {
String host = "[grid ip]";
ClientConfiguration cfg = new ClientConfiguration().setAddresses(String.format("%s:10800", host));
try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
DateTime startTime = new DateTime();
DateTime endTime = startTime.plusMinutes(2);
DateTime lastSeenTime = startTime;
int counter = 0;
int lastKey = 0;
ClientCache<Integer, Integer> cache = igniteClient.getOrCreateCache("java_thin");
while (endTime.toDate().after(new Date())) {
DateTime currentTime = new DateTime();
if (currentTime.getSecondOfMinute() != lastSeenTime.getSecondOfMinute()) {
lastSeenTime = currentTime;
long passedTime = (currentTime.toDate().getTime() - startTime.toDate().getTime())/1000;
System.out.println(String.format("time: %d | counter: %d | values count: %d", passedTime, counter, lastKey));
counter = 0;
}
counter++;
lastKey++;
cache.put(lastKey, lastKey * 2);
}
System.out.println(String.format("Finale counts: %d", lastKey));
}
catch (ClientException e) {
System.err.println(e.getMessage());
}
catch (Exception e) {
System.err.format("Unexpected failure: %s\n", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment