views:

138

answers:

1

Hi,

When an http request is processed by the Apache web server it typically forks a new process unless one is using something like fastcgi.

My question is related to "simultaneous requests" when using fastcgi.

If I'm using fastcgi and I have a tree-like datastructure in main memory, do I need to worry about concurrent read/write access to the tree?

Or can I just rely on the fact that requests are processed in the order they arrive.

What if one request tries to access the disk and it blocks? Are the other requests processed or do they wait in a queue?

If I'm not using fastcgi, things seem clearer since I have to reload the tree data structure from a database to manipulate it and then write it back to a database - no concurrency required.

Essentially, do I need to worry about multiple readers/writes to my main memory data structures with Apache?

Thanks in advance.

+1  A: 

When an http request is processed by the Apache web server it typically forks a new process

No, usually one of pre-forked processes accepts the connection and executes it. There is no fork-per-request

If your FastCGI application is single threaded, you should not worry about concurrecy, also if you run in mod-prefork. But if you manage your data structures in shared memory you should worry about concurrency.

Artyom
Thanks for the clarification regarding forking but I was thinking of CGI applications regarding process creation - from wikepedia:"CGI is a protocol for interfacing external applications to web servers. CGI applications run in a separate process, which is created at the start of each request and torn down at the end."Sorry for the confusion, hopefully my question will make more sense now.
pdshift
I didn't fully understand the issue with shared memory explanation - my apologies for being a bit slow. Say a request comes in and a mod-prefork process modifies the shared memory. Next another request comes in and modifies it. If the order is preserved, I'm not clear where the issue is.
pdshift
Ok... I meant the Apache itself. Yes, you are right, CGI is forked per-request and **exits** after response, so, there should not be any concurrency problem, unless you access process shared memory vima mmap or shmem, that I assume you do not.
Artyom