Symfony Armenian Community

Full-Stack Web Application Framework

PHP Non-Blocking (Async) I/O Crash Testing / Converting Impossible to Possible

Ուրեմն, տեստ արեցի, PHP Non-Blocking I/O ստուգելիս, կասկած կար որ հիշողության խնդիր՝ Memory Leak կառաջանա։ Հարցում եմ ուղարկում, որ 200 MB ծավալով պատասխան է վերադարձնում, վարկյանում 4 հատ ու background֊ում, էս հրամանով (PHP 5.6)
while [ 1 ]; do for i in {1..4}; do wget -bqO- http://127.0.0.1:1337; done; sleep 1; done; sleep 1;
 Արդյունքում ստացվումա, որ էս ահավոր տրաֆիկին, PHP֊ն դիմանումա, բացի այդ հասցնումա մաքրել օպերատիվ հիշողությունը․․․ 

 Կոդը էսա

namespace Tigran;
require 'vendor/autoload.php';
use React\EventLoop\Factory;
use React\Socket\Server;
use React\Http\Server as Srv;
const RESPONSE_SIZE = 200;  // in megabytes
$app = function ($request, $response) {
    $data = str_repeat(chr(rand(32,126)),  RESPONSE_SIZE * 1024 * 1024);
    print sprintf("Allocated memory usage: %s, Memory Limit: %d, PID: %d\n",
        number_format(memory_get_usage()),
        ini_get("memory_limit"),
        getmypid()
    );
    $response->writeHead(200, array('Content-Type' => 'text/plain'));
    $response->end($data);
    unset($data);
};
// Make sure garbage collection is there, and enabled
if(!function_exists('gc_enable'))
    die("Please use PHP 5.3+ with Garbage Collection enabled");
gc_enable();
// Taken from React examples.
$loop = Factory::create();
$socket = new Server($loop);
$http = new Srv($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run();
Վերադարձրած  Output֊ը ստորև։

Allocated memory usage: 210,905,016, Memory Limit: -1, PID: 8026
Allocated memory usage: 409,277,216, Memory Limit: -1, PID: 8026
Allocated memory usage: 587,283,944, Memory Limit: -1, PID: 8026
Allocated memory usage: 733,484,928, Memory Limit: -1, PID: 8026
Allocated memory usage: 761,109,840, Memory Limit: -1, PID: 8026
Allocated memory usage: 851,827,080, Memory Limit: -1, PID: 8026
Allocated memory usage: 909,383,640, Memory Limit: -1, PID: 8026
Allocated memory usage: 986,876,008, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,038,735,776, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,077,930,600, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,108,450,136, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,104,320,936, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,120,782,800, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,119,442,416, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,115,642,888, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,096,466,328, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,085,263,200, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,066,208,872, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,064,876,408, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,100,391,616, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,121,264,288, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,140,386,056, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,144,219,944, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,150,649,344, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,161,555,544, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,140,867,776, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,124,025,048, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,118,609,984, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,116,259,216, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,106,180,808, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,079,136,928, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,075,683,544, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,077,859,840, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,081,539,576, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,077,496,424, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,074,708,664, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,055,941,512, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,061,989,328, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,055,050,792, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,056,740,112, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,042,191,680, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,059,443,424, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,054,609,904, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,063,432,616, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,081,787,672, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,046,901,712, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,020,023,656, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,055,728,440, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,066,273,928, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,056,941,400, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,096,972,576, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,143,592,560, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,130,418,424, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,140,821,184, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,114,823,176, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,113,131,944, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,127,112,456, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,096,405,152, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,033,510,744, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,019,995,952, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,024,742,488, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,034,127,440, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,097,184,736, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,168,896,904, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,215,109,816, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,203,090,944, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,179,895,632, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,153,629,936, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,083,008,648, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,035,549,120, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,036,731,432, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,009,682,672, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,028,472,432, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,034,608,200, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,036,348,776, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,006,480,256, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,017,531,536, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,029,109,024, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,037,743,480, Memory Limit: -1, PID: 8026
Allocated memory usage: 1,066,339,336, Memory Limit: -1, PID: 8026

Մեկնաբանություններ (0)

Առայժմ մեկնաբանություններ չկան

Մուտք

Login via Github

Symfony.AM (c) 2016

tigran[@]symfony.am