-
Notifications
You must be signed in to change notification settings - Fork 115
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
Implement use_blob
for execute_mdx_csv
function
#885
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The first results look promising. On very large datasets using blobs provides 30% or 40% better performance and a much lower memory footprint.
from datetime import datetime
from mdxpy import MdxBuilder, MdxHierarchySet
from TM1py.Objects.Cube import Cube
from TM1py.Objects.Dimension import Dimension
from TM1py.Objects.Hierarchy import Hierarchy
from TM1py.Services.TM1Service import TM1Service
PARAMETER_SETS = {
"Linux Server": {
"address": "10.77.19.30",
"port": 8010,
"ssl": True,
"user": "Admin",
"password": "apple"
},
"Windows Local": {
"address": "",
"port": 8010,
"ssl": True,
"user": "Admin",
"password": "apple"
}
}
CUBE = "TM1py Cube"
CHUNK_SIZES = [100_000, 500_000, 1_000_000, 2_500_000]
ITERATIONS = 2
def setup(tm1: TM1Service):
hierarchy = Hierarchy("TM1py Dimension 1", "TM1py Dimension 1")
cells = dict()
for e in range(max(CHUNK_SIZES)):
element = str(e).zfill(7)
hierarchy.add_element(element, "Numeric")
cells[element, "Measure"] = e
dimension = Dimension(name="TM1py Dimension 1", hierarchies=[hierarchy])
tm1.dimensions.update_or_create(dimension)
hierarchy = Hierarchy("TM1py Dimension 2", "TM1py Dimension 2")
hierarchy.add_element("Measure", "Numeric")
dimension = Dimension(name="TM1py Dimension 2", hierarchies=[hierarchy])
tm1.dimensions.update_or_create(dimension)
cube = Cube(name="TM1py Cube", dimensions=["TM1py Dimension 1", "TM1py Dimension 2"])
tm1.cubes.update_or_create(cube)
print("Created Cube")
tm1.cells.write_async(cube.name, cells)
print("Updated cells")
for name, parameters in PARAMETER_SETS.items():
with TM1Service(**parameters) as tm1:
setup(tm1)
for chunk_size in CHUNK_SIZES:
query = MdxBuilder.from_cube(CUBE)
query.columns_non_empty()
query.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_leaves("TM1py Dimension 1").head(chunk_size))
query.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("TM1py Dimension 2"))
before = datetime.now()
for _ in range(ITERATIONS):
csv = tm1.cells.execute_mdx_csv(query, use_blob=True)
print(f"{name}, use_blob=True, {chunk_size}, {(datetime.now() - before) / ITERATIONS}")
before = datetime.now()
for _ in range(ITERATIONS):
csv = tm1.cells.execute_mdx_csv(query, use_blob=False)
print(f"{name}, 'use_blob=False', {chunk_size}, {(datetime.now() - before) / ITERATIONS}") |
MariusWirtz
force-pushed
the
feature/read-with-blob
branch
from
April 4, 2023 18:18
a2a5634
to
61446b5
Compare
for `execute_mdx_dataframe`, `execute_mdx_csv`
MariusWirtz
force-pushed
the
feature/read-with-blob
branch
from
April 4, 2023 18:55
61446b5
to
121240f
Compare
On native cube views
from datetime import datetime
from TM1py.Objects.Subset import AnonymousSubset
from TM1py.Objects.NativeView import NativeView
from mdxpy import MdxBuilder, MdxHierarchySet
from TM1py.Objects.Cube import Cube
from TM1py.Objects.Dimension import Dimension
from TM1py.Objects.Hierarchy import Hierarchy
from TM1py.Services.TM1Service import TM1Service
PARAMETER_SETS = {
"Linux Server": {
"address": "10.77.19.30",
"port": 8010,
"ssl": True,
"user": "Admin",
"password": "apple"
},
"Windows Local": {
"address": "",
"port": 8010,
"ssl": True,
"user": "Admin",
"password": "apple"
}
}
CUBE = "TM1py Cube"
VIEW = "TM1py View"
CHUNK_SIZES = [100_000, 500_000, 1_000_000, 2_500_000]
ITERATIONS = 2
def setup(tm1: TM1Service):
hierarchy = Hierarchy("TM1py Dimension 1", "TM1py Dimension 1")
cells = dict()
for e in range(max(CHUNK_SIZES)):
element = str(e).zfill(7)
hierarchy.add_element(element, "Numeric")
cells[element, "Measure"] = e
dimension = Dimension(name="TM1py Dimension 1", hierarchies=[hierarchy])
tm1.dimensions.update_or_create(dimension)
hierarchy = Hierarchy("TM1py Dimension 2", "TM1py Dimension 2")
hierarchy.add_element("Measure", "Numeric")
dimension = Dimension(name="TM1py Dimension 2", hierarchies=[hierarchy])
tm1.dimensions.update_or_create(dimension)
cube = Cube(name="TM1py Cube", dimensions=["TM1py Dimension 1", "TM1py Dimension 2"])
tm1.cubes.update_or_create(cube)
tm1.cells.write_async(cube.name, cells)
for name, parameters in PARAMETER_SETS.items():
with TM1Service(**parameters) as tm1:
setup(tm1)
for chunk_size in CHUNK_SIZES:
native_view = NativeView(CUBE, view_name=VIEW)
native_view.add_row(
"TM1py Dimension 1",
AnonymousSubset(
dimension_name="TM1py Dimension 1",
expression=MdxHierarchySet.all_leaves("TM1py Dimension 1").head(chunk_size).to_mdx()))
native_view.add_column(
"TM1py Dimension 1",
AnonymousSubset(
dimension_name="TM1py Dimension 2",
expression=MdxHierarchySet.all_leaves("TM1py Dimension 2").to_mdx()))
tm1.views.update_or_create(native_view, private=False)
before = datetime.now()
for _ in range(ITERATIONS):
csv = tm1.cells.execute_view_csv(CUBE, VIEW, use_blob=True)
print(f"{name}, use_blob=True, {chunk_size}, {(datetime.now() - before) / ITERATIONS}")
before = datetime.now()
for _ in range(ITERATIONS):
csv = tm1.cells.execute_view_csv(CUBE, VIEW, use_blob=False)
print(f"{name}, 'use_blob=False', {chunk_size}, {(datetime.now() - before) / ITERATIONS}") |
MariusWirtz
force-pushed
the
feature/read-with-blob
branch
from
April 5, 2023 13:20
81dfbb9
to
5af21a0
Compare
gbryant-dev
reviewed
Apr 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves #884
Add
use_blob
toexecute_mdx_csv
,execute_mdx_dataframe
,execute_view_csv
,execute_view_dataframe
Reduces time to execute MDX by 20-40%
Reduces time to execute NativeView by 40-50%
Reduces memory footprint of Python process significantly in all cases.