-1

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

5
  • Does anyone have any idea on how to run the scripts using hhvm?
    – Maxx
    Jan 6, 2014 at 2:24
  • I'm not overly familiar with HHVM, and it's still got many bugs which makes it unstable for the moment. However, thousands instances of a forked process sounds.. surreal. I'd resort to threads rather than processes. The other thing I'd do is construct a worker farm made out of different machines. Forking thousands of processes to do almost the same computation isn't viable in any scenario. Distributing task(s) to different machines and/or using threads is much more sane.
    – N.B.
    Jan 16, 2014 at 16:04
  • Yes i have resorted to using the pthread extension of php. Well turns out that it perfectly suited my needs. The memory usage went down from more than 3gb to mere 120-200mb, the computations takes around 1/50th the time it took for multiple processes, and its more manageable in the sense that you only have one process to control, so in case of errors when you had to "kill -9 process" there is just one process to kill instead of thousand child processes.
    – Maxx
    Jan 17, 2014 at 11:59
  • And hhvm doesn't support threads, but even then running it on the native php interpreter feels blazingly fast. all thanks to threads. Anyways thanks for your response
    – Maxx
    Jan 17, 2014 at 12:00
  • It's good to hear someone used pthreads and prospered out of it :)
    – N.B.
    Jan 17, 2014 at 12:02

1 Answer 1

2

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
1
  • Perfect. I was looking for this exact thing for over a month now. Had to resort back to php interpreter. It works fine now, all thanks to you. I use Fedora and i think the log file is in the same location that you mentioned For Ubuntu. Anyways thanks a lot for a solution to this problem
    – Maxx
    Feb 11, 2014 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.