Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple prediction script for metadata size #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
pylint
python3-dbus
python3-dbus-python-client-gen
python3-justbytes
python3-matplotlib
python3-numpy
python3-pygithub
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
pylint
python3-dbus
python3-dbus-python-client-gen
python3-justbytes
python3-matplotlib
python3-numpy
python3-pygithub
Expand Down
117 changes: 117 additions & 0 deletions misc_scripts/pool_metadata_size_estimate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/python3
"""
pool_metadata_size_estimate: estimate the inrease of pool level metadata due
to addition of blockdevs.
"""

# isort: STDLIB
import argparse

# isort: THIRDPARTY
from justbytes import Range

STRING = 255
UUID = 36


def metadata_str(value):
"""
Parse a value representing the size of a metadata string.
"""
value = int(value)
if value > 255:
raise argparse.ArgumentTypeError(
f"Exceeds maximum length {STRING} for metadata string."
)

if value < 0:
raise argparse.ArgumentTypeError("Negative lengths prohbited.")

return value


def nat(value):
"""
Parse a value representing a natural number.
"""
value = int(value)
if value < 0:
raise argparse.ArgumentTypeError("Must be a natural number.")
return value


def gen_parser():
"""
Generate parser.
"""
parser = argparse.ArgumentParser(
description=(
"Calculate size increase in Stratis pool-level metadata due to "
"addition of new devices."
)
)

parser.add_argument(
"num_devices",
help="Number of devices to be added",
type=nat,
)

parser.add_argument(
"--hardware-info",
dest="hardware_info",
help="Bytes required to represent hardware info.",
type=metadata_str,
)

parser.add_argument(
"--user-info",
dest="user_info",
help="Bytes required to represent user info.",
type=metadata_str,
)

return parser


def f(*, hardware_info=None, user_info=None):
"""
Calculate the bytes required to store num_devices in metadata.

:param hardware_info: the len of the hardware info
:param user_info: the len of the user info
"""
commas = (0 if hardware_info is None else 1) + (0 if user_info is None else 1)

m = (
commas
+ (0 if hardware_info is None else hardware_info + 18)
+ (0 if user_info is None else user_info + 13)
+ (UUID + 9)
+ 3
)

return m


def main():
"""
Main method
"""

parser = gen_parser()
args = parser.parse_args()

num_devices = args.num_devices

user_info = args.user_info
hardware_info = args.hardware_info

m = f(hardware_info=hardware_info, user_info=user_info)
print(f"Slope: {m} bytes")
prediction = m * num_devices
print(f"Predicted use: {prediction} bytes, approx {Range(prediction)}")


if __name__ == "__main__":
main()