use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class ClientTool method doAction.
public void doAction(ClientOptions options) throws Exception {
DHTSession session;
Action action;
SynchronousNamespacePerspective<String, byte[]> syncNSP;
Stopwatch sw;
int outerReps;
NamespacePerspectiveOptions<String, byte[]> nspOptions;
// FUTURE - IMPLEMENT VALIDATION FLAG
// DHTClient.setValidateChecksums(!options.noValidation);
// note - server may be null
session = dhtClient.openSession(new SessionOptions(SKGridConfiguration.parseFile(options.gridConfig), options.server));
if (session == null) {
throw new RuntimeException("null session");
}
if (options.action != Action.CreateNamespace) {
Namespace ns;
ns = session.getNamespace(options.namespace);
nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
if (options.checksumType != null) {
nspOptions = nspOptions.defaultPutOptions(session.getDefaultPutOptions().checksumType(options.checksumType));
}
syncNSP = ns.openSyncPerspective(nspOptions);
} else {
syncNSP = null;
}
// syncNSP = session.openSyncNamespacePerspective(options.namespace, nspOptions);
if (options.warmup) {
outerReps = 2;
} else {
outerReps = 1;
}
for (int i = 0; i < outerReps; i++) {
sw = new SimpleStopwatch();
try {
action = options.action;
switch(action) {
case Put:
doPut(options, session, syncNSP, sw);
break;
case MultiPut:
doMultiPut(options, session, syncNSP, sw);
break;
case MultiGet:
doMultiGet(options, syncNSP, sw);
break;
case Get:
doGet(options, syncNSP, sw);
break;
case GetMeta:
doGetMeta(options, syncNSP, sw);
break;
case GetValueAndMeta:
doGetValueAndMeta(options, syncNSP, sw);
break;
case WaitFor:
doWaitFor(options, syncNSP, sw);
break;
case Snapshot:
doSnapshot(options, syncNSP, sw);
break;
case SyncRequest:
doSyncRequest(options, syncNSP, sw);
break;
case CreateNamespace:
doCreateNamespace(options, session, sw);
break;
case GetNamespaceOptions:
doGetNamespaceOptions(options, session, sw);
break;
default:
throw new RuntimeException("panic");
}
} finally {
session.close();
}
// sw.stop();
Log.warning("Elapsed:\t" + sw.getElapsedSeconds());
if (options.warmup || i < outerReps - 1) {
ThreadUtil.sleep(warmupDelayMillis);
}
}
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class ProducerConsumer method run.
public void run(int items) throws PutException, RetrievalException {
Stopwatch sw;
sw = new SimpleStopwatch();
for (int i = 1; i <= items; i++) {
switch(mode) {
case Producer:
produce(i);
break;
case Consumer:
consume(i);
break;
default:
throw new RuntimeException("panic");
}
ThreadUtil.sleep(delay);
}
sw.stop();
System.out.println(sw);
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class ChannelWriteTest method runTest.
public void runTest(Test test, int valueSize, int numValues, int iterations) throws IOException {
Stopwatch sw;
byte[] value;
byte[] checksum;
int entrySize;
int totalBytes;
GatheringByteChannel outChannel;
long totalWritten;
ByteBuffer valuesBuffer;
ByteBuffer[] buffers;
entrySize = valueSize + checksumSize;
totalBytes = entrySize * numValues;
value = new byte[valueSize];
checksum = new byte[checksumSize];
random.nextBytes(value);
outChannel = new FileOutputStream(new File("/dev/null")).getChannel();
sw = new SimpleStopwatch();
switch(test) {
case array:
{
byte[] msg;
for (int j = 0; j < iterations; j++) {
msg = new byte[totalBytes];
for (int i = 0; i < numValues; i++) {
System.arraycopy(value, 0, msg, i * entrySize, valueSize);
System.arraycopy(checksum, 0, msg, i * entrySize + valueSize, checksumSize);
}
valuesBuffer = ByteBuffer.wrap(msg);
totalWritten = 0;
while (totalWritten < totalBytes) {
long written;
written = outChannel.write(valuesBuffer);
if (written > 0) {
totalWritten += written;
}
}
if (totalWritten != totalBytes) {
throw new RuntimeException("totalWritten != totalBytes");
}
}
}
break;
case buffer:
buffers = new ByteBuffer[numValues * 2];
for (int i = 0; i < numValues; i++) {
buffers[i * 2] = ByteBuffer.allocate(value.length);
buffers[i * 2 + 1] = ByteBuffer.allocate(checksum.length);
}
sw.reset();
sendBuffers(buffers, iterations, totalBytes, outChannel);
break;
case direct:
buffers = new ByteBuffer[numValues * 2];
for (int i = 0; i < numValues; i++) {
buffers[i * 2] = ByteBuffer.allocateDirect(valueSize);
// buffers[i * 2].put(value);
// buffers[i * 2].flip();
buffers[i * 2 + 1] = ByteBuffer.allocateDirect(checksumSize);
// buffers[i * 2 + 1].put(checksum);
// buffers[i * 2 + 1].flip();
}
sw.reset();
sendBuffers(buffers, iterations, totalBytes, outChannel);
break;
case mixed:
buffers = new ByteBuffer[numValues * 2];
for (int i = 0; i < numValues; i++) {
buffers[i * 2] = ByteBuffer.allocateDirect(valueSize);
// buffers[i * 2].put(value);
// buffers[i * 2].flip();
buffers[i * 2 + 1] = ByteBuffer.allocate(checksum.length);
// buffers[i * 2 + 1].put(checksum);
// buffers[i * 2 + 1].flip();
}
sw.reset();
sendBuffers(buffers, iterations, totalBytes, outChannel);
break;
}
sw.stop();
System.out.printf("%s\tTime per iteration %e\n", test.toString(), sw.getElapsedSeconds() / (double) iterations);
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class RingTree method getResolvedMap.
// ///////////////////////////////
public ResolvedReplicaMap getResolvedMap(String ringParentName, ReplicaPrioritizer replicaPrioritizer) {
try {
ResolvedReplicaMap resolvedMap;
List<RingEntry> entryList;
Node node;
Stopwatch sw;
Log.warningf("getResolvedMap: %s", ringParentName);
sw = new SimpleStopwatch();
resolvedMap = new ResolvedReplicaMap(replicaPrioritizer);
if (debug) {
System.out.println("getResolvedMap: " + topology.getRoot());
}
node = topology.getNodeByID(ringParentName);
if (node == null) {
throw new RuntimeException("Unable to getNodeByID " + ringParentName);
}
entryList = project(node, LongRingspace.globalRegion);
for (RingEntry entry : entryList) {
resolvedMap.addEntry(entry);
}
resolvedMap.computeReplicaSet();
sw.stop();
Log.warningf("getResolvedMap: %s complete %f", ringParentName, sw.getElapsedSeconds());
return resolvedMap;
} catch (RuntimeException re) {
re.printStackTrace();
throw re;
}
}
use of com.ms.silverking.time.Stopwatch in project SilverKing by Morgan-Stanley.
the class StorageModule method reap.
public void reap(boolean leaveTrash) {
Stopwatch sw;
Log.warning("Reap");
sw = new SimpleStopwatch();
for (NamespaceStore ns : namespaces.values()) {
if (!ns.isDynamic()) {
ns.reap(leaveTrash);
}
}
sw.stop();
Log.warning("Reap complete: " + sw);
}
Aggregations