Testig persistent connections and load testing for multi-threading

From: Date: Thu, 23 Jul 2009 22:56:44 +0000
Subject: Testig persistent connections and load testing for multi-threading
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6535@lists.php.net to get a copy of this message
Hi, Quite late in the 5.3.0 process we discovered an issue partly related to persistent connections. This reminded me of a wish for a better way to test them as I don't like setting up a web server, running inside valgrind, and adding all that complexity for running such tests in an (more or less) automatic way. So I started writing a small tool using the embedded SAPI for that, after some testing I thought this might also be a good way to test TSRM/threading related stuff so I added a threading mode to it running multiple requests in parallel which didn't work well being based on the embedded SAPI so I transformed it into it's own SAPI. What it does is creating $c threads, optionally runs a start script in each of them, then runs $n times/thread a "main" script followed by a shutdown script. Each of these runs in it's own request context. Now I'd like to put it in PECL or somewhere (building SAPIs from PECL requires many additional steps, but I doubt this thing is needed in php-src...) using the PHP License. Current code name is "pconn" or "pconnect-test". A simple use-case is illustrated below; a thing I didn't figure out, yet, is how such a thing might be integrated into run-tests (old or new) Code (which still needs some cleanup) is at http://schlueters.de/~johannes/php/pconn.tar.bz2 johannes Usecase: start.php: <?php $_PCONN['cnt'] = 0; // That's a thread-persistent variable, similar to $_SESSION // or keeping some kind of status over equests echo "start ".(function_exists('zend_thread_id') ? zend_thread_id()." - " : '')."\n"; ?> main.php: <?php $_PCONN['cnt']++; if (function_exists('zend_thread_id')) { echo "thread ".zend_thread_id()."\n"; } else { echo "main\n"; } exit(PCONN_SUCCESS); // returning PCNN_FAIL would terminate the thread and call shutdown ?> shutdown.php: <?php echo "shutdown thread ".(function_exists('zend_thread_id') ? zend_thread_id()." - count: " : '') .$_PCONN['cnt']."\n"; ?> $ pconn -c2 -n10 -a start.php -z shutdown.php main.php start 2 start 3 thread 2 thread 3 thread 3 thread 2 .... thread 3 shutdown thread 3 - count: 20 thread 2 shutdown thread 2 - count: 20 A more useful use-case checking whether mysql_pconnect properly re-uses a connection could look like this: main.php: <?php mysql_pconnect(...); $threadid = mysql_thread_id(); if ($threadid != $_PCONN['thread_id') { $_PCONN['changed_thread_id'] = $threadid; exit(PCONN_FAIL); } else { $_PCONN['thread_id'] = $threadid; exit(PCONN_SUCCESS); } ?> shutdown.php: <?php if ($_PCONN['changed_thread_id']) { echo "The thread id was changed - something went wrong ...."; }

« previous php.pecl.dev (#6535) next »