Style Optimizations¶
The following section explains how GeoServer performances are improved when using optimized styles since styling is an important feature but requires some attention in order to avoid slowing down the performances. This tutorial aims at showing how GeoServer performances change by choosing a different style for the same data set using JMeter.
Note
This example requires to have already completed Adding a Shapefile, Adding a Style and the first 9 steps of the Creating a Base Map with a Layer Group section.
Use scale dependencies¶
One of the key tricks with styling data is to delay the display of detailed layers at higher zoom levels by filtering data based on attributes to display only the important features first.
If you show too much data the map will not be readable, but rather a graphic blob. Rule of thumb: never show more than 1000 features (records) max in the display. A few additional hints:
- Have labels show up only when zoomed in
- Show details as you zoom in
- Eagerly add MinScaleDenominator to your SLD rules
- Add more expensive rendering when there are less features, this is key to get both a good looking and fast map
In the picture below we can see various applications of scale dependencies. Detailed layers, such as streets and buildings, show up only when fairly zoomed in. The DEM is hidden when we get very close to the city to avoid getting the representation too «busy», visually speaking. The streets change from simple line to cased line.
Labeling¶
Labels are one of the most important elements in creating good looking maps. Here below some recommendations:
Labeling conflict resolution is expensive, limit to the most inner zooms
Halo is important for readability, but adds significant overhead
Be careful with maxDisplacement, makes for various label location attempts
The Concept of FeatureTypeStyle¶
GeoServer uses SLD FeatureTypeStyle objects as Z layers for painting. Each one allocates its own rendering surface (which can use a lot of memory), hence the recommendation here is to use as few of them as possible.
Use translucency sparingly¶
Translucent display is expensive, use it sparingly (e.g. translucent fill <CssParameter name="fill-opacity">0.5</CssParameter>
).
Delay the display of detailed layers at higher zoom levels, filter based on attributes to display only the important features first.
Ok now let’s dive into benchmarking various styling options.
Configuring GeoServer¶
On your Web browser, navigate to the GeoServer Welcome Page.
Go to Styles and click on
Add new Style
On the bottom of the page, click on Choose File and select the SLD file called
line_label
in the$TRAINING_ROOT/data/jmeter_data
(%TRAINING_ROOT%\data\jmeter_data
if you are on Windows ) directoryClick on Upload and then on Submit. Now we have a style which supports labeling but has no control on the label conflicts and overlapping
Return to the GeoServer Welcome Page.
Go to Layer Groups and click on
test
Add a new Layer to the Layer Group called bbuildings
Change the associated styles by clicking on each style and choosing another one on the list. Use the following styles:
Layer Style geosolutions:Mainrd line_label geosolutions:BoulderCityLimits polygon geosolutions:bplandmarks polygon geosolutions:bbuildings polygon Click on Save. With this configuration we have a Layer Group composed by 4 Layers with 4 bad styles associated. This will result in a low throughput, if compared to that of the test with optimized styels.
Configuring JMeter¶
Go to
$TRAINING_ROOT/data/jmeter_data
(%TRAINING_ROOT%\data\jmeter_data
on Windows ) and copy the filetemplate.jmx
file and create astyles.jmx
oneFrom the training root, on the command line, run
jmeter.bat
( orjmeter.sh
if you’re on Linux) to start JMeterOn the top left go to File –> Open and search for the new jmx file copied
Disable Thread Group 8, 16, 32 and 64
In the active
CSV Data Set Config
elements, modify the path of the CSV file by setting the path for the filestyle.csv
in the$TRAINING_ROOT/data/jmeter_data
( or%TRAINING_ROOT%\data\jmeter_data
on Windows ) directoryIn the HTTP Request Default element modify the following parameters:
Name Value layers test srs EPSG:2876
Test with unoptimized styles¶
Run the test. You should see something like this:
Note
Remember to run and stop the test a few times for having stable results
When the test is completed, Save the results in a text file.
Remove the result from JMeter by clicking on Run –> Clear All on the menu
Setting optimized styles¶
Go to Layer Groups and click on
test
Change the associated styles by clicking on each style and choosing another one on the list. Use the following styles:
Layer Style geosolutions:Mainrd mainrd geosolutions:BoulderCityLimits citylimits geosolutions:bplandmarks arealandmarks geosolutions:bbuildings buildings Click on Save. The new styles contain scale dependencies and label optimization, which will result in a better throughput.
Test with optimized styles¶
Run again the test.
You may see that the throughput is greater than that of the first test. The use of scale dependencies reduces the layers to see at lower zoom levels while conflict resolution avoids to show multiple overlapping label at each zoom level.