Kraken: Improve /line_reports perf #4104
Merged
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.
Apply PTRef filters only once to all before iterating on lines.
This greatly improves perfs when there is a "difficult" PTRef filter and still a lot of lines to iterate on (like Bus mode on Paris region).
Perfs:
measures done without any disruption loaded locally:
/line_reports
with difficult filter, the gain is proportional to the number of lines in response (gain x750v1/physical_modes/Bus/line_reports
on Paris for 1350 lines).Little gains without filter.
with all disruptions on Paris region after improvement:
Compared to no-disruption kraken's durations are between x1 and x2 slower, which is more than acceptable.
No point in removing shortcuts in PTRef, the time to build candidates to removal is too short.
JIRA: https://navitia.atlassian.net/browse/NAV-2150
Details
Ideas not explored (by order of expected ROI):
has_applicable_message()
calls: prefilter sub-objects on has_applicable_message (hard to do just once with the line being mandatory for rail/line-sections).contains()
calls on routes: consume prefiltered routes when buildingLineReport
(linked to a single line)contains()
call on networks: iterate on prefiltered networks to buildLineReport
(line linked to a single network). Lines will have to be correctly sorted after.Measures:
v1/physical_modes/Bus/route_schedules?count=25&items_per_schedule=10
: same perfv1/line_reports
: Paris 100ms > 50ms (gain x2).v1/networks/<main bus network>/line_reports
: Paris 4.25s > 40ms (gain x106), Lyon 2.58s > 35ms (gain x73)v1/commercial_modes/Bus/line_reports
: Paris 67.7s > 130ms (gain x520), Lyon 411ms > 12ms (gain x34)v1/physical_modes/Bus/line_reports
: Paris 181.7s > 240ms (gain x750), Lyon 6.45s > 54ms (gain x119)-> Not worth removing the shortcut