Project

General

Profile

Actions

Task #5267

open

IO Bench script

Added by Veyre Pierre over 10 years ago. Updated over 10 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 #1

Updated by Veyre Pierre over 10 years ago

  • Tracker changed from Bug to Task
Actions

Also available in: Atom PDF