httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owen Boyle <...@bourse.ch>
Subject Re: memory/caching problem?
Date Mon, 17 Dec 2001 09:06:09 GMT
Dave Shaw wrote:
> 
> We're experiencing a problem that may be some sort of bizarre memory
> management problem in a Apache/FreeBSD/Perl CGI environment, and are
> hoping someone else has seen or heard of something similar (not that
> anyone would wish this on anybody else).
> .....
> Perhaps the only unusual thing about the error-prone CGI scripts
> we've observed is that they are calling perl 'flock' (on a normal
> file).

Aha! - if you're file-locking you must be writing and reading to/from
files... This is tricky on a busy server.

Remember that there are many httpd daemons running soncurrently on your
system and it is quite common for two or more CGI programs to run at the
same time. If they are all using the same file, it is quite easy to find
two or more instances reading and writing simultaneously. This will
cause no end of fun.

The fact that you already use "flock" indicates you are aware of this,
but I would guess that perhaps you haven't implemented all the locking
you need and that you still get some corruption. Work carefully through
your program and make sure that if it writes something to a file, noting
else can write to the same file until you're finished. A common mistake
is to do:

lock_file();
write_to_file();
unlock_file();

do_stuff();

lock_file();
read from_file();
unlock_file();

You should do:

lock_file();
write_to_file();

do_stuff();

read from_file();
unlock_file();

If there is a gap between writing and reading (i.e. separate invocations
of the program) then you need to use distict filenames for each process
and pass filenames between invocations using hidden parameters, etc.

Rgds,

Owen Boyle

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message