Changeset 17722


Ignore:
Timestamp:
04/29/14 11:37:14 (11 years ago)
Author:
tbretz
Message:
By never using more than one php array for a single pixel at a time instead of 1440 the memory consumption could be significantly decreased, however, I do not know how much memory the corresponding JS array uses, but I guess it is much less.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/www/viewer/index.php

    r17718 r17722  
    119119        return;
    120120
    121     $data = fread($handle, $size*$count);
    122     $data = unpack($format.$count, $data);
     121    $binary = fread($handle, $size*$count);
     122    $data   = unpack($format.$count, $binary);
    123123
    124124    return $count==1 ? $data[1] : $data;
    125125}
    126126
    127 // This is to allow for events of ROI=1024
    128 ini_set("memory_limit", "384M");
     127//ini_set("memory_limit", "64M");
    129128
    130129//define('E_FATAL',  E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
     
    162161    // Read the data and copy it from an associative array to an Array
    163162    // (this is just nicer and seems more logical)
     163    //$data   = array();
     164    $binary = array();
     165    for ($i=0; $i<$evt['numPix']; $i++)
     166        $binary[$i] = fread($file, 2*$evt['numRoi']);
     167    /*
    164168    $data = array();
    165169    for ($i=0; $i<$evt['numPix']; $i++)
    166170    {
    167         //$data[$i] = get($file, "s", $evt['numRoi']);
    168171        $var = get($file, "s", $evt['numRoi']);
    169 
    170172        $data[$i] = array();
    171173        for ($j=0; $j<$evt['numRoi']; $j++)
    172174            $data[$i][$j] = $var[$j+1]*0.48828125; // dac -> mV
    173     }
     175    }*/
    174176}
    175177
     
    229231
    230232    // This is much faster than the variables option in the constructor
    231     $v8->data  = $data;
    232     $v8->event = $evt;
    233     $v8->clone = function($data) { return $data; };
     233
     234    $roi = $evt['numRoi'];
     235
     236    //$v8->data   = $data;
     237    //$v8->test   = array();;
     238    //$v8->data   = array();
     239    $v8->event  = $evt;
     240    $v8->clone  = function($data) { return $data; };
     241    $v8->unpack = function($i)
     242    {
     243        global $binary, $roi;
     244        $u = unpack("s".$roi, $binary[$i]);
     245        $arr = array();
     246        for ($i=0; $i<$roi; $i++)
     247            $arr[$i] = $u[$i+1]*0.48828125;
     248        return $arr;
     249    };
     250
     251    //  10, 445, 91.75 MiB
     252    // 376, 720, 91.75 MiB
    234253
    235254    $rc['startJs'] = microtime(true);
     255    $rc['timeJS']  = array();
    236256
    237257    // Buffer output from javascript
     
    240260    try
    241261    {
     262
     263        // We unpack the data pixel by pixel and copy the array directly to the
     264        // Javasscript array. This significantly decreases memory usage because
     265        // we need only one of the super memory hungry php arrays of size ROI
     266        // instead of 1440.
     267        $JS = "$.data = new Array($.event.numPix); for (var i=0; i<$.event.numPix; i++) $.data[i] = $.unpack(i);";
     268        $v8->executeString($JS, 'internal');
     269
     270        $rc['timeJs'][0] = (microtime(true) - $rc['startJs']);
     271
    242272        $JS = "function proc(pixel){\n".$_POST['source1']."\n};proc(".$pixel.");";
    243273        $rc['waveform'] = $v8->executeString($JS, 'proc');
     274
     275        $rc['timeJs'][1] = (microtime(true) - $rc['startJs']);
    244276
    245277        if (isset($_POST['source2']))
     
    270302    $now = microtime(true);
    271303
    272     $rc['timeJs']  = ($now - $rc['startJs']);
     304    $rc['timeJs'][2]  = ($now - $rc['startJs']);
    273305}
    274306
    275307$rc['timePhp'] = ($now - $rc['startPhp']);
     308
     309$rc['memory'] = memory_get_peak_usage(true)/1024/1024;
    276310
    277311// Output result as JSON object
Note: See TracChangeset for help on using the changeset viewer.