Tutorial :Slow performance from MapServer



Question:

I'm using mapserver to create a map that will be displayed with the google map api. I'm encountering performances issues.

My maps are all in shapefile format.

I run tests to get time to render maps.

When rendering a map with the shp2img tool, using command line

shp2img -i gif -m C:\myfolder\mymapfile.map -o C:\myfolder\test.gif -all_debug 5 -map_debug 5  

I get the following metrics from the log files:

[Thu Apr 30 13:50:19 2009].148000 msLoadMap(): 0.000s  [Thu Apr 30 13:50:19 2009].180000 msDrawMap(): Layer 0 (PWorld2), 0.032s  [Thu Apr 30 13:50:19 2009].180000 msDrawMap(): Drawing Label Cache, 0.000s  [Thu Apr 30 13:50:19 2009].180000 msDrawMap() total time: 0.032s  [Thu Apr 30 13:50:19 2009].195000 msSaveImage() total time: 0.015s  [Thu Apr 30 13:50:19 2009].195000 msFreeMap(): freeing map at 01595E18.  [Thu Apr 30 13:50:19 2009].195000 freeLayer(): freeing layer at 0159CD00.  [Thu Apr 30 13:50:19 2009].195000 shp2img total time: 0.047s  

When rendering the same map through mapserver, using

http://localhost/cgi-bin/mapserv.exe?mymapfile.map&layers=&mode=tile&tilemode=gmap&tile=1+1+2  

log file is giving this:

[Thu Apr 30 13:51:50 2009].664000 CGI Request 1 on process 3520  [Thu Apr 30 13:51:50 2009].664000 msTileSetExtent (-10013744.792915, 8348.961808) (-5009.377085, 10010405.208192)  [Thu Apr 30 13:51:51 2009].23000 msDrawMap(): Layer 0 (PWorld2), 0.359s  [Thu Apr 30 13:51:51 2009].23000 msDrawMap(): Drawing Label Cache, 0.000s  [Thu Apr 30 13:51:51 2009].23000 msDrawMap() total time: 0.359s  [Thu Apr 30 13:51:51 2009].23000 msSaveImage() total time: 0.000s  [Thu Apr 30 13:51:51 2009].23000 mapserv request processing time (loadmap not incl.): 0.359s  [Thu Apr 30 13:51:51 2009].23000 msFreeMap(): freeing map at 01598690.  

For the same map, the shp2img tool is rendering map 10 times faster than mapserver. When adding more layers and using the tiling mode for google map, can be up to 10 seconds.

Is somebody knows why mapserver is rendering this slow? Is there a workaround?


Solution:1

There are a couple of differences between the shp2img and the mapserv request:

1) shp2img creates a single image, your mapserv request generates tiles. This means that it might have to render 9 tiles for the samen bounding box instead of 1. This generates overhead. Try rendering without the tiles option set and run your test again.

2) You have a small overhead for the cgi request in mapserv 3) Mapserv is pushing the image over http while shp2img is writing directly to disk. 4) You did not specify the layer in the mapserv request which means that mapserv goes looking for layers.


Solution:2

You can read this: http://mapserver.org/optimization/index.html

  • One of the most important point is to remove the unused projections in the EPSG file. E.g. under RedHat 6 /usr/share/proj/epsg I have 3 projections.
  • Remove unused fonts
  • The mapfile parser reads the file from top to bottom, hence put the most used layers at the top of the file (the EPSG parser works in the same way)

The shape files "should have" the same caller projection, otherwise Mapserver has to reproject them on the fly.

E.G. From my OpenLayers code (900913):

var options = {      projection: new OpenLayers.Projection('EPSG:900913'), //aka  EPSG:3785      displayProjection: new OpenLayers.Projection('EPSG:4326'), //geographic   

All my shape files are 900913 projection based.


Solution:3

I have a couple of suggestions but no hard answers, I haven't done much mapserver config but I've worked with people who have.

  1. There are a lot of optimizations you can do to mapserver, I'd check the mailing list.
  2. Make the mapfile as small as possible, as opening and parsing the mapfile can be time consuming for mapserver.
  3. Create all the tiles ahead of time and just use mapserver get the files. Tiling on the fly is not very fast.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »