Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Commit

Permalink
Load TPC-C ITEM with multiple threads. (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmwnshn authored May 14, 2021
1 parent 6e8c04f commit b61f29d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,26 @@ public TPCCLoader(TPCCBenchmark benchmark) {
@Override
public List<LoaderThread> createLoaderThreads() throws SQLException {
List<LoaderThread> threads = new ArrayList<LoaderThread>();
final CountDownLatch itemLatch = new CountDownLatch(1);

int numLoaders = this.workConf.getLoaderThreads();
final CountDownLatch itemLatch = new CountDownLatch(numLoaders);

// ITEM
// This will be invoked first and executed in a single thread.
threads.add(new LoaderThread() {
@Override
public void load(Connection conn) throws SQLException {
loadItems(conn, TPCCConfig.configItemCount);
itemLatch.countDown();
}
});
// The ITEM table will be fully loaded before any other table.
// Because the ITEM table is large (100k items per the TPC-C spec),
// we divide the ITEM table across the maximum number of loader threads.
for (int i = 1; i <= TPCCConfig.configItemCount;) {
int numItemsPerLoader = TPCCConfig.configItemCount / numLoaders;
int itemStartInclusive = i;
int itemEndInclusive = Math.min(TPCCConfig.configItemCount, itemStartInclusive + numItemsPerLoader - 1);
threads.add(new LoaderThread() {
@Override
public void load(Connection conn) throws SQLException {
loadItems(conn, itemStartInclusive, itemEndInclusive);
itemLatch.countDown();
}
});
i = itemEndInclusive + 1;
}

// WAREHOUSES
// We use a separate thread per warehouse. Each thread will load
Expand Down Expand Up @@ -150,7 +159,7 @@ protected void transCommit(Connection conn) {
}
}

protected int loadItems(Connection conn, int itemKount) {
protected int loadItems(Connection conn, int itemStartInclusive, int itemEndInclusive) {
int k = 0;
int randPct = 0;
int len = 0;
Expand All @@ -162,7 +171,7 @@ protected int loadItems(Connection conn, int itemKount) {

Item item = new Item();
int batchSize = 0;
for (int i = 1; i <= itemKount; i++) {
for (int i = itemStartInclusive; i <= itemEndInclusive; i++) {

item.i_id = i;
item.i_name = TPCCUtil.randomStr(TPCCUtil.randomNumber(14, 24,
Expand Down

0 comments on commit b61f29d

Please sign in to comment.