protected function _flowPredict($flow) { if (count($this->_arrFlow) >= 18) { array_shift($this->_arrFlow); } array_push($this->_arrFlow, $flow); $average = ceil(array_sum($this->_arrFlow) / count($this->_arrFlow)); $driveConf = $this->_objAha->getConfig()->get('aha', 'drive'); $maxFlow = $driveConf['max_process_num']; if ($average > $maxFlow * 0.85) { \Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->set(0); //根据流量预测 可能已经堵住了 清零自恢复 Log::monitor()->error(array(Monitor::KEY => Monitor::FLOW_OVER_PREDICT_RESET, 'average' => $average, 'maxFlow' => $maxFlow * 0.85)); } Log::statsLog()->debug(array('type' => 'flowPredict', 'average' => $average, 'maxFlow' => $maxFlow, 'point' => $maxFlow * 0.85)); return $average; }
public function next() { if (false !== $this->_line && is_resource($this->_fileHandle)) { $this->_line = fgets($this->_fileHandle); $this->_lineNo++; } elseif (count($this->_arrCity) > $this->_cityKey + 1) { if (is_resource($this->_fileHandle)) { fclose($this->_fileHandle); } while ($this->_cityKey <= count($this->_arrCity)) { $fileName = $this->_cityDir . $this->_arrCity[++$this->_cityKey]; if (!file_exists($fileName) || !($this->_fileHandle = fopen($fileName, 'r'))) { Log::appLog()->warning(array('cityFileNotFound' => $fileName)); continue; } else { break; } } if ($this->_fileHandle) { fseek($this->_fileHandle, 0); $this->_line = fgets($this->_fileHandle); } } (yield true); }
protected function _onAckProcess() { $this->_objProtocolPackage->readPipe($this->_worker); $arrPackage = $this->_objProtocolPackage->getPackages(); if (empty($arrPackage)) { return AHA_AGAIN; } foreach ($arrPackage as $package) { $message = json_decode($package, true); $cmd = intval($message['cmd']); switch ($cmd) { case Constant::PACKAGE_TYPE_COMPLETE: //来自distribute进程 通知drive进程继续发任务 //\Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->sub(1);//在distribute进程减1有最短路径 break; default: Log::appLog()->warning(array(Monitor::KEY => Monitor::UNEXPECTED_PACK, '%package' => $package)); break; } Log::billLog()->debug(array('%package' => $package, 'type' => 'onAckProcess')); } if ($this->_bolNeedTrigger) { $this->_bolNeedTrigger = false; $this->_onAckTrigger(); } return AHA_AGAIN; }
protected function _taskWorkerComplete($package) { $pid = $package['content']['pid']; $res = \Daemon\Library\Ipc\Shared::getCurrentTaskTable()->decr($pid, 'taskNum', 1); if (false === $res) { Log::monitor()->error(array(Monitor::KEY => Monitor::TABLE_DECR_ERR, '#package' => $package)); } $driveWorker = $this->_objManager->getDriveWorker(); list($drivePid, $driveProcess) = each($driveWorker); $ret = $driveProcess->write(json_encode($package) . Constant::PACKAGE_EOF); if (false === $ret) { Log::monitor()->error(array(Monitor::KEY => Monitor::IPC_PIPE_WRITE_ERR, '#package' => $package)); Log::redoLog(array('redo' => $package)); return false; } Log::billLog()->debug(array('#package' => $package, 'type' => 'complete')); return true; }
protected function _send($package) { $ret = $this->_worker->write(json_encode($package) . Constant::PACKAGE_EOF); if (false === $ret) { Log::monitor()->error(array(Monitor::KEY => Monitor::IPC_PIPE_WRITE_ERR, '&package' => $package)); Log::redoLog()->debug(array('redo' => $package)); } else { \Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->add(1); } Log::billLog()->debug(array('&package' => $package, 'type' => 'send')); }
protected function _send($package) { $ret = $this->_worker->write(json_encode($package) . Constant::PACKAGE_EOF); if (false === $ret) { Log::monitor()->error(array(Monitor::KEY => Monitor::IPC_PIPE_WRITE_ERR, '^package' => $package)); Log::redoLog()->debug(array('redo' => $package)); } \Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->sub(1); //在distribute进程减1有最短路径 if (\Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->get() > 2 << 16) { \Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->set(0); } Log::billLog()->debug(array('^package' => $package, 'type' => '_distributeResponse')); }