Repository navigation
TASK-62: Remove N+1 in getQuantityOnHandByInventoryItem (expiry alerts p95 1339ms -> 241ms) - #11
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…em (remove N+1) Co-Authored-By: taylor.curran <taylorcurranagtc@gmail.com>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Author
This file contains hidden or 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
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.
✨ Description of Change
Link to GitHub issue or Jira ticket: TASK-62 (Devin Boards, latency optimizer)
Description:
ProductAvailabilityService.getQuantityOnHandByInventoryItem(location)groupedproduct_availabilityby theinventoryItemassociation, so Hibernate issued oneselect … from inventory_item where id=?per grouped row, and callers then lazily loaded each lot'sproduct(one more select per product). It backs the dashboard expiry alerts (/json/getDashboardExpiryAlerts,GET /api/dashboard/expirationSummaryon a cache miss), Expired stock / Expiring stock reports (HTML + CSV) andInventoryService.getInventorySampling.This change groups by
inventoryItem.id(the SQL of the aggregate query is unchanged, so row order is unchanged) and then loads the inventory items with their product in batches of 1,000 (select ii from InventoryItem ii left join fetch ii.product where ii.id in (:ids)). The returnedMap<InventoryItem, Number>has the same keys (InventoryItem equality is by id), values and iteration order.Original code author: the
groupProperty("inventoryItem")query was added by Walkowiak (awalkowiak@soldevelo.com) in aab76df "OBPIH-3316: Refactor queries against inventory snapshot to improve performance" (2020-11-17), with the bin-location variant later touched by Dariusz Rodzewicz in 9034da3 (OBPIH-6037). The expiry-alert caller (DashboardService.getExpirationAlerts) is Justin Miranda's (cfc5bfb, OBPIH-1602).Results —
GET /openboxes/json/getDashboardExpiryAlerts, Main Warehouse, 5,760 in-stock lots / 3,000 productsinventory_item+ 2,880productselects)in (…)selects)p95 −82%, p99 −90%. Query counts are from the MySQL general log for a single request.
Method: both revisions built with
./gradlew bootRepackageand run as packaged wars (java -jar, no spring-loaded agent; underbootRunthe agent adds a large reflection overhead to both sides: 4.2 s → 3.6 s p50 there), against the same MySQL 8.0.46 container and seed. 3 warm-up requests, then 60 sequential requests with curl%{time_total}; nearest-rank percentiles. 8 vCPU / 31 GB VM, JDK 8,-Xmx3g.Equivalence evidence
Captured from the before and after builds against the same data:
/json/getDashboardExpiryAlerts: byte-identical/api/dashboard/expirationSummary?locationId=1: byte-identical/inventory/listExpiringStock?status=within90Days&format=csvand/inventory/listExpiredStock?format=csv: byte-identical (row order included)./gradlew test --tests 'org.pih.warehouse.inventory.*': 59 tests, 0 failures.Cost / tradeoffs
INlist small enough for MySQL and the query plan cache.Repro
Seed (MySQL 8; MySQL 5.7 fails the Liquibase views changelog)
Build, run, benchmark
run.sh:
login.sh:
bench.sh:
Devin-Org: engineering
Implemented in session Find and fix next slow path in new repo
Review with Devin · Open in Devin Desktop
Note
Devin errored when opening this Pull Request as taylorcurranpython.
As a fallback, Devin opened this PR as itself.