avniproject / avni-server

Backend APIs for Avni
https://avniproject.org
GNU Affero General Public License v3.0
7 stars 25 forks source link

[DEA] Search is slow #810

Open mahalakshme opened 1 month ago

mahalakshme commented 1 month ago

https://avni.freshdesk.com/a/tickets/4778 and many more tickets

AC:

Image

Technical suggestions:

https://gist.github.com/petmongrels/353507f954ed0b31d434638ecacb90d0

Old: ignore:

AC:

Technical suggestions:

Inputs:

Out of scope:

some msg

petmongrels commented 3 weeks ago

https://avni.freshdesk.com/a/tickets/4778

petmongrels commented 3 weeks ago

https://gist.github.com/petmongrels/353507f954ed0b31d434638ecacb90d0

mahalakshme commented 2 weeks ago

@petmongrels for the 3rd case, I see the query still has distinct in the query. Cant understand what will be the effect on the search results. Aren't we searching in the latest encounter alone or in the latest enrolment alone?

mahalakshme commented 1 week ago

Image

1t5j0y commented 4 days ago

Changes made:

  1. Don't order search results by default. (Users can still sort by specific columns after getting search results.)
  2. Use exists by query to eliminate use of distinct
  3. Calculate count only for initial search. Pagination or sorting on a search result will use count already calculated for initial search.
  4. Added logging to keep track of time taken by DEA searches (across results and count queries) for later analysis.

Observation:

Areas for further investigation for improving performance:

  1. Bumping up db memory does improve performance for queries using joins which indicates that there might be scope for db tuning on existing instance or that it is time to bump db resources if current performance improvement isn't sufficient.

-- 1.1. Resource bump performance for joins (rough indication based on manual checks) JSCS coded concept search - db.t3.medium (1.83 minutes), db.t3.large (36.22s) Note: With the current code change, this search now roughly takes 34s on db.t3.medium

-- 1.2. DB Tuning further reading and config recommendations

1t5j0y commented 3 days ago

Removed calculation of count on server and display of count on webapp as agreed. Concept and name searches for JSCS are well under 5 seconds now (tested against prerelease) .

mahalakshme commented 1 day ago

@petmongrels you are reviewing this no?