-
Notifications
You must be signed in to change notification settings - Fork 240
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
Excessive Storage Utilisation - Tiles are cached at duplicate locations, never get pruned #2298
Comments
Interesting report! I did a brief test in the Tangram ES Android demo app to see if I could observe this. The demo app uses a similar caching configuration to yours, but limited to 16MB (https://github.com/tangrams/tangram-es/blob/main/platforms/android/demo/src/main/java/com/mapzen/tangram/android/MainActivity.java#L209-L225). What I observed is that the "Cache" amount in the Application manager corresponds almost exactly to the size of the Just to make sure that we're measuring the same things, can you check the size of your tile cache directory by using
Check the output of that and tell me whether it still differs from the "Cache" amount reported by Android. |
Okay, this is curious.
Copying over all files in that directory yields a directory whose size is 23 MB. The number of files contained is 5213. So, it looks like this is just the size on disk and the OkHttpCache counts instead the logical size. So, this explains the 2x rate of growing of the cache. This also explains why another user who set his cache size limit to 250MB reported in streetcomplete/StreetComplete#3417 that the cache size was reported to be about 500MB. The output of Only one third of the cache files are below 2KB, so I find it really surprising that the size on disk seems to be +100% the size. On the NTFS file system, it is +50% size. Anyway, I think this issue can then be closed, all has been answered. Thank you for your time! |
In any case, this is a finding that may be useful for providers of map tiles: Maybe rather have fewer large(r) map tiles than many very small ones. |
For anybody interesting in comparing results themselves, first command gives how much real space is used (
Also, |
FYI @Joxit @ianthetechie (anyone else I missed who might appreciate a heads-up?) |
Good information to know! This makes me think that it would be possible to implement a more space-efficient cache by combining tile responses into a single file - like a sqlite database. I don't expect to do this in Tangram ES but it might be possible for a client application. |
Hi there, yes file system is not adapted to tile storing, you should use SQLite based on the MBTiles specification |
@Joxit indeed MBTiles is what I had in mind when I mentioned an sqlite database. It's a tempting idea, but I think it would be pretty complicated for a couple reasons:
This doesn't mean it can't be done! Tangram ES allows a client application to replace the entire HTTP implementation, so you could certainly create a tile cache based on MBTiles if you wanted to. |
Hmm...
I am not sure if browsers put all the cached files in some kind of giant indexed table so they don't have this problem. I'd also be curious how MapLibre handles this. After all, MapLibre is pretty much the reference implementation that all the map tile providers cater for. |
Seems like the ideal setup would be an independent library which handles this. That way it could be shared between renderers, and only included when needed. |
Last I remember we did add some code to do offline Rendering via mbtiles. If needed we should be able to use that tile source class generically for all tile source cache? |
Yep, there is code in Tangram ES currently for caching vector tile sources in a local mbtiles database. However in its current form it isn't a substitute for HTTP caching. The existing mbtiles cache will naively store all tiles forever, regardless of the I looked into maplibre to see what approach is used there. It does seem to use a local sqlite database for tile caching, complete with parsing and logic for response headers. The maplibre caching code is in the shared native library, for reuse across platforms. A similar approach would make sense for Tangram ES. Tile caching could be implemented in the shared core library using sqlite, with options like the maximum cache size exposed to the client SDKs. I would support this approach, I think it could lead to a better user experience for Tangram ES. But the scope of this work is beyond my current availability (for the time being, at least). It would be nice if the caching code from maplibre could be shared in an independent library, but unfortunately it seems very tightly coupled with the internals of their renderer. |
Spawned from streetcomplete/StreetComplete#3417 .
In a nutshell
It looks like the map tiles are cached both at the location the user of this library specified and at another location at the same time. The issues are:
My cache configuration
The OkHttpCache actually prunes tiles in
sdcard/Android/data/de.westnordost.streetcomplete/cache/tile_cache
correctly when this directory exceeds a size of 50MB. I tested this.What is wrong? Observations
Reported cache size:
Actual size of external cache directory:
There are no other cache files in neither of
/sdcard/Android/data/de.westnordost.streetcomplete/cache/
/data/data/de.westnordost.streetcomplete/cache/
When panning the map and thus downloading new tiles, the reported cache size grows at pretty much at 2x the rate as the size of the external cache directory
When comparing the total free storage space on the phone before and after clearing the cache for the app, it is clear that the reported cache size by Android is not a display error: In this case, indeed 57 MB storage space has been freed.
However, the size of the directories mentioned in point 3 were reduced by only 22MB.
Thus, I conclude that there must be a third directory somewhere where the tiles are cached and that is never pruned that is outside of the directories mentioned in point 3 and used by tangram-es to store duplicates of the downloaded tiles.
Android is able to attribute this directory to the app and able to clear it but I have not found where on the sdcard it is supposed to be.
Used versions
The text was updated successfully, but these errors were encountered: