Skip to content

Cache tiles in ready-to-serve encoding #1112

@nyurik

Description

@nyurik

Current State

Since v0.13, Martin caches tile data as it comes back from the individual sources (PG/mbtiles/pmtiles). This means that if mbtiles contains gziped-compressed MVT tiles, cache will contain that tile, and no re-compression will be needed. If PostgreSQL generates an uncompressed tile, the tile will be cached, but each tile request has to gzip that tile anew. This is the usual case unless user has a custom PG function that uses a gzip extension to compress the tile on the database side.

Goals

  • Martin should cache data after compressing it
  • Martin could re-compress responses in Brotli even if the storage format is gzip.

Solutions

  • generic solution - either as a custom function or a proper Actix "filter", capture the entire request (URL path + query + accept-encoding), and cache/send back the most optimal response
  • per end-point (tiles vs tilejson vs sprites ...) a more custom implementation that takes into account the specifics of each endpoint. This might be easier to implement, but also means that each endpoint will have to write a bit of extra code.

Brotli vs Gzip

Per Brotli wiki, it offers significantly better rate of compression and decompression performance than gzip. Desktop Chrome current default Accept-Encoding is gzip, deflate, br (tested on Linux with latest Chrome). Reading Quality_values seem to indicate that the order of the values is irrelevant as long as they have the same "q" value (default is 1), which means that the "gzip, deflate, br" string indicates it is OK to send back Brotli, even though it is 3rd in the list. Obviously if br is not in the list, it will have to be gzip or identity.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions