5

I search for a good WMS server that support PostGIS at the end I found MapServer as the fastest and best choice.

Every performance test say it's faster than GeoServer because of its native compiled code.

Then when we developed our server side using MapScript (the MapServer extension for PHP).

When we did some benchmark on server and compared it with GeoServer and

Wow! MapServer is 2 to 3 times slower than GeoServer.

We also repeat the experiment with MapServer CGI and results not changed.

Our experiment environments:

  • Windows 7 64 bit
  • MapServer version 6.0.3 (MS4W 3.0.6) (MS4W/PHP Mapscript)
  • GeoServer 2.7
  • PostGIS 2.1
  • PostgreSQL 9.4

The PHP code which used to render tiles and used as WMS server:

<?php
if(!isset($_REQUEST['layerId']))
    die('Layer Is Not Valid');

$layerId=(int)$_REQUEST['layerId'];

$map=new mapObj(null);
$map->setFontSet(realpath("lib\\server-side\\fonts.list"));
$map->setConfigOption("MS_ERRORFILE",__DIR__.("\\ms_error.log"));

$map->metadata->set('wms_enable_request','GetCapabilities GetMap GetFeatureInfo');
$map->metadata->set('wms_getmap_formatlist','image/png,png,png8,png24');
$map->setProjection("init=epsg:4326");

$layer = new LayerObj($map);

$layer->set('labelcache', MS_ON);
$layer->setProcessing('LABEL_NO_CLIP=FALSE');
$layer->setProcessing('FORCE2D=YES');

$layer->set('name', "MasterLayer");
$layer->set('status', MS_DEFAULT );

$layer->setConnectionType(MS_POSTGIS);
$layer->set('connection', "user=postgres password=psgpass dbname=map host=127.0.0.1 port=5432");
$layer->set('data', "geodata from geo_data as subquery using SRID=-1 using unique id ");

$layer->set('type', MS_LAYER_POLYGON);

$class = new ClassObj( $layer );

$style = new StyleObj( $class );
$style->color->setRGB(255,0,0);
$style->set('opacity',100);

$request = new Owsrequestobj();
$request->loadparams();
$request->setparameter('REQUEST', 'GetMap');
$request->setparameter('LAYERS', 'MasterLayer');
$request->setparameter('FORMAT', 'png8');

ms_ioinstallstdouttobuffer();
$map->owsdispatch($request);

$contenttype = ms_iostripstdoutbuffercontenttype();

if (!empty($contenttype))
{
    header('Content-type: $contenttype');
    ms_iogetStdoutBufferBytes();
}
else 
    echo "Fail to render!";
ms_ioresethandlers();
?>

DataBase Data Projection: EPSG:4326

Does anybody know why GeoServer is much faster when it isn't compiled natively? Am I missed something?

9
  • 1
    potentially relevant question here. Also, this presentation linked to in one of the comments. FastCGI is mentioned frequently.
    – wchatx
    Commented Jul 12, 2015 at 15:18
  • the first link really no i saw it before. The Second One Can Help But Most Of Those Optimization I Applied Before
    – MSS
    Commented Jul 12, 2015 at 15:38
  • we need to know what sort of data you have, how it is styled, how you configured the two programs etc
    – Ian Turton
    Commented Jul 12, 2015 at 15:49
  • @iant if you mean data base its Geometry and Polygon Type and data come from postgres database. If it help i can put php and data sample here. I really think mapserver should be faster and I did some thing wrong or some driver is missing or the version is too old
    – MSS
    Commented Jul 12, 2015 at 17:52
  • both programs has a layer with EPSG4326 and feed by same table. Every polygon have a simple fill color and border. Actually I disable all options in mapserver to make it faster but performance didn't change too much and still the geoserver is the absolute winner.
    – MSS
    Commented Jul 12, 2015 at 18:01

2 Answers 2

6

According to a recent comparison of different mapping engines in performing tile seeding (see Section 4.3), MapServer should be much faster than GeoServer.

Is there any re-projection of geometries in your rendering stack?

An old version of MapServer might have the same issue with proj4 lib as Mapnik had.

6
  • About re-projection I'm not sure data in database(postgres) saved with EPSG4326 and map file projection is also is also 4326 . The server make wms tiles for openlayers 3. Unfortunately I cant find the binaries' the latest version of mapscript (php) for windows to test performance. About the proj4 i dont know exactly which version is used (its a dll without details) but from exe it version is: Rel. 4.8.0, 6 March 2012
    – MSS
    Commented Jul 13, 2015 at 17:38
  • Mapscript exact version: MapServer version 6.0.3 (MS4W 3.0.6) OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS= THREADS SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
    – MSS
    Commented Jul 13, 2015 at 18:08
  • Might be worth trying with a 64 bit version of MapServer (say from GISinternals)
    – nmtoken
    Commented Jul 14, 2015 at 11:31
  • 1
    It doesn't include PHP-MapScript actually any of their releases !
    – MSS
    Commented Jul 19, 2015 at 19:03
  • according this benchmark, geoserver is faster but mapserver renders nicely: esdm.co.uk/… Commented Jul 21, 2015 at 2:13
3

Unless you have a requirement to dynamically manipulate the images created by MapServer you should use the CGI application to server WMS requests. If not PHP will need to create all those objects in your code for every request, which if you are using tiles will be ~16 per map view.

You should also set mapserv.exe to run using FastCGI. See the instructions at http://www.ms4w.com/README_INSTALL.html#g-fastcgi

To take full advantage of FastCGI add the following to each layer that reads from a database:

PROCESSING "CLOSE_CONNECTION=DEFER"

This will mean the database connection can be reused between requests, otherwise every layer may have to create, open, and close a database connection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.