Search in sources :

Example 1 with Timer

use of com.ms.silverking.time.Timer in project SilverKing by Morgan-Stanley.

the class FSStress method stressOne.

private void stressOne(int id) throws IOException {
    Timer runTimer;
    Timer displayTimer;
    long filesRead;
    long bytesRead;
    displayTimer = new SimpleTimer(TimeUnit.SECONDS, displayIntervalSeconds);
    runTimer = new SimpleTimer(TimeUnit.SECONDS, durationSeconds);
    filesRead = 0;
    bytesRead = 0;
    while (!runTimer.hasExpired()) {
        long fileBytes;
        filesRead++;
        fileBytes = readRandomFile();
        bytesRead += fileBytes;
        totalFiles.incrementAndGet();
        totalBytes.addAndGet(fileBytes);
        if (displayPerThreadTotals && displayTimer.hasExpired()) {
            long bytes;
            bytes = bytesRead;
            out.printf("id %d\tduration %f\tfiles %d\tbytes %d\tGB %d\tMB/s %f %f\n", id, runTimer.getSplitSeconds(), filesRead, bytes, bytes / 1000000000, NetUtil.calcMBps(bytes, runTimer.getSplitSeconds()), NetUtil.calcMBps(bytes, displayIntervalSeconds));
            displayTimer.reset();
        }
    }
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) Timer(com.ms.silverking.time.Timer) SimpleTimer(com.ms.silverking.time.SimpleTimer)

Example 2 with Timer

use of com.ms.silverking.time.Timer in project SilverKing by Morgan-Stanley.

the class ActiveRegionSync method waitForCompletion.

public boolean waitForCompletion(long time, TimeUnit unit) {
    do {
        Timer timer;
        timer = new SimpleTimer(TimeUnit.MILLISECONDS, timeoutCheckMillis);
        completionLock.lock();
        try {
            while (!isComplete) {
                // just this check; not the sync
                boolean checkTimedOut;
                try {
                    if (debug || verbose) {
                        Log.warningAsyncf("ars completionCV.await %s", uuid);
                    }
                    checkTimedOut = !timer.await(completionCV);
                    if (debug || verbose) {
                        Log.warningAsyncf("ars completionCV.await done %s", uuid);
                    }
                } catch (InterruptedException e) {
                    checkTimedOut = false;
                }
                if (checkTimedOut) {
                    break;
                }
            }
        } finally {
            completionLock.unlock();
        }
    } while (!isComplete && SystemTimeSource.instance.absTimeMillis() - lastUpdateMillis < TimeUnit.MILLISECONDS.convert(time, unit));
    return isComplete;
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) Timer(com.ms.silverking.time.Timer) SimpleTimer(com.ms.silverking.time.SimpleTimer)

Example 3 with Timer

use of com.ms.silverking.time.Timer in project SilverKing by Morgan-Stanley.

the class SyncController method waitForCompletion.

public void waitForCompletion(long time, TimeUnit unit) throws ConvergenceException {
    Timer timer;
    Timer statusTimer;
    scanForEligibleActions();
    timer = new SimpleTimer(unit, time);
    statusTimer = new SimpleTimer(statusComputationIntervalUnit, statusComputationIntervalMillis);
    lock.lock();
    try {
        boolean nonZeroCompletions;
        Stopwatch resendSW;
        Stopwatch alertSW;
        boolean incompleteDisplayed;
        incompleteDisplayed = false;
        nonZeroCompletions = false;
        alertSW = new SimpleStopwatch();
        resendSW = new SimpleStopwatch();
        while (!complete() && !timer.hasExpired()) {
            if (!nonZeroCompletions) {
                ThreadUtil.sleep(1);
            }
            if (statusTimer.hasExpired()) {
                computeStatus();
                statusTimer.reset();
            }
            sendNonConflictingRequests();
            nonZeroCompletions = serviceCompletionQueue(timer.getRemainingMillisLong(), TimeUnit.MILLISECONDS);
            if (nonZeroCompletions) {
                incompleteDisplayed = false;
                alertSW.reset();
            } else {
                if (alertSW.getSplitSeconds() > nonCompletionAlertThresholdSeconds && !incompleteDisplayed) {
                    incompleteDisplayed = true;
                    displayIncomplete();
                }
            }
            if (resendSW.getSplitSeconds() > resendCheckIntervalSeconds) {
                checkForResends();
                resendSW.reset();
            }
        }
        if (hasErrors) {
            throw new ConvergenceException("SyncController unable to complete due to errors");
        } else if (abandoned) {
            throw new ConvergenceException("Abandoned");
        } else if (!complete()) {
            throw new ConvergenceException("Sync timed out");
        }
    } finally {
        lock.unlock();
    }
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) Timer(com.ms.silverking.time.Timer) SimpleTimer(com.ms.silverking.time.SimpleTimer) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 4 with Timer

use of com.ms.silverking.time.Timer in project SilverKing by Morgan-Stanley.

the class OpCompletionTracker method waitForCompletion.

public Pair<Set<UUIDBase>, Set<UUIDBase>> waitForCompletion(Set<UUIDBase> uuids, int time, TimeUnit unit) {
    Timer waitTimer;
    Set<UUIDBase> incompleteOps;
    Set<UUIDBase> failedOps;
    incompleteOps = new HashSet<>();
    failedOps = new HashSet<>();
    waitTimer = new SimpleTimer(unit, time);
    for (UUIDBase uuid : uuids) {
        completionState.putIfAbsent(uuid, new OpCompletionState());
    }
    try {
        for (UUIDBase uuid : uuids) {
            OpCompletionState opCompletionState;
            boolean complete;
            opCompletionState = completionState.get(uuid);
            complete = opCompletionState.waitForCompletion(waitTimer.getRemainingMillis(), TimeUnit.MILLISECONDS);
            if (!complete) {
                incompleteOps.add(uuid);
            }
            if (opCompletionState.getResult().hasFailed()) {
                failedOps.add(uuid);
            }
        }
    } finally {
        for (UUIDBase uuid : uuids) {
            completionState.remove(uuid);
        }
    }
    return new Pair<>(incompleteOps, failedOps);
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) Timer(com.ms.silverking.time.Timer) SimpleTimer(com.ms.silverking.time.SimpleTimer) UUIDBase(com.ms.silverking.id.UUIDBase) Pair(com.ms.silverking.collection.Pair)

Example 5 with Timer

use of com.ms.silverking.time.Timer 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)

Aggregations

SimpleTimer (com.ms.silverking.time.SimpleTimer)7 Timer (com.ms.silverking.time.Timer)7 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)2 Stopwatch (com.ms.silverking.time.Stopwatch)2 Pair (com.ms.silverking.collection.Pair)1 UUIDBase (com.ms.silverking.id.UUIDBase)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1