[mapserver-users] Mapserver Thread Safety

Umberto Nicoletti umberto.nicoletti at gmail.com
Wed Nov 19 06:35:47 PST 2008


On Wed, Nov 19, 2008 at 3:10 PM, Nelson Soto <NSoto at plotplans.com> wrote:
> So I kind of feel stupid at the moment…
>
> I had one understanding of thread safety and now I think I have another

that is the effect of learning, congrats!

>
> My first understanding was that if multiple users were accessing a site
> programmed very basically (not with any type of "multi-threading" code) but
> simply the fact that multiple users were making requests that they could
> potentially bump into requests and not return the same result if only one
> user were making requests.
>
> Now, I think it means specifically programming for a "multi-threaded"
> application so that you are using multiple code paths asynchronously in a
> given request would not be recommended without placing code-locks for
> various features.

Depending on the platform you are using both statements can be true as
they are different cases of multi-threading.

In the case of mapserver the checklist is as follows:

If you are using mapserver as a CGI then thread safety is not an issue
for you because each request will be handled by a new process that
will die immedately after so basically there is no chance of 'bumping
into others' requests' as you call it.

Same if you're using python, because of a quirk in the python
interpreter called GIL (Global Interpreter Lock) which stops the whole
python interpreter when entering external code such as the C shared
library of mapcript.

If you are using fastcgi AND have compiled mapserver with thread
support also no need to worry, unless you use one of the unsafe
components listed in the thread safety FAQ on the mapserver web site.

If you are using Java/C#/PHP/Ruby AND have compiled mapserver with
thread support you don't have to worry that much actually because
mapserver will lock properly when entering the same thread-unsafe code
paths listed in the FAQ cited above.

So your question eventually boils down to: should I also place locks
in my C#/Java code?
In general I would say it is not (I don't in my java app) provided
that you don't share mapscript objects between requests: don't create
a mapObj at the beginning of the session and reuse it for all the
session. Create a new mapObj with every request instead.

HTH,
Umberto

>
> Can someone please clarify for me what the thread-safety is in regards to
> Mapserver and Mapscript C#, PHP and Java and perhaps clarify one thing; If I
> am programming without implementing multiple threads in code but plan to
> have multiple users accessing the site, will they bump into any requests?
>
>
>
> Sorry for the ignorance, and thank you..
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>



More information about the MapServer-users mailing list