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

Optimize WorkloadState.addToQueue for large txn rates #191

Merged
merged 3 commits into from
Jun 20, 2022
Merged
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
23 changes: 10 additions & 13 deletions src/main/java/com/oltpbenchmark/WorkloadState.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,29 @@ public WorkloadState(BenchmarkState benchmarkState, List<Phase> works, int num_t
* Add a request to do work.
*/
public void addToQueue(int amount, boolean resetQueues) {
int workAdded = 0;

synchronized (this) {
if (resetQueues) {
workQueue.clear();
}


// Only use the work queue if the phase is enabled and rate limited.
if (currentPhase == null || currentPhase.isDisabled()
|| !currentPhase.isRateLimited() || currentPhase.isSerial()) {
return;
} else {
// Add the specified number of procedures to the end of the queue.
for (int i = 0; i < amount; ++i) {
workQueue.add(new SubmittedProcedure(currentPhase.chooseTransaction()));
}
}

// Can't keep up with current rate? Remove the oldest transactions
// (from the front of the queue).
while (workQueue.size() > RATE_QUEUE_LIMIT) {
workQueue.remove();

// Add the specified number of procedures to the end of the queue.
// If we can't keep up with current rate, truncate transactions
for (int i = 0; i < amount && workQueue.size() <= RATE_QUEUE_LIMIT; ++i) {
workQueue.add(new SubmittedProcedure(currentPhase.chooseTransaction()));
workAdded++;
}

// Wake up sleeping workers to deal with the new work.
int numToWake = Math.min(amount, workersWaiting);
for (int i = 0; i < numToWake; ++i) {
int numToWake = Math.min(workAdded, workersWaiting);
while (numToWake-- > 0) {
this.notify();
}
}
Expand Down