Search in sources :

Example 36 with Stopwatch

use of com.ms.silverking.time.Stopwatch 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();
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) Timer(com.ms.silverking.time.Timer) SimpleTimer(com.ms.silverking.time.SimpleTimer) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 37 with Stopwatch

use of com.ms.silverking.time.Stopwatch 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());
}
Also used : Random(java.util.Random) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 38 with Stopwatch

use of com.ms.silverking.time.Stopwatch 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);
}
Also used : SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) ByteBuffer(java.nio.ByteBuffer) BigDecimal(java.math.BigDecimal)

Example 39 with Stopwatch

use of com.ms.silverking.time.Stopwatch 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));
        }
    }
}
Also used : SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 40 with Stopwatch

use of com.ms.silverking.time.Stopwatch 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());
    }
}
Also used : Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Aggregations

Stopwatch (com.ms.silverking.time.Stopwatch)42 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)41 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)7 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)2 DHTKeyIntEntry (com.ms.silverking.cloud.dht.collection.DHTKeyIntEntry)2 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)2 StatSeries (com.ms.silverking.numeric.StatSeries)2 SimpleTimer (com.ms.silverking.time.SimpleTimer)2 Timer (com.ms.silverking.time.Timer)2 FileOutputStream (java.io.FileOutputStream)2 Date (java.util.Date)2 Random (java.util.Random)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GetOptions (com.ms.silverking.cloud.dht.GetOptions)1 NamespaceOptions (com.ms.silverking.cloud.dht.NamespaceOptions)1 NamespaceVersionMode (com.ms.silverking.cloud.dht.NamespaceVersionMode)1 PutOptions (com.ms.silverking.cloud.dht.PutOptions)1 SessionOptions (com.ms.silverking.cloud.dht.SessionOptions)1