Scanning…
Before you start …
This page is about running faster using persistent and private pooled connections workload balancing techniques. This is not a discussion about using QTEMP or *LDA in called RPG programs across browser clicks, that is a different topic entirely.
Server set up asks if Developer or Production. If Developer, Z-Ray is on by default, but easy to turn off. If Production, Z-Ray is off by default, but easy to turn on. Z-Ray is recommended to be off in Production for performance and security reasons. It can be set up in secured mode in production to only be used on pages deliberately accessed by a developer.
There are many ways to workload balance PHP Toolkit connections:
$ToolkitServiceObj->setToolkitServiceParams( array('stateless'=>true));
// php:db2_connect <- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user" -> XTOOLKIT:XMLSERVICE $ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user"))
// php:db2_connect :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user1" -> XTOOLKIT:XMLSERVICE(1) // rand pick server: // :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user10" -> XTOOLKIT:XMLSERVICE(10) $ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user".rand(1,10))
The following is a relative performance guideline:
<?php // job 1 (client) job 2 (server) // any php-cgi job attach QSQSRVR call XMSLERVICE // ------------------ ------------------------------ // php:db2_(p)connect <- XML IN/OUT -> QSQSRVR:XMLSERVICE $extension='ibm_db2'; try { $ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass, $extension); } catch (Exception $e) { echo $e->getMessage(), "\n"; exit(); } $options = array('stateless'=>true,'plugSize'=>'4K'); $ToolkitServiceObj->setToolkitServiceParams($options); $ToolkitServiceObj->disconnect();
<?php // job 1 (client) job 2 (proxy) job 3..13 (10 servers) // any php-cgi job QSQSRVR passthru XTOOLKIT(s) ready (always) // ------------------ ------------------ -------------------------- // php:db2_(p)connect:<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user1" -> XTOOLKIT:XMLSERVICE(1) // :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user2" -> XTOOLKIT:XMLSERVICE(2) // rand pick a server: // :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user10" -> XTOOLKIT:XMLSERVICE(10) $extension='ibm_db2'; try { $ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass, $extension); } catch (Exception $e) { echo $e->getMessage(), "\n"; exit(); } $maxpool = 10; // 10 jobs good enough to handle my machine needs $internalKey = '/tmp/packers'.rand(1,$maxpool); $ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>$internalKey)); /* Do not use the disconnect() function for "state full" connection */ /* NEVER EVER USE THIS ... $ToolkitServiceObj->disconnect(); */ /* Why? *immed kill of job, not nice or sync, just kill */
<?php // job 1 (client) job 2 (proxy) job 3..13 (10 servers) // any php-cgi job QSQSRVR passthru XTOOLKIT(s) ready (always) // ------------------ ------------------ -------------------------- // php:db2_(p)connect:<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user1" -> XTOOLKIT:XMLSERVICE(1) // :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user2" -> XTOOLKIT:XMLSERVICE(2) // rand pick a server: // :<- XML IN/OUT -> QSQSRVR:XMLSERVICE <- "/tmp/$user10" -> XTOOLKIT:XMLSERVICE(10) require_once("ToolkitService.php"); $i5persistentconnect = true; if ($i5persistentconnect) $conn = db2_pconnect($database,$user,$password); else $conn = db2_connect($database,$user,$password); if (!$conn) echo "Bad connect: $conn,$database,$user,perm=$i5persistentconnect"; try { $ToolkitServiceObj = ToolkitService::getInstance($conn); } catch (Exception $e) { die($e->getMessage()); } $maxpool = 10; // 10 jobs good enough to handle my machine needs $ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>'/tmp/packers'.rand(1,$maxpool),'plug'=>'iPLUG32K'));
Always use PgmCall API for speed including data area, job attributes, etc. (V6+ also call CL and OPM *PGM with PgmCall), most command functions will run significantly slower.
$ToolkitServiceObj->CLInteractiveCommand
$ToolkitServiceObj->CLCommandWithOutput
$ToolkitServiceObj->CLCommand
$ToolkitServiceObj->PgmCall
Setting plug size to match your data size can offer increased performance.
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>'/tmp/packers'.rand(1,$maxpool),'plugSize' => '15M'));
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>'/tmp/packers'.rand(1,$maxpool),'plugSize'=>'512K'));
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>'/tmp/packers'.rand(1,$maxpool),'plugSize'=>'4K'));
Why a plug size at all?
DB2 connections are safe reliable transport for XML documents between client (PHP) and server (XMLSERVICE), but DB2 forces you to declare IN/OUT parameter size of any call procedure, XMLSERVICE download includes a few different stored procedure sizes (iPLUG4k .. iPLUG15M), so your script needs to choose the IN/OUT size that fits your data.
Tony “Ranger” Cairns - IBM i PHP / PASE