Project

General

Profile

Actions

Task #5267

open

IO Bench script

Added by Veyre Pierre about 11 years ago. Updated about 11 years ago.

Status:
Assigned
Priority:
Normal
Assigned To:
-
Start date:
10/07/2013
Due date:
% Done:

0%

Estimated time:

Description

Implement this script in Python and shell

<?php 

system(escapeshellcmd("dd if=/dev/zero of=data.bin bs=1024 count=0 seek=102400"));

echo "Launching ".$argv[1]. " read and write processes.";

$pids = array();

for($i = 1; $i <= $argv[1]; $i++) {

 $pids[$i] = pcntl_fork();

 if(!$pids[$i]) {
  writer($i);
  reader();
  exit();
 }
}

for($i = 1; $i <= $argv[1]; $i++) {
 pcntl_waitpid($pids[$i], $status, WUNTRACED);
}

function reader(){
    $filename = "data.bin";
    $handle = fopen($filename, "r");
    $timestart = microtime(true);
    $contents = fread($handle, $fs = filesize($filename));
    $timeend = microtime(true);
    $time = $timeend-$timestart;

    fclose($handle);

    $exec_time = number_format($time, 3);
    echo "\nHost has read ".$fs." on ".$filename." in ".$exec_time. " seconds\n";
}

function writer($number){
    $filename = "data.bin";
    $handle = fopen($filename, "r");
    $contents = fread($handle, $fs = filesize($filename));
    write($contents,$number);
}

function write($contents,$number){
    $filename = "data-".$number.".bin";
    $handle = fopen($filename,"xr");
    $timestart = microtime(true);
    $written = fwrite($handle,$contents);    
    $timeend = microtime(true);
    $time = $timeend-$timestart;

    fclose($handle);

    $exec_time = number_format($time, 3);
    echo "\nHost has written ".$written." on ".$filename." in ".$exec_time. " seconds\n";

}

?>
Actions

Also available in: Atom PDF