Question

Hi i'm trying to use hhvm to run all of the background PHP workers that are currently there in my application. I don't want to run hhvm as a server as Apache is already taking care of it , all i want to do is to run my php codes with hhvm, instead of the regular Zend engine.

Ok here are the codes which i want to run.

This is the entry point of the computationally intensive modules that i want to run

-------------**RunRenderer.php**--------------
#!/usr/bin/php
<?php

require_once 'Config.php';

require_once 'Renderer.php';



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


?>

Here is just a small a portion of the main controller that controls/forks/manages thousands of php tasks/processes.

----------------------------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');
    }

}

?>

So normally i would run the program as

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

which would invoke the default zend engine and Renderer.php would fork around thousands of instances of LocalBumpMaps ( along with 100 other map rendering classes ). Now with each of this subtasks taking around 20-30 mb all of the memory in the workstation gets exhausted pretty quickly thus causing the system to screech to a halt.

Of course the main rendering engine is written in C++, but due to some weird requirement the whole front end is in PHP. And the php modules needs to perform around billions of calculations per second. So the only options that was left was to use HHVM in hopes of some significant increase in performance and efficiency. But the problem is i can't get this code to run with hhvm. This is what i'm trying

hhvm RunRenderer.php -p ./pid $1

This doesn't do anything at all. No processes are forked, no output, nothing happens. So can anyone please tell me how do i run the php scripts with hhvm instead of zend.

I hope my question makes sense, and i would really appreciate any help.

Thanks, Maxx

Was it helpful?

Solution

Just run the following line first without forking a process:

hhvm RunRenderer.php

If you see console output, and that you can Ctrl+C to terminate the process, then you can demonize the process with an Upstart script. Create a file called /etc/init/renderer.conf:

start on startup
stop on shutdown
respawn

script
  hhvm RunRenderer.php
end script

Then you can manually start and stop the process by running:

start renderer

and

stop renderer

If you are running Ubuntu 12.04LTS and above, a log file will be created for you automatically under the name /var/log/upstart/renderer.log. You can fetch live output by tailing the file:

tail -f /var/log/upstart/renderer.log
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top