HHVM-运行资源丰富的php守护进程
HHVM - Running resource extensive php daemons
嗨,我正在尝试使用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
- 守护进程()有什么缺点吗?
- boost-asio 作为守护进程的"template"
- Linux 守护进程 - 运行函数两次
- Unix域套接字(C++)-客户端使服务器守护进程崩溃
- HHVM-运行资源丰富的php守护进程
- DBUS 代码在放置在守护进程内时崩溃,但在没有守护进程代码的独立独立 main() 函数中运行良好
- 启动-停止守护进程启动的C程序无法捕获信号
- 如何使本机Unix/Linux守护进程在Android上工作
- 创建C++守护进程并保护环境
- 与守护进程对话
- 从服务器套接字创建守护进程处理
- 在服务器上执行守护进程
- API控制Linux守护进程
- 程序(nload)在shell中执行时作为守护进程运行,但不在启动/自动化脚本中执行
- c++守护进程服务器停止
- 我不希望一个作为守护进程的服务器进程关闭——即使在收到终止信号时也是如此.有什么办法可以确保这一点吗
- C++守护进程不会收到 SIGCHLD 信号
- 如何为apache守护进程设置LD_LIBRARY_PATH
- 监视守护进程的状态
- 在c++中使用ifstream打开和关闭后,snmptrapd守护进程不再写入.txt文件