Search in sources :

Example 1 with SimpleTimer

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

the class NumConversion method main.

// ///////////
public static void main(String[] args) {
    int i;
    byte[] b;
    // i = Integer.parseInt(args[0]);
    // b = new byte[BYTES_PER_INT];
    // intToBytes(i, b);
    // System.out.println( ">>"+ bytesToInt(b) );
    // benchmark test
    byte[] bytes = { Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE };
    SimpleTimer timer = new SimpleTimer(TimeUnit.SECONDS, 3);
    timer.reset();
    timer.stop();
    timer.start();
    while (!timer.hasExpired()) System.out.println(timer.getSplitSeconds());
    // 
    // //		timer = new SimpleTimer(TimeUnit.SECONDS, 3);
    // //		timer.reset();
    // //		while (!timer.hasExpired())
    // //			System.out.println(timer.getSplitSeconds());
    // 
    SimpleStopwatch watch = new SimpleStopwatch();
    watch.reset();
    for (int j = 0; j < 1_000_000_000; j++) bytesToLong(bytes);
    watch.stop();
    System.out.println("Time for  inline: " + watch.getElapsedMillis());
    watch.reset();
    for (int j = 0; j < 1_000_000_000; j++) bytesToLong2(bytes);
    watch.stop();
    System.out.println("Time for wrapped: " + watch.getElapsedMillis());
// SimpleTimer timer = new SimpleTimer(TimeUnit.MILLISECONDS, 1_000_000_000);
// timer.stop();
// //		timer.reset();
// timer.start();
// for (int j = 0; j < 1_000_000; j++)
// bytesToLong(bytes);
// timer.stop();
// 
// System.out.println("Time for  inline: " + timer.getElapsedMillis());
// 
// timer.start();
// for (int j = 0; j < 1_000_000; j++)
// bytesToLong2(bytes);
// timer.stop();
// 
// System.out.println("Time for wrapped: " + timer.getElapsedMillis());
}
Also used : SimpleTimer(com.ms.silverking.time.SimpleTimer) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 2 with SimpleTimer

use of com.ms.silverking.time.SimpleTimer 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 3 with SimpleTimer

use of com.ms.silverking.time.SimpleTimer 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 4 with SimpleTimer

use of com.ms.silverking.time.SimpleTimer 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 5 with SimpleTimer

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

Aggregations

SimpleTimer (com.ms.silverking.time.SimpleTimer)8 Timer (com.ms.silverking.time.Timer)7 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)3 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