HHVM-运行资源丰富的php守护进程

HHVM - Running resource extensive php daemons

本文关键字:守护 进程 php 运行 资源丰富 HHVM-      更新时间:2023-10-16

嗨,我正在尝试使用hhvm来运行我的应用程序中当前存在的所有后台PHP工作程序。我不想把hhvm作为服务器运行,因为Apache已经在处理它了,我只想用hhvm运行我的php代码,而不是用常规的Zend引擎。

好的,这是我想要运行的代码。

这是我想要运行的计算密集型模块的入口点

-------------**RunRenderer.php**--------------
#!/usr/bin/php
<?php
require_once 'Config.php';
require_once 'Renderer.php';

Renderer::getInstance()->run();

?>

这里只是主控制器的一小部分,用于控制/forks/管理数千个php任务/进程。

----------------------------Renderer.php---------------------
<?php
require 'Workers/BumpMapsCalc.php';
/**
* Main Entry class of the Map rendering module
* 
* Create workers for all of the different maps calc sub routines 
* 
* 
* 
*/
class Renderer extends Core_Daemon {
/**
* the interval at which the execute method will run
* 
* Interval : 10 min
* 
*/
protected $loop_interval = 600;
/**
* Set the chunk size
*/
protected $chunkSize = 500;
/**
* Loop counter
*/
protected $loopCounter;
/**
* Low limit and the high limit
*/
protected $lowLimit;
protected $highLimit;

/**
* set the plugins for lock file and settings ini files
* 
*/
protected function setup_plugins() {
$this->plugin('Lock_File');
$this->plugin('settings', new Core_Plugin_Ini());
$this->settings->filename = BASE_PATH . "/Config/settings.ini";
$this->settings->required_sections = array('geometry');

}

protected function setup() {

$this->log("Computing Bumps Maps");
}
/**
* Create multiple separate task  that will run in parallel
* Provide the low limit and the high limit which should effectively partition
* the whole table into more manageable chunks , thus making importing and 
* storing data much faster and finished within 10 min
* 
*/
protected function execute() {

for ($this->loopCounter = 1 ; $this->loopCounter <= $this->settings['geometry']['number'] ; $this->loopCounter += $this->chunkSize) {
$this->lowLimit = $this->loopCounter;
$this->highLimit = $this->loopCounter + $this->chunkSize;
$this->task(new LocalBumpMaps($this->lowLimit, $this->highLimit));
}

}
protected function log_file() {
$dir = BASE_PATH . "/Logs";
if (@file_exists($dir) == false)
@mkdir($dir, 0777, true);

return $dir . '/log_' . date('Y-m-d');
}
}
?>

所以通常我会以的身份运行程序

php RunRenderer.php -d -p ./pid/pid $1

它将调用默认的zend引擎,Renderer.php将派生数千个LocalBumpMaps实例(以及100个其他地图渲染类)。现在,由于每个子任务占用大约20-30 mb的内存,工作站中的所有内存都会很快耗尽,从而导致系统戛然而止。

当然,主渲染引擎是用C++编写的,但由于一些奇怪的要求,整个前端都是用PHP编写的。php模块每秒需要执行大约数十亿次计算。因此,剩下的唯一选择是使用HHVM,希望能显著提高性能和效率。但问题是,我无法让这些代码与hhvm一起运行。这就是我正在尝试的

hhvm RunRenderer.php -p ./pid $1

这根本没有任何作用。没有进程被分叉,没有输出,什么都没有发生。所以有人能告诉我如何用hhvm而不是zend运行php脚本吗。

我希望我的问题有道理,我真的很感激任何帮助。

谢谢,Maxx

只需先运行以下行而不分叉进程:

hhvm RunRenderer.php

如果您看到控制台输出,并且您可以Ctrl+C终止进程,那么您可以使用Upstart脚本妖魔化进程。创建一个名为/etc/init/render.conf:的文件

start on startup
stop on shutdown
respawn
script
hhvm RunRenderer.php
end script

然后,您可以通过运行以下程序手动启动和停止该过程:

start renderer

stop renderer

如果你运行的是Ubuntu 12.04LTS及以上版本,系统会自动为你创建一个名为/var/log/unststart/renderer.log的日志文件。你可以通过跟踪文件来获取实时输出:

tail -f /var/log/upstart/renderer.log