Skip to content

Commit

Permalink
Various TPC-C runner fixes (#491)
Browse files Browse the repository at this point in the history
* Import path fixes

* Python 3 upgrade fixes, fix class name

* Fix format

* Fix the payment transaction implementation

* Fix new order transaction implementation

* Fix order status implementation

* Fix delivery implementation

* Fix stock level implementation

* Fix formatting
  • Loading branch information
geoffxy authored Apr 16, 2024
1 parent a2f0242 commit f182ed1
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from datetime import datetime

import constants
from .. import constants


## ==============================================
Expand Down
728 changes: 394 additions & 334 deletions workloads/chbenchmark/py-tpcc/pytpcc/drivers/braddriver.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions workloads/chbenchmark/py-tpcc/pytpcc/runtime/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from datetime import datetime
from pprint import pprint, pformat

import constants
from util import *
from .. import constants
from ..util import *


class Executor:
Expand Down
10 changes: 5 additions & 5 deletions workloads/chbenchmark/py-tpcc/pytpcc/runtime/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
from random import shuffle
from pprint import pprint, pformat

import constants
from util import *
from .. import constants
from ..util import *


class Loader:
Expand Down Expand Up @@ -75,7 +75,7 @@ def execute(self):
def loadItems(self):
## Select 10% of the rows to be marked "original"
originalRows = rand.selectUniqueIds(
self.scaleParameters.items / 10, 1, self.scaleParameters.items
self.scaleParameters.items // 10, 1, self.scaleParameters.items
)

## Load all of the items
Expand Down Expand Up @@ -130,7 +130,7 @@ def loadWarehouse(self, w_id):

## Select 10% of the customers to have bad credit
selectedRows = rand.selectUniqueIds(
self.scaleParameters.customersPerDistrict / 10,
self.scaleParameters.customersPerDistrict // 10,
1,
self.scaleParameters.customersPerDistrict,
)
Expand Down Expand Up @@ -204,7 +204,7 @@ def loadWarehouse(self, w_id):
## Select 10% of the stock to be marked "original"
s_tuples = []
selectedRows = rand.selectUniqueIds(
self.scaleParameters.items / 10, 1, self.scaleParameters.items
self.scaleParameters.items // 10, 1, self.scaleParameters.items
)
total_tuples = 0
for i_id in range(1, self.scaleParameters.items + 1):
Expand Down
32 changes: 16 additions & 16 deletions workloads/chbenchmark/py-tpcc/pytpcc/tpcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
import glob
import time
import multiprocessing
from ConfigParser import SafeConfigParser
import pathlib
from configparser import ConfigParser
from pprint import pprint, pformat

from util import *
from runtime import *
import drivers
from .util import *
from .runtime import *
from .drivers.braddriver import BradDriver

logging.basicConfig(
level=logging.INFO,
Expand All @@ -54,10 +55,9 @@
## createDriverClass
## ==============================================
def createDriverClass(name):
full_name = "%sDriver" % name.title()
mod = __import__("drivers.%s" % full_name.lower(), globals(), locals(), [full_name])
klass = getattr(mod, full_name)
return klass
if name != "brad":
raise NotImplementedError
return BradDriver


## DEF
Expand All @@ -70,7 +70,7 @@ def getDrivers():
drivers = []
for f in map(
lambda x: os.path.basename(x).replace("driver.py", ""),
glob.glob("./drivers/*driver.py"),
glob.glob(str(pathlib.Path(__file__).parent.resolve()) + "/drivers/*driver.py"),
):
if f != "abstract":
drivers.append(f)
Expand Down Expand Up @@ -217,9 +217,7 @@ def executorFunc(driverClass, scaleParameters, args, config, debug):
description="Python implementation of the TPC-C Benchmark"
)
aparser.add_argument("system", choices=getDrivers(), help="Target system driver")
aparser.add_argument(
"--config", type=file, help="Path to driver configuration file"
)
aparser.add_argument("--config", type=str, help="Path to driver configuration file")
aparser.add_argument(
"--reset",
action="store_true",
Expand Down Expand Up @@ -291,14 +289,13 @@ def executorFunc(driverClass, scaleParameters, args, config, debug):
if args["print_config"]:
config = driver.makeDefaultConfig()
print(driver.formatConfig(config))
print
sys.exit(0)

## Load Configuration file
if args["config"]:
logging.debug("Loading configuration file '%s'" % args["config"])
cparser = SafeConfigParser()
cparser.read(os.path.realpath(args["config"].name))
cparser = ConfigParser()
cparser.read(os.path.realpath(args["config"]))
config = dict(cparser.items(args["system"]))
else:
logging.debug("Using default configuration for %s" % args["system"])
Expand Down Expand Up @@ -355,7 +352,10 @@ def executorFunc(driverClass, scaleParameters, args, config, debug):
else:
results = startExecution(driverClass, scaleParameters, args, config)
assert results
print(results.show(load_time))
if isinstance(results, int):
print("Result:", results)
else:
print(results.show(load_time))
## IF

## MAIN
2 changes: 1 addition & 1 deletion workloads/chbenchmark/py-tpcc/pytpcc/util/nurand.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OTHER DEALINGS IN THE SOFTWARE.
# -----------------------------------------------------------------------

import rand
from . import rand


def makeForLoad():
Expand Down
4 changes: 2 additions & 2 deletions workloads/chbenchmark/py-tpcc/pytpcc/util/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# -----------------------------------------------------------------------

import random
import nurand
from . import nurand

SYLLABLES = [
"BAR",
Expand Down Expand Up @@ -170,7 +170,7 @@ def makeLastName(number):
"""A last name as defined by TPC-C 4.3.2.3. Not actually random."""
global SYLLABLES
assert 0 <= number and number <= 999
indicies = [number / 100, (number / 10) % 10, number % 10]
indicies = [number // 100, (number // 10) % 10, number % 10]
return "".join(map(lambda x: SYLLABLES[x], indicies))


Expand Down
5 changes: 4 additions & 1 deletion workloads/chbenchmark/py-tpcc/pytpcc/util/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def show(self, load_time=None):
total_time += txn_time
total_cnt += txn_cnt
ret += "\n" + ("-" * total_width)
total_rate = "%.02f txn/s" % ((total_cnt / total_time))
if total_time > 0:
total_rate = "%.02f txn/s" % ((total_cnt / total_time))
else:
total_rate = "-- txn/s"
ret += f % ("TOTAL", str(total_cnt), str(total_time * 1000000), total_rate)

return ret.encode("utf-8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# OTHER DEALINGS IN THE SOFTWARE.
# -----------------------------------------------------------------------

import constants
from .. import constants


def makeDefault(warehouses):
Expand Down

0 comments on commit f182ed1

Please sign in to comment.