Repository navigation
Index trade_executed_view.order_book_id for GET /query/executed-trades/{orderBookId} - #23
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
…s/{orderBookId}
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)".
|
Co-Authored-By: taylor.curran <taylorcurranagtc@gmail.com>
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.
Summary
GET /query/executed-trades/{orderBookId}(trader-app, the trades list on the order book screen) runsTradeExecutedQueryRepository.findByOrderBookId, i.e.select ... from trade_executed_view where order_book_id=?.trade_executed_viewonly had its primary key (V1__baseline_schema.sql), so every call did a full scan of a table that gets one row per executed trade and never shrinks (EXPLAIN:type=ALL, rows=1000000).This adds the index
idx_trade_executed_view_order_book_id (order_book_id):V2__index_trade_executed_view_order_book_id.sql: Flyway migration for thekubernetesprofile (V1 is untouched, so its checksum is unchanged).information_schema.statisticsdoes not already list it, because a database Hibernate updated underlocaland then baselined at V1 underkubernetesalready has it (MySQL 5.7 has noCREATE INDEX IF NOT EXISTS).@Table(indexes = @Index(...))onTradeExecutedView: the same index for thelocalprofile, which builds the schema withddl-auto=update.No query, entity field or response changes.
Before / after (local, scratch MySQL 5.7, one trader-app at a time, alternating A/B)
1,000,000 rows in
trade_executed_viewover 2,000 order books (about 500 trades each). Sequential requests to a random order book after 10 warm-ups, 100 requests per run, ms:The exact Hibernate SQL on its own (pymysql, 3 alternating pairs × 60 queries): p95 465–585 ms → 6–14 ms, p99 505–683 ms → 15–30 ms.
Method / repro
docker run -d --name esarch-bench-mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=trader -e MYSQL_PASSWORD=trader -p 127.0.0.1:3316:3306 -v $PWD/docker/mysql/initdb:/docker-entrypoint-initdb.d:ro mysql:5.7, then loadtrader-app/src/main/resources/db/migration/V1__baseline_schema.sqlintoappdb.trade_executed_viewrows (randomorder_book_idfrom 2,000 UUIDs, seed 129) withLOAD DATA LOCAL INFILE.docker run -d -p 127.0.0.1:5672:5672 -e RABBITMQ_DEFAULT_USER=trader -e RABBITMQ_DEFAULT_PASS=trader rabbitmq:3.7-management,java -jar discovery-server/target/discovery-server-0.0.1-SNAPSHOT.jar.mvn -B -DskipTests package; runSPRING_PROFILES_ACTIVE=local ESARCH_MYSQL_PORT=3316 java -jar trader-app/target/trader-app.jar --logging.level.io.pivotal.refarch=INFO --spring.jpa.hibernate.ddl-auto=validate.GET /query/executed-trades/{id}sequentially; each pair runs "before" (no index) then "after" (CREATE INDEXfrom V2) against the same running server and data.Equivalence
generatedId, SHA-256) are identical before/after in every pair:fe4447e63e0d3da5,c6b530eaebff2728,dc61c2fc9f46d8b6. The SQL-only runs also hash identical row sets.kubernetespath (Flyway +ddl-auto=validate) applies V1 and V2 successfully and validates; thelocalpath (ddl-auto=update) creates the same index from the annotation. Both reach/actuator/healthUP.mvn -B verify(all modules) passes.Cost
TradeExecutedEventinsert also updates the index: one extra B-tree insert per trade. No caching, no stale data.Original code
TradeExecutedViewandTradeExecutedQueryRepository.findByOrderBookIdcome from the upstream Axon Trader: Allard Buijze allard.buijze@axoniq.io (bfd9855, 2018) and Steven van Beelen smcvbeelen@gmail.com (a083fe1, 2018). The Flyway baseline without the index came from #11 (devin-ai-integration).Runtime verification (testing agent)
Final build (db9a553) returned the same 466 trades as the pre-fix build for a seeded order book (sorted SHA-256 match); unknown order book still 404. Three more alternating A/B pairs (100 requests per state): p95 505.7/451.3/340.7 → 43.4/61.8/18.9 ms, p99 582.5/463.4/431.0 → 244.6/123.3/36.0 ms, hashes identical. Fresh
localandkubernetesschemas and a local→kubernetes switch on the same schema all reachUPwith one index and V2success=1. The order book UI does not call this endpoint, so the recording shows the live API.Note
Opened as Devin instead of Taylor Curran: the GitHub account taylorcurranpython has no write access to COG-GTM.
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.