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();
}
}
}
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;
}
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();
}
}
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);
}
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();
}
Aggregations