Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the wrong throughput of the ConstantThroughputTimer #6280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ConstantThroughputTimer extends AbstractTestElement implements Time

private static class ThroughputInfo{
final Object MUTEX = new Object();
long lastScheduledTime = 0;
double lastScheduledTime = 0.0;
}
private static final Logger log = LoggerFactory.getLogger(ConstantThroughputTimer.class);
private static final AtomicLong PREV_TEST_STARTED = new AtomicLong(0L);
Expand Down Expand Up @@ -201,7 +201,7 @@ private long calculateDelay() {
break;

case AllActiveThreads_Shared: // All threads - alternate calculation
delay = calculateSharedDelay(allThreadsInfo,Math.round(msPerRequest));
delay = calculateSharedDelay(allThreadsInfo, msPerRequest);
break;

case AllActiveThreadsInCurrentThreadGroup_Shared: //All threads in this group - alternate calculation
Expand All @@ -212,7 +212,7 @@ private long calculateDelay() {
if (groupInfo == null) {
groupInfo = threadGroupsInfoMap.computeIfAbsent(key, (k) -> new ThroughputInfo());
}
delay = calculateSharedDelay(groupInfo,Math.round(msPerRequest));
delay = calculateSharedDelay(groupInfo, msPerRequest);
break;

case ThisThreadOnly:
Expand All @@ -223,19 +223,19 @@ private long calculateDelay() {
return delay;
}

private static long calculateSharedDelay(ThroughputInfo info, long milliSecPerRequest) {
final long now = System.currentTimeMillis();
final long calculatedDelay;
private static long calculateSharedDelay(ThroughputInfo info, double milliSecPerRequest) {
final double now = (double)System.currentTimeMillis();
final double calculatedDelay;

//Synchronize on the info object's MUTEX to ensure
//Multiple threads don't update the scheduled time simultaneously
synchronized (info.MUTEX) {
final long nextRequestTime = info.lastScheduledTime + milliSecPerRequest;
final double nextRequestTime = info.lastScheduledTime + milliSecPerRequest;
info.lastScheduledTime = Math.max(now, nextRequestTime);
calculatedDelay = info.lastScheduledTime - now;
}

return Math.max(calculatedDelay, 0);
return Math.round(Math.max(calculatedDelay, 0));
}

private void reset() {
Expand Down