Skip to content

Commit

Permalink
borrowing fixes from merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gargnitingoogle committed Aug 6, 2024
1 parent 162b5f8 commit ff7ee55
Show file tree
Hide file tree
Showing 5 changed files with 563 additions and 74 deletions.
67 changes: 45 additions & 22 deletions perfmetrics/scripts/testing_on_gke/examples/dlio/dlio_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,55 @@
import json


def validateDlioWorkload(workload, name):
def validateDlioWorkload(workload: dict, name: str):
"""Validates the given json workload object."""
if (
'dlioWorkload' not in workload
or 'fioWorkload' in workload
or 'bucket' not in workload
):
print(
f"{name} does not have 'dlioWorkload' or 'bucket' key in it, or"
" has 'fioWorkload' key in it"
)
if 'dlioWorkload' not in workload:
print(f"{name} does not have 'dlioWorkload' key in it.")
return False

if 'bucket' not in workload:
print(f"{name} does not have 'bucket' key in it.")
return False

if 'fioWorkload' in workload:
print(f"{name} has 'fioWorkload' key in it, which is unexpected.")
return False

dlioWorkload = workload['dlioWorkload']
for requiredAttribute in ['numFilesTrain', 'recordLength', 'batchSizes']:
for requiredAttribute, _type in {
'numFilesTrain': int,
'recordLength': int,
'batchSizes': list,
}.items():
if requiredAttribute not in dlioWorkload:
print(f'dlioWorkload for {name} does not have {requiredAttribute} in it')
print(
f'In {name}, dlioWorkload for {name} does not have'
f' {requiredAttribute} in it'
)
return False
if not type(dlioWorkload[requiredAttribute]) is _type:
print(
f'In {name}, dlioWorkload[{requiredAttribute}] is of type'
f' {type(dlioWorkload[requiredAttribute])}, not of type {_type} '
)
return False

for batchSize in dlioWorkload['batchSizes']:
if not type(batchSize) is int:
print(
f'In {name}, one of the batch-size values in'
f" dlioWorkload['batchSizes'] is '{batchSize}', which is of type"
f' {type("batchSize")}, not int'
)
return False
if batchSize < 1:
print(
f'In {name}, one of the batch-size values in'
f" dlioWorkload['batchSizes'] is '{batchSize}' < 1, which is not"
' supported.'
)
return False

return True


Expand Down Expand Up @@ -52,7 +83,7 @@ def __init__(self, scenario, numFilesTrain, recordLength, bucket, batchSizes):
self.batchSizes = batchSizes


def ParseTestConfigForDlioWorkloads(testConfigFileName):
def ParseTestConfigForDlioWorkloads(testConfigFileName: str):
"""Parses the given workload test configuration file for DLIO workloads."""
print(f'Parsing {testConfigFileName} for DLIO workloads ...')
with open(testConfigFileName) as f:
Expand Down Expand Up @@ -80,15 +111,7 @@ def ParseTestConfigForDlioWorkloads(testConfigFileName):
dlioWorkload['numFilesTrain'],
dlioWorkload['recordLength'],
workload['bucket'],
(
dlioWorkload['batchSizes'].split(',')
if (
'batchSizes' in dlioWorkload
and dlioWorkload['batchSizes']
and not str.isspace(dlioWorkload['batchSizes'])
)
else []
),
dlioWorkload['batchSizes'],
)
)
return dlioWorkloads
177 changes: 177 additions & 0 deletions perfmetrics/scripts/testing_on_gke/examples/dlio/dlio_workload_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
"""This file defines unit tests for functionalities in dlio_workload.py"""

import unittest
from dlio_workload import DlioWorkload, validateDlioWorkload


class DlioWorkloadTest(unittest.TestCase):

def test_validate_dlio_workload_empty(self):
self.assertFalse(validateDlioWorkload(({}), "empty-dlio-workload"))

def test_validate_dlio_workload_invalid_no_bucket(self):
self.assertFalse(
validateDlioWorkload(({"dlioWorkload": {}}), "invalid-dlio-workload-1")
)

def test_validate_dlio_workload_invalid_no_dlioWorkloadSpecified(self):
self.assertFalse(
validateDlioWorkload(({"bucket": {}}), "invalid-dlio-workload-2")
)

def test_validate_dlio_workload_invalid_commented_out_dlioWorkload(self):
self.assertFalse(
validateDlioWorkload(
({"_dlioWorkload": {}, "bucket": "dummy-bucket"}),
"commented-out-dlio-workload",
)
)

def test_validate_dlio_workload_invalid_mixed_dlioWorkload_fioWorkload(self):
self.assertFalse(
validateDlioWorkload(
({
"dlioWorkload": {},
"fioWorkload": {},
"bucket": "dummy-bucket",
}),
"mixed-dlio/fio-workload",
)
)

def test_validate_dlio_workload_invalid_missing_numFilesTrain(self):
workload = dict({
"dlioWorkload": {
"recordLength": 10000,
"batchSizes": [100, 200],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-missing-numFilesTrain"
)
)
pass

def test_validate_dlio_workload_invalid_unsupported_numFilesTrain(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": "1000",
"recordLength": 10000,
"batchSizes": [100, 200],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-unsupported-numFilesTrain"
)
)
pass

def test_validate_dlio_workload_invalid_missing_recordLength(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"batchSizes": [100, 200],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-missing-recordLength"
)
)
pass

def test_validate_dlio_workload_invalid_unsupported_recordLength(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": "10000",
"batchSizes": [100, 200],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-unsupported-recordLength"
)
)
pass

def test_validate_dlio_workload_invalid_missing_batchSizes(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": 10000,
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-missing-batchSizes"
)
)
pass

def test_validate_dlio_workload_invalid_unsupported_batchSizes1(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": 10000,
"batchSizes": ["100"],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-unsupported-batchSizes1"
)
)
pass

def test_validate_dlio_workload_invalid_unsupported_batchSizes2(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": 10000,
"batchSizes": [0, -1],
},
"bucket": "dummy-bucket",
})
self.assertFalse(
validateDlioWorkload(
workload, "invalid-dlio-workload-unsupported-batchSizes2"
)
)
pass

def test_validate_dlio_workload_valid_single_batchSize(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": 10000,
"batchSizes": [100],
},
"bucket": "dummy-bucket",
})
self.assertTrue(validateDlioWorkload(workload, "valid-dlio-workload-2"))
pass

def test_validate_dlio_workload_valid_multiple_batchSizes(self):
workload = dict({
"dlioWorkload": {
"numFilesTrain": 1000,
"recordLength": 10000,
"batchSizes": [100, 200],
},
"bucket": "dummy-bucket",
})
self.assertTrue(validateDlioWorkload(workload, "valid-dlio-workload-2"))
pass


if __name__ == "__main__":
unittest.main()
88 changes: 58 additions & 30 deletions perfmetrics/scripts/testing_on_gke/examples/fio/fio_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,61 @@
import json


def validateFioWorkload(workload, name):
def validateFioWorkload(workload: dict, name: str):
"""Validates the given json workload object."""
if (
'fioWorkload' not in workload
or 'dlioWorkload' in workload
or 'bucket' not in workload
):
print(
f"{name} does not have 'fioWorkload' or 'bucket' key in it, or"
" has 'dlioWorkload' key in it."
)
if 'fioWorkload' not in workload:
print(f"{name} does not have 'fioWorkload' key in it.")
return False

if 'bucket' not in workload:
print(f"{name} does not have 'bucket' key in it.")
return False

if 'dlioWorkload' in workload:
print(f"{name} has 'dlioWorkload' key in it, which is unexpected.")
return False

fioWorkload = workload['fioWorkload']
for requiredAttribute in [
'fileSize',
'blockSize',
'filesPerThread',
'numThreads',
]:
for requiredAttribute, _type in {
'fileSize': str,
'blockSize': str,
'filesPerThread': int,
'numThreads': int,
}.items():
if requiredAttribute not in fioWorkload:
print(f'fioWorkload for {name} does not have {requiredAttribute} in it.')
print(f'In {name}, fioWorkload does not have {requiredAttribute} in it')
return False
if not type(fioWorkload[requiredAttribute]) is _type:
print(
f'In {name}, fioWorkload[{requiredAttribute}] is of type'
f' {type(fioWorkload[requiredAttribute])}, not of type {_type} '
)
return False

if 'readTypes' in fioWorkload:
readTypes = fioWorkload['readTypes']
if not type(readTypes) is list:
print(
f"In {name}, fioWorkload['readTypes'] is of type {type(readTypes)},"
" not 'list'."
)
return False
for readType in readTypes:
if not type(readType) is str:
print(
f'In {name}, one of the values in'
f" fioWorkload['readTypes'] is '{readType}', which is of type"
f' {type(readType)}, not str'
)
return False
if not readType == 'read' and not readType == 'randread':
print(
f"In {name}, one of the values in fioWorkload['readTypes'] is"
f" '{readType}' which is not a supported value. Supported values"
' are read, randread'
)
return False

return True


Expand All @@ -55,13 +87,13 @@ class FioWorkload:

def __init__(
self,
scenario,
fileSize,
blockSize,
filesPerThread,
numThreads,
bucket,
readTypes,
scenario: str,
fileSize: str,
blockSize: str,
filesPerThread: int,
numThreads: int,
bucket: str,
readTypes: list,
):
self.scenario = scenario
self.fileSize = fileSize
Expand All @@ -80,7 +112,7 @@ def PPrint(self):
)


def ParseTestConfigForFioWorkloads(fioTestConfigFile):
def ParseTestConfigForFioWorkloads(fioTestConfigFile: str):
"""Parses the given workload test configuration file for FIO workloads."""
print(f'Parsing {fioTestConfigFile} for FIO workloads ...')
with open(fioTestConfigFile) as f:
Expand Down Expand Up @@ -111,11 +143,7 @@ def ParseTestConfigForFioWorkloads(fioTestConfigFile):
fioWorkload['numThreads'],
workload['bucket'],
(
(
[]
if str.isspace(fioWorkload['readTypes'])
else fioWorkload['readTypes'].split(',')
)
fioWorkload['readTypes']
if 'readTypes' in fioWorkload
else ['read', 'randread']
),
Expand Down
Loading

0 comments on commit ff7ee55

Please sign in to comment.