script for dealing with temporary files
Doyon, Jean-Francois
Jean-Francois.Doyon at CCRS.NRCAN.GC.CA
Mon Jun 19 06:46:22 PDT 2006
The problem there is that you cronjob is likely to delete files as they're
about to being used ... It's a fraction of a second, but it can happen (In
fact, it did for me).
The end result is that some very unlucky users get "broken" maps for no
obvious reasons (because the cronjob ran at that point in time between the
rendering of the map, and the browser fetching it).
This is why letting the image sit around for a few minutes is recommended.
Also, you can gain some performance from keeping the legend symbology around
... as they're relatively expensive, since there can be lots of very small
images, and the HTTP over head is marginally significant. If you keep them
around, not only does mapserver not render them unnecessarily, but also, the
browsers cache them. It makes a noticeable difference for us anyways, with
sometimes large HTML legends with lots of symbols.
J.F.
_____
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of M S
Sent: June 16, 2006 6:42 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] script for dealing with temporary files
how about a cron job:
0 1 * * * /path/to/script
that runs a shell script:
rm -f /path/to/tmp/files/*;
On 6/16/06, Doyon, Jean-Francois <
<mailto:Jean-Francois.Doyon at ccrs.nrcan.gc.ca>
Jean-Francois.Doyon at ccrs.nrcan.gc.ca> wrote:
Good idea.
Here's mine, written in Python. It preserves the legend symbology but
deletes other temporary images generated by mapserver:
#!/home/atlas/web/bin/python
# Directory where MapServer temporary files are created
TMPDIR = '/dev/shm/atlas'
# Time-To-Live (TTL) in minutes
TTL = 5
# Nothing to change below
from glob import glob
from os.path import getatime
from os import unlink
from time import time
import re
filelist = glob(TMPDIR + '/*.gif') + glob(TMPDIR + '/*.img.tmp')
grace = TTL * 60
for file in filelist:
try:
atime = getatime(file)
if atime < time() - grace and not
re.match('^.*?_\d{5,6}_\d{10}_\d{1,2}_\d{1,2}_\d{1,2}_\d{1,2}\.gif$', file):
unlink(file)
except:
pass
Cheers,
J.F.
-----Original Message-----
From: UMN MapServer Users List [mailto:
<mailto:MAPSERVER-USERS at LISTS.UMN.EDU> MAPSERVER-USERS at LISTS.UMN.EDU ] On
Behalf Of Bruce Raup
Sent: June 16, 2006 4:52 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU <mailto:MAPSERVER-USERS at LISTS.UMN.EDU>
Subject: [UMN_MAPSERVER-USERS] script for dealing with temporary files
I see in the mapserver documentation that a suggested way for removing
temporary files that mapserver creates is a simple 'find' command:
#!/bin/csh
find /usr/local/www/docs/tmp -follow -name "*.gif" -exec rm {} \;
A problem with this is that it even removes files that have just been
created. The -mtime option to find is a bit of help if you can wait a day
to delete files, but we didn't have that option. So I wrote a simple script
in perl that allows you to specify a minimum age in minutes a file should
have before it gets deleted. I'm sure many other people have written such
scripts, probably better ones than mine, but I thought I share mine since
it's definitely better than the above 'find' command. It's available at
http://cires.colorado.edu/~braup/software/clean_tmp_area.pl
<http://cires.colorado.edu/%7Ebraup/software/clean_tmp_area.pl>
If you have any comments or suggestions for improvement, I'd be happy to
hear about them.
Cheers,
Bruce
--
Bruce Raup
http://cires.colorado.edu/~braup/ <http://cires.colorado.edu/%7Ebraup/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060619/85a7c8f2/attachment.htm>
More information about the MapServer-users
mailing list