Skip to content

Commit

Permalink
Optimize WorkloadState.addToQueue for large txn rates (cmu-db#191)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Pavlo <[email protected]>
  • Loading branch information
gogo9th and apavlo authored Jun 20, 2022
1 parent d9a6a7b commit 01278bc
Showing 1 changed file with 10 additions and 13 deletions.
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

0 comments on commit 01278bc

Please sign in to comment.