-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
perf: BOM Update Tool #31072
Merged
Merged
perf: BOM Update Tool #31072
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
- Create child-parent map once and fetch value from child key to get parents - Get parents recursively for a leaf node (get all ancestors) - Approx. 44 secs for 4lakh 70k boms
Codecov Report
@@ Coverage Diff @@
## develop #31072 +/- ##
===========================================
- Coverage 63.50% 63.46% -0.05%
===========================================
Files 986 988 +2
Lines 67457 67574 +117
===========================================
+ Hits 42838 42885 +47
- Misses 24619 24689 +70
|
- Move `get_boms_in_bottom_up_order` in bom update tool’s file - Remove repeated rm cost update from `update_cost`. `calculate_cost` handles RM cost update - db_update children in `calculate_cost` optionally - Don’t call `update_exploded_items` and regenerate exploded items in `update_cost`. They will stay the same (except cost)
- Doc is only used to iterate over items(which wont change) and change rate/amount of rows - These changes are inserted in db via `db_update`, so no harm - Tested locally: refetching cached doc after db update, reflects fresh data.
marination
force-pushed
the
perf-bom-update-tool
branch
4 times, most recently
from
May 19, 2022 21:26
1c84087
to
ef36f6f
Compare
- Use the right price list and currency to avoid rate conversion (1000/62.9), since rates are reset correctly now - Use RM rate based on Price List in BOM. Non stock item has no valuation
marination
force-pushed
the
perf-bom-update-tool
branch
from
May 19, 2022 21:45
ef36f6f
to
90d4dc0
Compare
3 tasks
marination
force-pushed
the
perf-bom-update-tool
branch
from
May 24, 2022 12:21
3e7f15e
to
e46e9f9
Compare
Update cost tests are breaking. Will fix while writing tests |
- Process BOMs level wise and Pause after level is complete - Cron job will resume Paused jobs, which will again process the new level and pause at the end - This will go on until all BOMs are updated - Added Progress section with fields to track updated BOMs in Log - Cleanup: Add BOM Updation utils file to contain helper functions/sub-functions - Cleanup: BOM Update Log file will only contain functions that are in direct context of the Log Co-authored-by: Gavin D'souza <[email protected]>
marination
force-pushed
the
perf-bom-update-tool
branch
2 times, most recently
from
May 27, 2022 05:24
565d2dc
to
c6e9d6c
Compare
- Generate RM-Rate map from Items table (will include subassembly items with rate) - Function to reset exploded item rate from above map - `db_update` exploded item rate only if rate is changed - Via Update Cost, only update exploded items rate, do not regenerate table again - Exploded Items are regenerated on Save and Replace BOM job - `calculate_exploded_cost` is run only via non doc events (Update Cost button, Update BOMs Cost Job)
marination
force-pushed
the
perf-bom-update-tool
branch
from
May 27, 2022 09:03
3d66ea0
to
eabd829
Compare
- Separate getting dependants and checking if they are valid (loop within loop led to redundant processing that slowed down function) - Adding to above, the same dependant(parent) was repeatedly processed as many children shared it. Expensive. - Use a parent-child map similar to child-parent map to check if all children are resolved - `map.get()` reduced time: 10 mins -> 0.9s~1 second (as compared to `get_cached_doc` or query) - Total time: 17 seconds to process 6599 leaf boms and 4.2L parent boms - Previous Total time: >10 mins (I terminated it due to not wanting to waste time XD)
- If `Update Cost` job is ongoing, then block creation of new ones since all BOMs are updated - `db_update` in `calculate_rm_cost` only if changed values to reduce redundant row updates - Misc: Use variable for batch size
- This was done due to stale reads while the background jobs tried updating status of the log - Added a table where all bom jobs within log will be tracked with what level they are processing - Cron job will check if table jobs are all processed every 5 mins - If yes, it will prepare parents and call `process_boms_cost_level_wise` to start next level - If pending jobs, do nothing - Current BOM Level is being tracked that helps adding rows to the table - Individual bom cost jobs (that are queued) will process and update boms > will update BOM Update Batch table row with list of updated BOMs
- Utility to update cost in all BOMs without cron jobs or background jobs (run immediately) - Re-use util wherever all bom costs are to be updated - Skip explicit commits if in test - Specify company in test records (dirty data sometimes, company wh mismatch) - Skip background jobs queueing if in test
marination
force-pushed
the
perf-bom-update-tool
branch
9 times, most recently
from
June 8, 2022 05:18
9543c9a
to
6dd3263
Compare
- Use base_rate for assertions as rate is subject to change due to conversion factor (USD)
marination
force-pushed
the
perf-bom-update-tool
branch
from
June 8, 2022 05:50
6dd3263
to
9f2793c
Compare
- Use qb instead of db.sql - Don't use `args` as argument for function - Cleaner variable names
ankush
reviewed
Jun 8, 2022
erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py
Outdated
Show resolved
Hide resolved
…ta (update cost) - Remove `auto_commit_on_many_writes` in `update_cost_in_level()` as commits happen every N BOMs - Auto commit every 50 BOMs - test: Remove hacky `frappe.flags.in_test` returns - test: Enqueue `now` if in tests (for update cost and replace bom) - Replace BOM: Copy bom object to `_doc_before_save` so that version.py finds a difference between the two - Replace BOM: Add reference to version - Update Cost: Unset `processed_boms` if Log is completed (useless after completion) - test: `update_cost_in_all_boms_in_test` works close to actual prod implementation (only call Cron job manually) - Test: use `enqueue_replace_bom` so that test works closest to production behaviour Co-authored-by: Ankush Menat <[email protected]>
marination
force-pushed
the
perf-bom-update-tool
branch
from
June 9, 2022 10:58
51b6a50
to
3fa0a46
Compare
ankush
approved these changes
Jun 9, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
First Draft
get_boms_in_bottom_up_order
update_cost
New BOM Cost Updation Flow
Consider the following BOMs and their dependencies:
Working:
Given the above example, on submitting the BOM Update Log, Raw Material BOMs will be processed first (batch size = 20k). The status will be In Progress
These Jobs will keep updating their row in the table in the Log and keep checking if all other jobs of this level are done (via
bom_batches
table)The Current Level is also maintained in the Progress Section, which will increment as we progress up the levels
Once a level is complete and the cron (every 5 mins) determines a level is complete (all rows of current level have status Pending -> Completed), it will prepare next level parent boms (dependants) and kickstart the next level
How do we determine "Parent BOMs" ? : By checking immediate parents with no Dependencies. Here 1 has immediate parents A and α (alpha). A can be considered since it has no unresolved/non-updated Dependencies, but α (alpha) has A and B as unresolved dependencies. So we proceed with A as parent of 1 in the next level.
A Cron Job will run every 5 minutes and check for In Progress jobs and start processing the next level if all jobs of current level are completed
The Log will be set as Complete when there are no more Dependants/ Parent BOMs to resolve/update
To Test:
Todo: