Shift DB load from Primary to Replicas Rapid Action | Goal 2: reduce the number of CI requests spending more than 50ms on primary db wall-time per request from 4.2% to 2%
A very small proportion of requests are responsible for a large share of the time we spend in statements and transactions in the primary database. For CI Sidekiq jobs, 2% of jobs represent 74% of primary db query time. For the CI api, a similar 2% of jobs represent 36% of query time on the primary database. Many of these high latency queries are the result of n+1 sql queries, gaps in application limits, pathological edge cases, etc. If we prioritise this reducing these expensive queries, we can make a resolve the low-hanging fruit and potentially make a big difference to the amount of traffic these edge cases contribute to load. This is how this metric has performed (since Monday, when we obtained the instrumentation we needed to measure this), and keeping in mind that Tuesday involved a major outage. **Progress towards this goal is being tracked in this spreadsheet** https://docs.google.com/spreadsheets/d/1EGcN7B1J6PJq3F6ES0_j4AecWdXy6ouUpNL8qpf9grE/edit#gid=0 the spreadsheet includes ELK links reports for adding new data. Finding expensive rails endpoints to prioritise -- use this ELK query: https://log.gprd.gitlab.net/goto/18ed63d7946a98bc7e1724ad0d06536b Finding expensive sidekiq endpoints to prioritise -- use this ELK query: https://log.gprd.gitlab.net/goto/f27771a86b399a100e112e3df79f9947 # Progress Towards Goal **Progress towards this goal is being tracked in this spreadsheet** https://docs.google.com/spreadsheets/d/1EGcN7B1J6PJq3F6ES0_j4AecWdXy6ouUpNL8qpf9grE/edit#gid=0 the spreadsheet includes ELK links reports for adding new data. Updating the spreadsheet should update this chart. ![](https://docs.google.com/spreadsheets/d/e/2PACX-1vQbNI-2KjcWUBirx4CXg5VC-75B7xzPficlT8ejb1egyDGo1q7MN1ghuBP-13psVn3SOe49WOlnPFaf/pubchart?oid=464843183&format=image)
epic