Forum Discussion
Defragment not working
Thank you very much cpwebb . Very thorough and great information. I really appreciate it!
I used Profiler for two different datasets, and the following are the results:
1) The refresh failed for this dataset:
PeakMemory: 4.5GB , MashupPeakMemory: 1.49 GB
I checked the 'progress report end' for all the tables and observed that the MashupPeakMemory for most tables falls between 120MB and 250MB, except for one table, which was 1.4 GB!
2) This is another dataset with an incremental refresh, and the refresh failed:
PeakMemory: 3.95 GB , MashupPeakMemory: 2.12 GB
And same story with this dataset, as MashupPeakMemory for one of the tables was 1.65 GB!
I refreshed the same dataset again, and it refreshed successfully with a PeakMemory of 3.82GB, as follows:
As you mentioned, I think I need to tune the queries in Power Query for this table that is eating lots of memory, correct?
This is the query for that table:
Thanks again! much appreciated!
Thanks for the detailed information. I'm still learning a lot about this topic and it helps to have a real life example to work though!
It does sound like there's some tuning needed in your Power Query queries. Bear in mind that for the Command End for the refresh you're seeing peak values for all operations, so if you're refreshing 6 tables in parallel then that peak value could be 6 * (a reasonable amount of memory for a single table). From my limited experience I would say that 200-400MB is a reasonable value for memory used by Power Query for a single table.
That said, a MashupPeakMemory of 1.4GB or 1.6GB is definitely too high. For the Power Query query you posted, how much of that folds? Do the Merge and the Group operations fold? They would be the obvious memory-hungry operations; if they do, the next thing to investigate would be the steps where you're changing data types; moving them to the end of the query, or at least after the Merge, could help.
- hoosha_112 years agoHelper I
Thanks again cpwebb for your valuable comment.
I removed all the transformations and started from scratch, and noticed that the groupby (Table.group) query is not folding. Also as you mentioned, changin data type needs to be done after the Merge.
I tried a lot, but I wasn't able to fold the Groupby function, so I created a view in SQL server for the same table with same steps and columns. After refreshing the dataset with this view, and tracing the Profiler, the MashupPeakMemory dropped from 1.4GB to 140 MB for that table, and PeakMemory in CommandEnd for all operations was 3.4 GB.
I followed the same steps for another small dataset, and even though the MashupPeakMemory for that specific table dropped from 1.65GB to 120 MB, the refresh failed again. After some tests, I found that removing 4 calculated columns resolved the issue (I had another table with 9 Million rows and 4 calculated columns).
Below is one of the calculated column that is causing the issue (all other columns have exactly the same function):
Even I had optimized this query before by changing CALCULATE to MAXX!
By removing these 4 calculated columns the PeakMemory for all operations dropped to 2 GB.
I will try reducing the amount of parallelism to see how much PeakMemory changes.
I guess the challenge is to identify which calculated column is consuming more memory. With a larger dataset containing more columns, it becomes difficult to pinpoint the memory-hungry calculated columns.
Thanks again!
- cpwebb2 years agoMicrosoft Employee
I'm glad to hear you've made progress - pushing transforms as far upstream as possible is always a good thing.
Regarding your calculated columns, and DAX expression that uses FILTER() on a whole table always carries a risk of a memory spike. How many rows are in the FollowUps table? It could be that an expression something like this would be better from the point of view of memory:
Response(patient contact)_= var CurrentInspectionId = SELECTEDVALUE(FollowUps[InspectionId]) return CALCULATE( MAX(FollowUps[Response]), FollowUps[InspectionId] = CurrentInspectionId, FollowUps[QuestionId] = "973")Apologies for any typos/syntax errors, or if this is exactly what you had before you optimised.
I don't think there's a way of identifying how much memory each calculated column in a table uses during a refresh, so it will have to be a process of elimination - you'll need to add each calculated column individually, refresh and see how the memory usage is affected.
- hoosha_112 years agoHelper I
Hi and thank you again, cpwebb . I've continued working on this and managed to create a view of the table that previously had a query folding issue in SQL Server. Also we have 2 large tables, each containing around 9 million rows, where I've transferred almost all of the calculated columns for these tables into SQL server. Also adjusted the maximum parallelisim in PBI desktop to 3 and 1 before publishing.
Eventually, the PeakMemory dropped to around 3.4GB-3.6GB, but the refreshes still fail.
It's quite confusing, as I'm not sure where to look next.
Here are some findings from my tests:
1- When I define incremental refresh policy and publish the dataset, the first refresh, which creates the partitions, succeeds (tested multiple times), but subsequent refreshes fails.
2- Without defining an incremental refresh policy, the first refresh fails.
3- The CPU Time for the 2 large tables is 229000 and 103000. Even the manual refresh in PBI desktop for these 2 tables takes a considerable amount of time to complete.
4- Refreshed each table in SSMS and checked the profiler. We have 2 Fact tables, one with 300K rows and PeakMemory of 1.95GB and the other one with 9 million rows and PeakMemory of 2.9GB. There are 2 other child tables with PeakMemory of 1.7GB and 1.3GB and the remaining tables are around 200 MB.
5- Any time I publish the semantic model to PBI service, I observe the dictionary size for the ID columns of the 2 large tables is very big and I have to do the defragment, which sometimes works and reduces the size of dictionary and sometimes doesn't work.Additionally, I would like to know if it's possible to refresh the tables sequentially in PBI service? Does defining maximum parallelism (let's say to one) affect the tables, or is it only for the partitions?
I've created a Powershell query in Azure Runbooks to refresh the tables, but defining "maxParallelism" is resulting in an error (perhaps I'm not defining it correctly).
Thanks again, your ideas and comments are really really appreciated!