Code Serialization

Posted by craigtussey on 2006-10-05 03:49

Hello,

Please help me understand how Perl handles the following situation. In the C language in a network environment, when a client calls a database function in a DLL to access a server database, a system semaphore is is used to serialize code access to prevent the destruction of data in dataspaces.

How does Perl handle this. Consider 2 clients out in the WWW using the same form to work on 2 different records of the same type. At submission, the form executes a database function and passes the data entered using the form. The function retrieves the data from the CGI-like connection, assigns the data to Perl dataspaces and begins processing the code series of the function. Now the 2nd client executes the function in the same way, right on the heels of the 1st client. Might the dataspaces be corrupted? How does this work?

Thank you in advance for any responses. I appreciate your time.

Craigt

jeff.griffiths | Thu, 2006-10-05 07:22

Perl itself doesn't handle that, it is instead left to the database backend. So if you have a stack like this:

PerlCGI / Apache / MySQL

Apache will actually start a different Perl interpreter for each CGI request. The two Perl interpreters don't know anything about each other. When the Perl data processing is done and the database code is executed ( in this case using Perl DBI ) it is completely up to the MySQL server to handle each intterpreter's connections and do the right thing.

As it happens, MySQL ( and Oracle, and SQL Server ) is really good at handling mutliple clients reading and writing data simultaneously, even to the same table in the database.

craigtussey | Thu, 2006-10-05 07:30

Thank you jeffg.

Is the same true, as far as starting a different Perl interpreter instance for each CGI request, under mod-perl. My technical environment is Windows, XP, Apache, Perl, and mod_perl. I'm doing my own I/O, right now, using the voluntary locking scheme of Perl.

Respectfully,
craigt

jeff.griffiths | Thu, 2006-10-05 09:59

No, mod_perl is completely different, and depends a lot on your configuration. It does generally do a much better job of re-suing interpreters and resources, even on Windows. For more on mod_perl generally:

http://perl.apache.org/start/index.html