mild-blue / txmatching

Solver for kidney pair donation matching problems.
https://txm.demo.mild.blue
Other
2 stars 2 forks source link

Investigate why is the app so slow #1029

Closed kubantjan closed 1 year ago

kubantjan commented 1 year ago

Find out what are the bottlenecks. Propose solutions.

kubantjan commented 1 year ago

Sem prosim psat vystupy investigace @krllstdn

krllstdn commented 1 year ago

1. Optimise get_hla_antibodies_from_recipient_model() #1045

image On the image generated with snakeviz library is shown the time that takes a function call. As can be seen the function _from_dict () takes too much time to complete. get_hla_antibodies_from_recipient_model() is used almost everywhere, so if we optimize it we might significantly increase speed of the whole application. image On the image above are shown three endpoint calls that are made in calcucate page.

  1. http://localhost:8080/v1/txm-event/3/patients/configs/default
  2. http://localhost:8080/v1/txm-event/3/configuration/default
  3. http://localhost:8080/v1/txm-event/3/matching/calculate-for-config

I decided to code something that will be faster than _from_dict() function. And so I did. You can see results in PR #1045

So maybe it is worth checking other cases of Dacite library usage. #1047

kubantjan commented 1 year ago

Zkontrolovat jestli nevolame neco zbytecne

kubantjan commented 1 year ago

Next steps:

1) zkontorlovan jestli nevolame veci zbytecne (get_hla_antibodies_from_recipient_model ta vypada ze ji volame treba v http://localhost:8080/v1/txm-event/3/patients/configs/default kde to vypada, ze to k nicemu neni? 2) zkontrolvoat jestli nevolame v endpoitech veci nekolikrat 3) get_hla_antibodies_from_recipient_model vypada ze fakt trva dlouho - udelat issue na jeji zrychleni 4) sem pridat profil toho kdyz otevru matchings stranku a patients stranku detailni

krllstdn commented 1 year ago

Bod 1:

  1. V http://localhost:8080/v1/txm-event/3/configuration/default se vola cely get_txm_event_complete() i pres to ze by stacilo get_txm_event_base(). Na strance Matchings to zrychlilo ten endpoint call z 746ms (na obrazku) do 30ms
  2. http://localhost:8080/v1/txm-event/3/patients/configs/default tam musi byt (jestli ji blokuju v Developer Tools tak hned vsechno padne)

Bod 2

V trech zminenych endpointech narocne veci se nevolaji vicekrat.

Bod 3:

1045

Bod 4

Matchings (po optimalizaci)

Image

Patients (po optimalizaci)

Image

krllstdn commented 1 year ago

@kubantjan chci opravit bod 1 v bode 1 v me odpovedi. Potrebuju na to vytvorit issue i PR? nebo staci proste pridat do #1046? tam opravy na jeden radek, ale vytvaret issue a PR mi pride zbytecny. Jak to udelat nejlip?

kubantjan commented 1 year ago

@krllstdn klidně to přidej

kubantjan commented 1 year ago
krllstdn commented 1 year ago

Matchings page

image total time: 3,02s

1. Calculate for config

By function call in API

get_txm_event_complete()

2. http://localhost:8080/v1/txm-event/3/patients/configs/default (gets all patients for txm event 3 in 1,32s)

get_txm_event_complete()

the same as above. two "low-hanging fruits".

3. http://localhost:8080/v1/txm-event (gets all txm events without patients)

It could be faster, but I haven't seen nothing in particular that could be improved easily.

Other endpoints are already extremely fast.

Conclusions

Things that can be improved very fast and potentially bring further noticable iincrease in speed are

krllstdn commented 1 year ago

@kubantjan v conclusions jsou action items, ktere muzou byt udelane dost rychle

kubantjan commented 1 year ago

get_hla_typing_from_patient_model() vidím tam že píšeš že by šlo zrychlit ale nevidím kolik času to teď trvá

krllstdn commented 1 year ago

Opraveno. Trva to 0.475s. Skoro cely ten cas zabira from_dict(), tak ze teoriticky by se dalo optimalizovat a to by mohlo trvat 0.1-0.2 s. Je to dostatecny cas pro optimalizaci nebo na to vykaslame?

kubantjan commented 1 year ago

Jop to stojí za to udělaj issue a rovnou na něj mrkni

krllstdn commented 1 year ago

Patients page

Here it is a bit slower due to include-antibodies raw. image

http://localhost:8080/v1/txm-event/3/patients/configs/default?include-antibodies-raw

this include-antibodies-raw makes it slower

Queries take the biggest chunk of its completion time, so probably no easy solutions here.

krllstdn commented 1 year ago

rewriting get_recipient_from_recipient_model() without patient_base had no impact on speed. And from point of readability it also does not make much sense, so this was a bad idea.

krllstdn commented 1 year ago

Dacite

dacite is also used in

kubantjan commented 1 year ago

So the conclusion now is that if we want to focus on speedup we shall focus on sql queries. Is that right? @krllstdn ?

krllstdn commented 1 year ago

Yes, this is the slowest thing that there is.