use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class KVSerializationTest method runTest.
public void runTest(int numKeys, BufferMode bufferMode) {
SerializedKeyValueBuffers skvBuffers;
Stopwatch sw;
ThreadLocalRandom random;
skvBuffers = new SerializedKeyValueBuffers();
random = ThreadLocalRandom.current();
sw = new SimpleStopwatch();
for (int i = 0; i < numKeys; i++) {
DHTKey key;
ByteBuffer value;
key = new SimpleKey(random.nextLong(), random.nextLong());
value = randomValue(random);
skvBuffers.addKeyValue(key, value, bufferMode);
}
sw.stop();
System.out.println(skvBuffers);
System.out.printf("Elapsed %f\n", sw.getElapsedSeconds());
skvBuffers.freeze();
display(skvBuffers);
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class DaemonStateZK method waitForQuorumState.
public Map<IPAndPort, DaemonState> waitForQuorumState(Set<IPAndPort> members, DaemonState targetState, int inactiveNodeTimeoutSeconds, boolean exitOnTimeout) {
boolean targetReached;
int lastNotReadyCount;
int notReadyCount;
int inactiveCount;
Stopwatch sw;
Set<IPAndPort> incompleteMembers;
incompleteMembers = new HashSet<>(members);
if (verbose) {
System.out.printf("Waiting for quorum state: %s\n", targetState);
}
sw = new SimpleStopwatch();
lastNotReadyCount = Integer.MAX_VALUE;
targetReached = false;
randomAwait(0, minQuorumStatePollIntervalMillis);
while (!targetReached) {
StringBuilder sb;
sb = new StringBuilder();
try {
if (mc.getZooKeeper().getState() == States.CONNECTED) {
Map<IPAndPort, DaemonState> quorumState;
Stopwatch qsSW;
Set<IPAndPort> newlyCompleteMembers;
Pair<Boolean, Map<IPAndPort, DaemonState>> rVal;
boolean allRead;
qsSW = new SimpleStopwatch();
rVal = getQuorumState(incompleteMembers, targetState);
qsSW.stop();
Log.info("getQuorumState elapsed ", qsSW.getElapsedSeconds());
allRead = rVal.getV1();
quorumState = rVal.getV2();
targetReached = true;
notReadyCount = 0;
inactiveCount = 0;
newlyCompleteMembers = new HashSet<>();
for (IPAndPort incompleteMember : incompleteMembers) {
DaemonState memberState;
memberState = quorumState.get(incompleteMember);
if (verbose && allRead) {
sb.append(String.format("%s\t%s\n", incompleteMember, memberState));
}
if (memberState == null) {
if (allRead) {
++inactiveCount;
if ((int) sw.getSplitSeconds() < inactiveNodeTimeoutSeconds) {
++notReadyCount;
targetReached = false;
} else {
sb.append(String.format("%s\t%s\tinactive node timed out\n", incompleteMember, memberState));
if (exitOnTimeout) {
Map<IPAndPort, DaemonState> stateMap;
System.out.print(sb);
Log.warningf("Timeout: %s", incompleteMember);
stateMap = fetchAndDisplayIncompleteState(incompleteMembers, targetState);
return stateMap;
}
}
} else {
targetReached = false;
}
} else if (memberState.ordinal() < targetState.ordinal()) {
targetReached = false;
++notReadyCount;
} else {
newlyCompleteMembers.add(incompleteMember);
}
}
incompleteMembers.removeAll(newlyCompleteMembers);
if (verbose) {
if (allRead) {
if (notReadyCount != lastNotReadyCount) {
System.out.print(sb);
} else {
System.out.printf("Waiting for %d nodes\n", notReadyCount);
}
} else {
System.out.printf("waitForQuorumState > %d incomplete\n", maxIncompletePerFetch);
}
}
lastNotReadyCount = notReadyCount;
}
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
}
if (!targetReached) {
int maxSleepMillis;
if ((int) sw.getSplitSeconds() > inactiveNodeTimeoutSeconds) {
if (exitOnTimeout) {
Map<IPAndPort, DaemonState> stateMap;
Log.warningf("Timeout in targetState: %s", targetState);
try {
stateMap = fetchAndDisplayIncompleteState(incompleteMembers, targetState);
} catch (KeeperException e) {
e.printStackTrace();
stateMap = ImmutableMap.of();
}
return stateMap;
}
}
maxSleepMillis = (int) Math.max((double) maxQuorumStatePollIntervalMillis * ((double) incompleteMembers.size() / (double) maxQuorumStatePollThreshold), minQuorumStatePollIntervalMillis);
maxSleepMillis = Math.min(maxSleepMillis, maxQuorumStatePollIntervalMillis);
Log.info("waitForQuorumState maxSleepMillis: ", maxSleepMillis);
expectedSignals = incompleteMembers.size();
randomAwait(minQuorumStatePollIntervalMillis, maxSleepMillis);
Log.info("waitForQuorumState awake");
}
}
if (verbose) {
System.out.printf("Quorum state reached: %s\n", targetState);
}
return ImmutableMap.of();
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class BulkThroughput method runTest.
public void runTest(BulkThroughputTest test, TestParameters p, int externalReps, int threadID, SynchronousNamespacePerspective<String, byte[]> syncNSP, AsynchronousNamespacePerspective<String, byte[]> asyncNSP) throws PutException, RetrievalException {
List<Double> throughputList;
List<Double> allBatchTimes;
String context;
context = keyPrefix + threadID + ".";
int size = externalReps * ((p.maxKey - p.minKey) / p.batchSize + 1);
allBatchTimes = new ArrayList<>(size);
System.out.println("max: " + p.maxKey);
System.out.println("min: " + p.minKey);
System.out.println("batchSize: " + p.batchSize);
System.out.println("size: " + size);
throughputList = new ArrayList<>(externalReps);
for (int j = 0; j < externalReps; j++) {
Stopwatch sw;
double _Mbps;
int valueSize;
List<Double> batchTimes;
double iops;
switch(test) {
case Write:
valueSize = values[0].length;
break;
default:
valueSize = -1;
}
batchTimes = new ArrayList<>((p.maxKey - p.minKey) / p.batchSize + 1);
sw = new SimpleStopwatch();
for (int i = 0; i < p.repetitions; i++) {
switch(test) {
case Write:
write(p, batchTimes, context, syncNSP);
break;
case Read:
valueSize = read(p, batchTimes, context, syncNSP);
break;
case ReadAsync:
valueSize = readAsync(p, context, asyncNSP);
break;
default:
throw new RuntimeException("Panic");
}
}
sw.stop();
allBatchTimes.addAll(batchTimes);
long bytes;
out.printf("valueSize %d\n\n", valueSize);
StatSeries batchStats;
batchStats = new StatSeries(batchTimes);
bytes = calcBytes(p, valueSize);
_Mbps = NetUtil.calcMbps(bytes, sw);
iops = (double) (p.numKeys * p.repetitions) / sw.getElapsedSeconds();
out.printf("Elapsed %s\n", sw);
out.printf("Bytes %d\n", bytes);
out.printf("Throughput (Mbps) %f\n", _Mbps);
out.printf("Throughput (IOPS) %f\n", iops);
out.printf("Sum %f\n", batchStats.sum());
out.printf("Max %f\n", batchStats.max());
out.printf("50%% %f\n", batchStats.percentile(90));
out.printf("90%% %f\n", batchStats.percentile(90));
out.printf("95%% %f\n", batchStats.percentile(95));
out.printf("99%% %f\n", batchStats.percentile(99));
throughputList.add(_Mbps);
}
StatSeries allBatchStats;
allBatchStats = new StatSeries(allBatchTimes);
out.printf("\n\nSum %f\n\n", allBatchStats.sum());
out.printf("Max %f\n\n", allBatchStats.max());
for (int i = 0; i <= 95; i += 5) {
out.printf("%3d%%\t%f\n", i, allBatchStats.percentile(i));
}
out.printf("%3d%%\t%f\n", 99, allBatchStats.percentile(99));
out.println(StatSeries.summaryHeaderString());
out.println(new StatSeries(throughputList).toSummaryString());
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class BulkThroughputAnalysis method runParallelTests_B.
public void runParallelTests_B(BulkThroughputTest test, TestParameters p, int externalReps) throws PutException, RetrievalException {
List<Double> throughputList;
List<Double> allBatchTimes;
allBatchTimes = new ArrayList<>(externalReps * ((p.maxKey - p.minKey) / p.batchSize + 1));
throughputList = new ArrayList<>(externalReps);
for (int j = 0; j < externalReps; j++) {
Stopwatch sw;
double _Mbps;
int valueSize;
List<Double> batchTimes;
sw = new SimpleStopwatch();
// temporary
batchTimes = null;
switch(test) {
case Write:
valueSize = values[0].length;
break;
default:
valueSize = -1;
}
allBatchTimes.addAll(batchTimes);
long bytes;
out.printf("valueSize %d\n\n", valueSize);
StatSeries batchStats;
batchStats = new StatSeries(batchTimes);
bytes = calcBytes(p, valueSize);
_Mbps = NetUtil.calcMbps(bytes, sw);
out.printf("Elapsed %s\n", sw);
out.printf("Bytes %d\n", bytes);
out.printf("Throughput (Mbps) %f\n", _Mbps);
out.printf("Sum %f\n", batchStats.sum());
out.printf("Max %f\n", batchStats.max());
out.printf("50%% %f\n", batchStats.percentile(50));
out.printf("95%% %f\n", batchStats.percentile(90));
out.printf("90%% %f\n", batchStats.percentile(95));
out.printf("99%% %f\n", batchStats.percentile(99));
throughputList.add(_Mbps);
}
StatSeries allBatchStats;
allBatchStats = new StatSeries(allBatchTimes);
out.printf("\n\nSum %f\n\n", allBatchStats.sum());
out.printf("Max %f\n\n", allBatchStats.max());
for (int i = 0; i <= 95; i += 5) {
out.printf("%3d%%\t%f\n", i, allBatchStats.percentile(i));
}
out.printf("%3d%%\t%f\n", 99, allBatchStats.percentile(99));
out.println(StatSeries.summaryHeaderStringLow());
out.println(new StatSeries(throughputList).toSummaryStringLow());
out.println("\n\n");
// processReplicaTimeStats();
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class PerspectiveTest method createPerspectives.
public void createPerspectives(int numPerspectives) {
Stopwatch runSW;
runSW = new SimpleStopwatch();
for (int i = 0; i < numPerspectives; i++) {
ns.openAsyncPerspective(String.class, byte[].class);
}
runSW.stop();
out.printf("Num Perspectives: %d\n", numPerspectives);
out.printf("Elapsed: %f\n", runSW.getElapsedSeconds());
out.printf("Perspectives / s: %f\n", (double) numPerspectives / runSW.getElapsedSeconds());
out.printf("s / Perspective: %f\n", runSW.getElapsedSeconds() / (double) numPerspectives);
out.printf("\n");
}
Aggregations