Optimizing a tile cache¶
While a tile cache for a layer automatically brings many improvements in performance—less time generating images, less redundancy—there are ways to optimize the cache so as to further improve performance and adjust it to your needs.
Use 8-bit images¶
PNG (Portable Network Graphics) is a popular file format for bitmap images. PNG is used in most cases except where a lossy compression format like JPEG would produce a more desired file size (for serving imagery). PNGs produced by GeoServer normally have a 24-bit “true color” color palette (2:sup:24 = 16.8 million colors).
In practice, such a large color palette is unnecessary for most map tiles. Unless the layer is rendering imagery files or other content requiring a full color palette, most of the time images will not be using anywhere near that many colors. More importantly, as PNG uses high quality lossless compression, those 24-bit colors take up a lot of unnecessary space.
Consequently, it is recommended to use PNG8 for tiles whenever possible. PNG8 forces GeoServer to use an 8 bit indexed color palette with only 256 colors. This can greatly reduce the size of image files.
For example, here is WMS output for the usa:states layer with format=image/png and the same request but using format=image/png8:
The above images were generated using the following requests:
The sizes are 31,098 bytes and 13,653 bytes, respectively. The PNG8 graphic is less than half the size of the PNG graphic.
The specifics of the disk space savings depend on the disk block size of the storage medium, but in almost all cases, there is a marked decrease in image size, with minor if any visual differences.
Reduce colors in symbology¶
Designing map symbology with a minimal color palette will ensure that the conversion from PNG to PNG8 does not introduce undesired visual effects. For this reason, using gradients would not be recommended.
Use paletted images¶
This functionality is not currently available using the embedded caching functionality in GeoServer, only in the standalone GeoWebCache.
When generating PNG8 tiles, it is often based on full color palette source imagery, and so the images will need to be “downsampled” to 256 colors. The determination of which 256 colors to use (known as the “palette”) is by default determined on a tile-by-tile basis. This downsampling is quite processing intensive, and can even sometimes lead to color-mismatch along tile boundaries, as a color could be mapped to different colors based on the content of each tile.
The way to prevent this is to create a image that consists of the 256 colors to use in the resulting PNG8, and then point GeoServer at this image. This “paletted image” can consist of any image content at all; the importance is the color palette used.
A simple way of generating a paletted image is by taking an appropriate-looking tile generated by GeoServer and using that as the paletted image. A more methodical way to generate the paletted image is to use a photo editing software and create a PNG8 image containing the desired color palette.
When the paletted image is created (in this example it is called palettefile.png), it must be referenced in the WMS requests that generate the tiles. This is done with the palette parameter: palette=pallettefile. Place the palette file in the GeoServer data directory in the palettes directory to eliminate the need for path info. If that is not possible, place the file in an web-accessible location, and add the path to the parameter: palette=http://path/to/palettefile.
Make sure to omit the file extension in the palette parameter.