Benutzerspezifische Werkzeuge
Sie sind hier: Startseite Documentation FAQs

Is MapServer Thread-safe?

Artikelaktionen
Zum Inhaltsverzeichnis
Is MapServer Thread-safe?

Q: Is MapServer thread-safe?

A: Generally, no (but see the next question). Many components of MapServer use static or global data that could potentially be modified by another thread. Under heavy load these unlikely events become inevitable, and could result in sporadic errors.

Q: Is it possible to safely use any of MapServer in a multi-threaded application?

A: Some of it, yes, with care. Or with Python :) Programmers must either avoid using the unsafe components of MapServer or carefully place locks around them. Python's global interpreter lock immunizes against MapServer threading problems; since no mapscript code ever releases the GIL all mapscript functions or methods are effectively atomic. Users of mapscript and Java, .NET, mod_perl, or mod_php do not have this extra layer of protection.

A: Which components are to be avoided?

Q: Below are lists of unsafe and unprotected components and unsafe but locked components.

Unsafe:

  • OGR layers: use unsafe CPL services
  • Cartoline rendering: static data
  • Imagemap output: static data
  • SWF output: static data and use of unsafe msGetBasename()
  • SVG output: static data
  • WMS/WFS server: static data used for state of dispatcher
  • Forcing a temporary file base (an obscure feature): static data
  • MyGIS: some static data

Unsafe, but locked:

  • Map config file loading: global parser
  • Setting class and and layer filter expressions (global parser)
  • Class expression evaluation (global parser)
  • Setting map and layer projections (PROJ)
  • Raster layer rendering and querying (GDAL)
  • Database Connections (mappool.c)
  • PostGIS support
  • Oracle Spatial (use a single environment handle for connection)
  • SDE support (global layer cache)
  • Error handling (static repository of the error objects)
  • WMS/WFS client connections: potential race condition in Curl initialization
  • Plugin layers (static repository of the loaded dll-s)

Rather coarse locks are in place for the above. Only a single thread can use the global parser at a time, and only one thread can access GDAL raster data at a time. Performance is exchanged for safety.

Diese FAQ betrifft: MapServer 4.6, MapServer 4.8

von Sean GilliesZuletzt verändert: 07.08.2006 17:33
Mitwirkende: Sean Gillies, Umberto Nicoletti, Tamas Szekeres

MapScript for web clients

Kommentar von Adrian Kruk am 21.01.2008 05:48
I don't know architecture of mapserver. So listed unsafe components telling me nothing except my imagination what these components are doing.
Above answer need some examples of code (e.g. C# with mapscript_csharp lib)

We have this kind of situation.
We have ASP.NET application and we are using mapscript_csharp dll.
Each of browser clients will have its own map object instance stored in session cache. So each client request is creating new thread on server.

So, new client must wait for its map object if mapscript is just creating map object for other client (other thread), even if our server has many processors?
Becouse of Map config file loading its global parser and it is locked.
I Am wrong?

The same situation after some time. Two clients (two threads on server) requests for image calling map.draw(). This is unsafe situation becouse of 'some static data in Imagemap output'?





Any answer so far?

Kommentar von Alejandro Ruiz am 31.07.2008 18:28
We have also a .NET application, coded in C#. When used by a single user, it works just fine, it creates the maps neatly. Nevertheless, when more than one user are logged in and try to create a map at the same time, Mapserver is not being able to handle this, it locks the application and after a few minutes, the server times out and throws an expection message to each user: Sys.WebForms.PageRequestManagerTimeoutException:

I found this link: http://www.gisdevelopment.net/technology/gis/ma03197pf.htm ,

therefore I know it is possible to use Mapserver in a multi-user environment.

Would it be that once the first user opens the .map file, it locks it and won't let others open more instances of it, but at the same time his/her session won't be able to release it once it has finished parsing it?

Please advise.
Thanks.
 

Powered by Plone