|
Posted by Richard Lynch on 01/06/05 19:36
Plan on doing a LOT of testing -- My guesses on the probability of
thread-safety were just that: GUESSES
Thread-safe bugs are the kind of thing that can remain hidden for *YEARS*
or even *DECADES* and not get triggered but once in a million executions
of your scripts.
By definition, they rely on *TWO* copies of your script running in
"parallel" and timing is everything.
For example, suppose your script is like this:
<?php
/* LOTS OF CODE */
thread_bug_function();
/* LOTS OF CODE */
?>
You can run that script a million times, and nothing will go wrong.
You can even run your web-server with multiple copies of your PHP script
running a million times and nothing will go wrong.
Let's examine the case of just *TWO* Apache children processes, running
your script in parallel.
Depending on when one script starts, when it gets interrupted by the OS so
other processes can run, and when it re-starts, you have *THREE* possible
cases:
(where the "time" at which something is run is indicated in a vertical
manner.
CASE #1:
APACHE CHILD ONE APACHE CHILD TWO
<?php <?php
/* LOTS OF CODE */ /* LOTS OF CODE */ thread_bug_function();
thread_bug_function(); /* LOTS OF CODE */
/* LOTS OF CODE */ ?>
?>
CASE #2:
APACHE CHILD ONE APACHE CHILD TWO
<?php <?php
/* LOTS OF CODE */ /* LOTS OF CODE */
thread_bug_function();
/* LOTS OF CODE */ thread_bug_function(); /* LOTS OF CODE */
?> ?>
CASE #3:
APACHE CHILD ONE APACHE CHILD TWO
<?php <?php
/* LOTS OF CODE */ /* LOTS OF CODE */
thread_bug_function(); thread_bug_function();
/* LOTS OF CODE */ /* LOTS OF CODE */
?> ?>
CASE #1 and CASE #2 cause no problem at all -- The 'thread_bug_function'
doesn't run at the same time in one child as the other child, because of
the timing -- it runs BEFORE or AFTER the same function in the other
child.
CASE #3 will crash big-time, because the thread-bug got executed at the
SAME TIME in BOTH children.
But here's the thing: The *larger* your code base, the better the odds
are that CASE #1 and CASE #2 will happen, because there is so much going
on in the /* LOTS OF CODE */ sections.
The ONLY time the bug is triggered is when the two scripts happen to try
to execute the buggy line AT THE SAME TIME.
So CASE #3 is super super super rare. And it gets more and more rare as
you add more and more code (yours or the PHP Modules you are asking about)
to your project.
The more you think about this, the more you'll realize just how impossible
a question you are posing, and just how complicated you are making your
server by using threads.
There is NO PRACTICAL WAY to systematically test for a thread bug.
Only disciplined coding by experienced software developers will avoid
thread bugs -- and even that is hardly a "given"
So you're really really really going out on a limb to use the threads.
If you *NEED* the threads, you are going to have to pay a heavy heavy
heavy price in doing a *TON* of testing under heavy load servers, with as
much variance in timing of script start/end as you can introduce.
Every line of code you add, and every Module you load in to add
functionality/features will GEOMETRICALLY INCREASE your risk and the need
for testing.
The reason you kept getting "bad" answers, or answer at all, is you kept
asking a "bad" question :-)
Things to consider:
#1. Do you really *NEED* threads?
#2. If you *DO* need them, can you segment your application and modularize
and isolate the thread usage to a single server, or a single body of code,
or an isolated case that will be called rarely or ???
#3. Do you have the resources to run a billion tests?
If you need threads, and you can't isolate them to a sandbox, and you
don't have the resources for a billion tests, QUIT NOW.
You will save yourself a ton of money and frustration by not tackling an
insurmountable project that will ruin you.
"A man's got to know his limitations"
-- Dirty Harry
symbulos partners wrote:
> I apologise for the last e-mail concerning this subject, but I had not
> received your e-mail back.
>
> Thanks for the explanations, they will be very useful.
> --
> symbulos partners
> -.-
> symbulos - ethical services for your organisation
> http://www.symbulos.com
>
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|