opencaching / opencaching-pl

The source code of Opencaching.PL (and some other domains)
https://opencaching.pl/
GNU General Public License v3.0
22 stars 33 forks source link

Gpx export memory issue #1006

Open kojoty opened 7 years ago

kojoty commented 7 years ago

from oc.pl forum:

Post autor: Kipcior » poniedziałek, 8 maja 2017, 08:47 Żeby nie zakładać nowego tematu. Dzisiaj mam problem z eksportem wyników wyszukiwania do gpx. Jak zawsze wybrałem kryteria: Polska, wielkopolskie, reszta bez wykluczeń. Wyrzuciło mi liste ponad 3800 skrzynek. Po kliknięciu eksport do gpx wszystkich wyników wyszukiwania mieliło mieliło by po jakims czasie pokazac info: Firefox nie może odnaleźć pliku https://opencaching.pl/ocplgpx9909973.g ... =max&zip=1. Próbowałem kilka razy, zmieniając kryteria. Zawsze ten sam rezultat.

error example in log: [Mon May 08 09:38:35.706903 2017] [:error] [pid 28018] [client 81.15.211.114:5293] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 100708352 bytes) in /srv/ocpl/lib/search.gpxgc.inc.php on line 565, referer: https://opencaching.pl/search.php?searchto=searchbyname&showresult=1&expert=0&output=HTML&sort=bydistance&f_inactive=0&f_ignored=0&f_userfound=0&f_userowner=0&f_watched=0&f_geokret=0&country=PL&region=PL41&cachetype=1111111110&cache_attribs=&cache_attribs_not=&cachesize_1=1&cachesize_2=1&cachesize_3=1&cachesize_4=1&cachesize_5=1&cachesize_6=1&cachesize_7=1&cachesize_8=%7Bcachesize_8%7D&cachevote_1=-3&cachevote_2=3.000&cachenovote=1&cachedifficulty_1=1&cachedifficulty_2=5&cacheterrain_1=1&cacheterrain_2=5&cacherating=0&cachename=%25&gpxLogLimit=100&cachename=

andrixnet commented 7 years ago

The query does return 3865 caches... and there are 100 logs requested for each cache... It is concievable that 100MB memory limit can't handle the actual amount of data.

kojoty commented 7 years ago

yeah, and we need to find a way to deal with such request or prevent such requests...

andrixnet commented 7 years ago

Possible solutions:

deg-pl commented 7 years ago

From FB profile of RT: User > RT:

Cześć od dwóch dni nie mogę pobrać pliku gpx z sekcji "Eksport wszystkich skrzynek". Przez jakiś czas kręci się kółeczko ale się nie otwiera pole "Rozpoczęto pobieranie pliku". Potem otwiera się czysta strona w przeglądarce i koniec. Wcześniej wszystko działało bez zarzutu.

deg > user:

Hej - deg z tej strony Wczoraj w logach zauważyłem próby pobrania ogromnej ilości skrzynek - zakończone błędem. Być może to właśnie Twoje próby. Przed chwilą sprawdziłem dla mojej okolicy i bez problemu pobiera GPXa. Napisz proszę jakie filtry wyszukiwania stosujesz i ile skrzynek jest do pobrania.

user > RT:

Próbowałem pobrać skrzynki w promieniu 100km bez własnych i znalezionych. Łączna liczba skrzynek to 3500. Wcześniej nie było z tym problemu. Plik miał zwykle ok. 110MB. Pojedynczego GPX pobieram - problem jest przy pobieraniu grupy GPXów. a strona, która mi się pojawia na biało ma adres: https://opencaching.pl/ocplgpx9975037.gpx?startat=0&count=max&zip=1

From server logs: [Wed Sep 20 12:10:31.388279 2017] [:error] [pid 27521] [client 89.70.135.77:52676] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 125579264 bytes) in /srv/ocpl/lib/search.gpxgc.inc.php on line 546, referer: https://opencaching.pl/search.php?searchto=searchbydistance&showresult=1&expert=0&output=HTML&sort=bydistance&f_userowner=1&f_userfound=1&f_inactive=1&latNS=N&lat_h=52&lat_min=07.550&lonEW=E&lon_h=21&lon_min=04.000&distance=100&unit=km

deg-pl commented 7 years ago

This is not good solution. I've added downloadMemorylimit and tried to export big (28765 caches) GPX. Server stoped to respond for many minutes. After over 10 minutes I restarted apache. There was no error in error.log.

following5 commented 7 years ago

Have tested again after the rollback: The server is also blocked with the old implementation, so that's an old problem. It just gets worse by allowing even bigger downloads.

following5 commented 7 years ago

This is a session handling problem. By default you cannot open a second page on the website as long another page is still loading in your web browser. Other users are not blocked.

A call to session_write_close() solves the problem.

deg-pl commented 7 years ago

Good news! Thanks for checking.

Have you any idea how to shorten time (resources?) needed to create large GPX?

following5 commented 7 years ago

After some quick profiling, I see three options for optimization:

following5 commented 7 years ago

These figures came from testing on the develsite with mostly cached data. But now I did a 1500 caches GPX download from Opencaching.pl twice, and the second GPX was created MUCH faster. This points to the SQL queries as bottleneck.

following5 commented 7 years ago

My fix - as proposed in #1252 and #1266 - would have immediately solved this issue, whatever maximum number of caches would be allowed to limit the download size and time.

But the discussion now is escalating in a way (see #1266 and #1273) which makes it too expensive for me to follow. Surely the GPX download can be optimized, but that's much work, and I wonder if it will ever be done.

I will retain my branch with the proposed fix for some weeks, for the case someone wants to finish it this way.