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

Commit b61f29d

Browse files
authored
Load TPC-C ITEM with multiple threads. (#358)
1 parent 6e8c04f commit b61f29d

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,26 @@ public TPCCLoader(TPCCBenchmark benchmark) {
7373
@Override
7474
public List<LoaderThread> createLoaderThreads() throws SQLException {
7575
List<LoaderThread> threads = new ArrayList<LoaderThread>();
76-
final CountDownLatch itemLatch = new CountDownLatch(1);
77-
76+
int numLoaders = this.workConf.getLoaderThreads();
77+
final CountDownLatch itemLatch = new CountDownLatch(numLoaders);
78+
7879
// ITEM
79-
// This will be invoked first and executed in a single thread.
80-
threads.add(new LoaderThread() {
81-
@Override
82-
public void load(Connection conn) throws SQLException {
83-
loadItems(conn, TPCCConfig.configItemCount);
84-
itemLatch.countDown();
85-
}
86-
});
80+
// The ITEM table will be fully loaded before any other table.
81+
// Because the ITEM table is large (100k items per the TPC-C spec),
82+
// we divide the ITEM table across the maximum number of loader threads.
83+
for (int i = 1; i <= TPCCConfig.configItemCount;) {
84+
int numItemsPerLoader = TPCCConfig.configItemCount / numLoaders;
85+
int itemStartInclusive = i;
86+
int itemEndInclusive = Math.min(TPCCConfig.configItemCount, itemStartInclusive + numItemsPerLoader - 1);
87+
threads.add(new LoaderThread() {
88+
@Override
89+
public void load(Connection conn) throws SQLException {
90+
loadItems(conn, itemStartInclusive, itemEndInclusive);
91+
itemLatch.countDown();
92+
}
93+
});
94+
i = itemEndInclusive + 1;
95+
}
8796

8897
// WAREHOUSES
8998
// We use a separate thread per warehouse. Each thread will load
@@ -150,7 +159,7 @@ protected void transCommit(Connection conn) {
150159
}
151160
}
152161

153-
protected int loadItems(Connection conn, int itemKount) {
162+
protected int loadItems(Connection conn, int itemStartInclusive, int itemEndInclusive) {
154163
int k = 0;
155164
int randPct = 0;
156165
int len = 0;
@@ -162,7 +171,7 @@ protected int loadItems(Connection conn, int itemKount) {
162171

163172
Item item = new Item();
164173
int batchSize = 0;
165-
for (int i = 1; i <= itemKount; i++) {
174+
for (int i = itemStartInclusive; i <= itemEndInclusive; i++) {
166175

167176
item.i_id = i;
168177
item.i_name = TPCCUtil.randomStr(TPCCUtil.randomNumber(14, 24,

0 commit comments

Comments
 (0)