100% CPU usage.

General discussion forum for the Zend Server
Post Reply
davidsh
Posts: 7
Joined: Mon Jan 30, 2012 8:53 am

100% CPU usage.

Post by davidsh » Mon Dec 23, 2019 11:22 am

Hi,

I have a problem with a php file in ZendServer6 calling RPG program, this put my CPU usage at 100%.

The server notificate Hight memory usage or Slow Request Execution and we can see CPU of server at 100% :
(for now we have zendserver and zendserver6 runing at same time)

Image
Image
Image


I do a persistent connection in Config file :
Image

In my php file i set Toolkit with $conn variable:
Image

This is the complete code for PHP file:

Code: Select all

<?php 

include_once zend_deployment_library_path('PHP Toolkit for IBMI i') . DIRECTORY_SEPARATOR . 'iToolkitService.php';
include_once 'CI5Toolkit.php';
include_once 'I5toolConfig.php';
include_once 'i5_Config.php';
// /////////////////////////////////////////////////////////////////////////////////////////////////////////

$ToolkitSrvObj = ToolkitService::getInstance($conn); ////print_r($ToolkitSrvObj);
$Dq = new DataQueue($ToolkitSrvObj);
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
$libl = 'PHP'; 
$DataQQue = 'PREGUNTA';
$DataQRes = 'RESPUESTA';
/************ FORMAT DATA *************/
$user		= trim(strtoupper($_REQUEST['user']));
$nlistado	= trim(strtoupper($_REQUEST['nlistado']));
$siglas		= strtoupper($_REQUEST['siglas']);
$visualiza	= trim(strtoupper($_REQUEST['visualiza']));
$cicsel		= trim($_REQUEST['cicsel']);
$ses		= trim($_REQUEST['sesion']);
///////////////////////////////
$keyrand="L3az2M";
$ses.=$keyrand;

if ($conn){
	UserFormat($user);//control del usuario
	frmtNomList($nlistado);
	frmtSiglas($siglas);
    	frmtcicsel($cicsel);
    	ValidateData('text',$ses,$spc,32,32,$vda);
	ValidateData('text',$user," ",1,10,$vda1);
	ValidateData('text',$nlistado," ",10,10,$vda2);
	ValidateData('text',$siglas," #",4,9,$vda3);
	if ( $visualiza!='Z' && $visualiza!='V' ) {
		$vda4=false;
	}
	else{
		$vda4=true;
	}
	ValidateData('number',$cicsel," ",12,12,$vda5);		
    $vda1=true;
    if ($vda && $vda1 && $vda2 && $vda3 && $vda4 && $vda5){
        if(strlen($siglas) > 4 && strlen($siglas) < 9 ){
            
			$KeyQueu=$ses."COMAND  ".$user.$nlistado."    ".$siglas.$visualiza.$cicsel;							
        }
        else{
			$KeyQueu=$ses."COMAND  ".$user.$nlistado.$siglas.$visualiza.$cicsel;							
        }
	
		VarQueuFormat($KeyQueu,128);
        	$Dq->SetDataQName($DataQQue, $libl); 
        	$Dq->SendDataQueue(128, $KeyQueu, 0, $ses); 
        	$Dq->SetDataQName($DataQRes, $libl);
		$i=0; $c=$d=$t=$l=$v=$e=$f=$m=$p=1;//inicializo los indices
        	$ret_rec = $Dq->ReceieveDataQueue(0, 'EQ', 32, $ses, 'Y');
        	$info2 = explode('¬', $ret_rec['datavalue']);
        	$info = [];
        	foreach ($info2 as $datos) {
            		$datos = trim(substr($datos, 0, strlen($datos) - 3));
            		array_push($info, $datos);
        		}
			if (trim($info[0]) == 'ENDRDQ' || trim($info[0]) == 'ER00'){
            		$arrJsonResponse["error"] = json_encode($info[1]);
		}
		else {
			if ( trim($info[0])== 'ER00' ){
				$arrJsonResponse["error"] = json_encode($info[1]);
			}
			else{
				while(trim($info[0]) != "ENDRDQ"){
					switch(trim($info[0])){	
                        case 'XXX0':
                        $arrJsonResponse["XXX0".$i] = implode("#", $info);
                        $i++;
                        break;
                      	case 'XXX1':
			case 'XXX2':
			case 'XXX3':
                        case 'XXX4':
                                                
                           	$arrJsonResponse["xxxx".$f] = implode("$", $info);				
				$f++;
                            	break;														
				}
			$ret_rec = $Dq->ReceieveDataQueue(0, 'EQ', 32, $ses, 'Y');
                    	$info2 = explode('¬', $ret_rec['datavalue']);
                    	$info = [];
                    	foreach ($info2 as $datos) {
                        	$datos = trim(substr($datos, 0, strlen($datos) - 3));
                        	if ($info2[0] != null) {
                        		array_push($info, $datos);
                        	}
                    	}
                    	

                }	
			}
		}		
	}
}
else{
    $arrJsonResponse["ERROR"] = "Error en el tipo de datos.";
}
echo json_encode($arrJsonResponse, JSON_PRETTY_PRINT);
?>
I don't see why this request have hight CPU usage and slow response.

Anyone can help me ?

Post Reply