use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.
the class FileWriteWithDelay method write.
public static void write(File file, long size, double rateLimitMBs, boolean randomBytes, Pair<Double, Double> delay) throws IOException {
OutputStream out;
long totalBytesWritten;
Stopwatch sw;
Timer displayTimer;
double pause;
boolean delayExecuted;
byte[] buff;
if (randomBytes) {
buff = buffer;
} else {
buff = buffer2;
}
delayExecuted = false;
totalBytesWritten = 0;
out = new FileOutputStream(file);
displayTimer = new SimpleTimer(TimeUnit.SECONDS, 1);
sw = new SimpleStopwatch();
do {
int bytesToWrite;
bytesToWrite = (int) Math.min(size - totalBytesWritten, buff.length);
out.write(buff, 0, bytesToWrite);
totalBytesWritten += bytesToWrite;
if (!delayExecuted && delay != null && sw.getSplitSeconds() > delay.getV1()) {
delayExecuted = true;
pause = delay.getV2();
} else {
double targetTime;
targetTime = totalBytesWritten / (rateLimitMBs * 1000000.0);
pause = targetTime - sw.getSplitSeconds();
}
if (displayTimer.hasExpired()) {
System.out.printf("%f\t%d\t%f\n", sw.getSplitSeconds(), totalBytesWritten, ((double) totalBytesWritten / sw.getSplitSeconds() / 1000000.0));
displayTimer.reset();
}
if (pause > 0.0) {
ThreadUtil.sleepSeconds(pause);
}
} while (totalBytesWritten < size);
out.close();
}
use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.
the class RewriteTest method testRandom.
public void testRandom(int numWrites, Mode mode) throws IOException {
Random r;
Stopwatch sw;
long fileLength = blockSize * 100;
int maxSize = blockSize;
// long fileLength = blockSize * 2;
// int maxSize = 24;
byte[] readBuf;
readBuf = new byte[blockSize];
r = new Random(0);
sw = new SimpleStopwatch();
for (int i = 0; i < numWrites; i++) {
long offset;
int size;
offset = r.nextLong() % fileLength;
if (offset < 0) {
offset = -offset;
}
size = r.nextInt(maxSize - 1) + 1;
System.out.printf("%d %d\n", offset, size);
raf.seek(offset);
if (mode == Mode.Write) {
raf.write(buf[i % 26], 0, size);
} else {
int numRead;
// Note - this verification only works for cases where writes
// don't overlap
numRead = raf.read(readBuf, 0, size);
if (numRead != size) {
throw new RuntimeException("numRead != size");
}
for (int j = 0; j < size; j++) {
if (readBuf[j] != buf[i % 26][j]) {
System.out.printf("%d\t%x != %x\n", offset + j, readBuf[j], buf[i % 26][j]);
}
}
}
}
raf.close();
sw.stop();
System.out.printf("Elapsed: %s\n", sw.getElapsedSeconds());
}
use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.
the class PureBufferedSerializationTest method runTest.
public void runTest(Test test, AllocationMethod allocationMethod, int size, int iterations) {
Stopwatch sw;
DummyPutMessage dummyMessage;
long length;
double secondsPerIteration;
ByteBuffer buf;
length = 0;
switch(allocationMethod) {
case byteBuffer:
buf = ByteBuffer.allocate(size);
break;
case directBuffer:
buf = ByteBuffer.allocateDirect(size);
break;
default:
throw new RuntimeException("panic");
}
while (buf.hasRemaining()) {
buf.put((byte) 7);
}
dummyMessage = new DummyPutMessage(buf, 0, size);
sw = new SimpleStopwatch();
switch(test) {
case serialization:
sw.reset();
for (int i = 0; i < iterations; i++) {
ByteBuffer[] buffers;
buffers = dummyMessage.toBuffers();
length += buffers[0].limit();
}
break;
default:
throw new RuntimeException("");
}
sw.stop();
System.out.println(length + " " + sw);
secondsPerIteration = sw.getElapsedSecondsBD().divide(new BigDecimal(iterations)).doubleValue();
System.out.printf("Time per iteration: %.2e\n", secondsPerIteration);
}
use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.
the class NamespaceRequest method waitForCompletion.
void waitForCompletion() {
synchronized (incompletePeers) {
Stopwatch sw;
sw = new SimpleStopwatch();
while (incompletePeers.size() > 0 && sw.getSplitMillis() < waitLimitMillis) {
try {
incompletePeers.wait(waitLimitMillis);
} catch (InterruptedException ie) {
}
}
if (incompletePeers.size() > 0) {
Log.warning("Unable to receive namespaces from: " + CollectionUtil.toString(incompletePeers));
}
}
}
use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.
the class SKAdminShell method doTestTarget.
private void doTestTarget(String[] args) throws RemoteException {
for (String target : args) {
String[] _args;
Stopwatch sw;
_args = new String[1];
_args[0] = target;
sw = new SimpleStopwatch();
doTarget(_args);
sw.stop();
out.printf("%s\t%s\n", target, sw.toString());
}
}
Aggregations