-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimisation du système de routage #4286
Comments
The existing routing system, having been developed more than a decade ago, is now outdated and better solutions have since emerged. However, the route is calculated in the user’s browser, leading to several drawbacks:
In order to solve the above issues, three pull requests have been opened. PR #4070 moves the route calculation from the browser to the server, while PR #4245 builds on this advancement and implements a more efficient backend routing system using pgRouting. To finish, PR #4263 builds upon this and uses a more performant routing algorithm, again using pgRouting. PR #4070: moving the routing system from the frontend to the backendThis pull request paves the way for future improvements that will enable faster routing and the handling of a larger topological network. This contribution focuses on relocating the routing system to the backend and assessing the performance differences related to this calculation’s location. To this end, the routing system that has been implemented server-side in this pull request had to be the same as for the browser-side one. It consists of Dijkstra's algorithm, written in JavaScript for the frontend routing, and in Python for the backend routing. A benchmark comparing the original and the new routing systems has been conducted. It assesses the gains in performance if the project were to switch to the new calculation system. Here is the report (in French): The automation of the benchmarking process discussed in the report, which facilitates the execution of numerous time-consuming measurements, has been made generic to allow for future reusability. This benchmarking system has been included into the pull request so it can help future optimization efforts. It is located in the Additionally, the necessary restructuring of the frontend code has led to several extra enhancements. First, the user experience has been improved. When a user creates steps that lead to an impossible route, the GeoTrek-admin interface now assists them in correcting these steps. This can happen when markers are placed on paths that are not linked, as well as when they try to place a marker outside of a path. Second, the implementation of this new system has led to the modification of the route edit process, which solved a historic bug. When a user needs to modify an existing trek, the interface has to display its route along with its editable markers. In the original system, the browser displays these markers and recomputes the route which is then displayed. This leads to an issue: if the path network has changed since the creation of the trek, it is possible for the old and the new route to be different. This is unwanted behavior: the route should not be modified without user input. It is also worth noting that this new system gets rid of the real-time update of the route during the drag-and-drop of a marker. Keeping this feature would have involved continuously sending requests to the backend, which would be heavy on the server and demand significant network resources. PR #4245: SQL-based route calculation using pgRoutingThis pull request replaces the Python-based routing system with a database-driven one, aiming to further improve the performances in terms of both speed and data volume capacity. By performing the routing directly in the database where the paths are stored, we eliminate the need to fetch and process them with Python, which can slow down calculation. As mentioned in the first benchmark report attached above, in order to apply Dijkstra’s algorithm, the Python implementation requires the generation of a graph and an adjacency matrix, which are cached. The SQL implementation also requires a graph, which is stored in the database. When a path is added, modified or deleted, this graph (and adjacency matrix) must be updated. A performance benchmark comparing this new pull request to the first one has been completed as well. Unlike the previous benchmark, it only measures execution times at the backend level, and has been conducted in a production environment in order to take measurements using a realistic PostgreSQL configuration. It is however similar to the previous benchmark in the following ways:
This graph shows the average execution times for Python and SQL routing systems, with and without a pre-generated graph (and adjacency matrix in the case of the Python implementation), for a request with 100 via-steps. Contrary to the first pull request’s benchmark, where the 100 via-steps were added one by one and thus sending 3-via-steps requests each time, this second benchmark sends a unique 100-via-steps request. Note that these measurements simulate cases where the whole path network has been added either with or without pre-generating the graph (by caching it for the Python implementation or by launching the PR #4263: optimization of route calculation using the A* algorithmThis pull request retains the use of pgRouting but replaces Dijkstra’s algorithm with the A* algorithm, which is more efficient for such routing applications. This graph shows the average routing execution times for both of these algorithms. Note that these measurements were not conducted in a production environment, unlike those for PR #4245. Therefore, they only serve to compare these two algorithms and do not reflect realistic execution times. It can be seen that the A* algorithm is indeed faster than Dijkstra’s algorithm, with a time difference of almost 2 seconds (7.9 seconds vs. 9.7 seconds). |
Thanks for this big enhancement, its documentation and all the technical and performance benchmarks. Thanks to your tests and benchmark, we see that we should only keep the pgRouting A* algorithm, in order to be easier to maintain only one system. |
Congrats for this work and well detailed post! It's great to see that you are still bringing changes to Geotrek's core despites its age ❤️ |
Thank you for the job, we look forward to seeing the presentation tomorrow! It will solve many issues we experienced with new paths interfering existing treks... |
No description provided.
The text was updated successfully, but these errors were encountered: