g2 Tue Jun 16 22:43:30 2009 UTC
Added files:
/phpruntests/code-samples/taskScheduler/example4 taskFileWriter.php
main.php
Modified files:
/phpruntests/code-samples/taskScheduler/classes taskScheduler.php
/phpruntests/code-samples/taskScheduler run.php
Log:
phpruntests - update taskScheduler-prototype
http://cvs.php.net/viewvc.cgi/phpruntests/code-samples/taskScheduler/classes/taskScheduler.php?r1=1.1&r2=1.2&diff_format=u
Index: phpruntests/code-samples/taskScheduler/classes/taskScheduler.php
diff -u phpruntests/code-samples/taskScheduler/classes/taskScheduler.php:1.1
phpruntests/code-samples/taskScheduler/classes/taskScheduler.php:1.2
--- phpruntests/code-samples/taskScheduler/classes/taskScheduler.php:1.1
Sat Jun 13 03:13:30 2009
+++ phpruntests/code-samples/taskScheduler/classes/taskScheduler.php Tue Jun
16 22:43:30 2009
@@ -9,14 +9,15 @@
const MSG_QUEUE_SIZE = 1024; // max-size of a single message
const KILL_CHILD = 'killBill'; // kill-signal to terminate a child
- private $taskList = array();
- private $processCount = NULL;
- private $inputQueue = NULL;
- private $pidStore = array();
- private $time = 0;
- private $countPass = 0;
- private $countFail = 0;
- private $groupTasks = false;
+ private $taskList = array(); // the list of the tasks to be executed
+ private $processCount = NULL; // the number of processes
+ private $inputQueue = NULL; // the input-queue (only used
by the sender)
+ private $pidStore = array(); // stores the pids of all
child-processes
+ private $time = 0; // the needed time
+ private $countPass = 0; // counts the passed tasks
+ private $countFail = 0; // counts the failed tasks
+ private $groupTasks = false; // are the tasks stored in groups?
+ private $memStore = array(); // stores the mem-usage after an
incomming task
/**
@@ -252,6 +253,8 @@
}
for ($i=0; $i<$limit; $i++) {
+
+ $this->memStore[] = memory_get_usage(true);
if (msg_receive($resultQueue, 0, $type,
self::MSG_QUEUE_SIZE, $task, true, NULL, $error)) {
@@ -273,6 +276,8 @@
$this->taskList[$index] = $task;
logg("RECEIVER store task $index");
}
+
+
}
else logg("RECEIVER ERROR $error");
}
@@ -352,7 +357,7 @@
/**
* the child is listening to the input-queue and executes the incomming
* tasks. afterwards it setts the task-state and sends it back to the
- * receiver by the result-queue.
+ * receiver via the result-queue.
* after receiving the kill-signal from the receiver it terminates
itself.
*
* @param int $cid the child-id (default=NULL)
@@ -426,6 +431,7 @@
print "Tasks:\t\t".$count."\n";
} else {
+
$count = sizeof($this->taskList);
print "Tasks:\t\t".$count."\n";
}
@@ -437,8 +443,12 @@
if ($this->processCount > 0) {
print "AVG
sec/task:\t".round($this->time/$this->processCount,5)."\n";
+ print
"Memory-MAX:\t".number_format(max($this->memStore))."\n";
+ print
"Memory-MIN:\t".number_format(min($this->memStore))."\n";
+ $avg =
array_sum($this->memStore)/sizeof($this->memStore);
+ print "Memory-AVG:\t".number_format($avg)."\n";
}
-
+
print "----------------------------------------\n";
flush();
}
@@ -470,6 +480,30 @@
}
}
+
+
+ public function printMemStatistic($int=10)
+ {
+ print "MEMORY-USAGE";
+ print "\n----------------------------------------\n";
+
+ $int = ceil(sizeof($this->memStore)/$int);
+
+ $title = "TASK:\t";
+ $body = "kB:\t";
+
+ for ($i=0; $i<sizeof($this->memStore); $i+=$int) {
+
+ $title .= "$i\t";
+ $body .= round($this->memStore[$i]/1000)."\t";
+ }
+
+ print $title."\n".$body;
+
+ print "\n----------------------------------------\n";
+ flush();
+ }
+
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/code-samples/taskScheduler/run.php?r1=1.1&r2=1.2&diff_format=u
Index: phpruntests/code-samples/taskScheduler/run.php
diff -u phpruntests/code-samples/taskScheduler/run.php:1.1
phpruntests/code-samples/taskScheduler/run.php:1.2
--- phpruntests/code-samples/taskScheduler/run.php:1.1 Sat Jun 13 03:13:31 2009
+++ phpruntests/code-samples/taskScheduler/run.php Tue Jun 16 22:43:30 2009
@@ -25,10 +25,11 @@
$argc = sizeof($argv);
-if ($argc == 2 || $argc == 3) {
+if ($argc >= 2 || $argc <= 3) {
$src = $argv[1];
$count = isset($argv[2]) ? $argv[2] : NULL;
+
} else {
die("USAGE: php run.php example processCount\n");
@@ -46,7 +47,7 @@
include $src;
-$taskList = createTaskList();
+$taskList = createTaskList($count);
// init scheduler
@@ -61,6 +62,8 @@
$c->printFailedTasks();
+$c->printMemStatistic(10);
+
exit(0);
?>
http://cvs.php.net/viewvc.cgi/phpruntests/code-samples/taskScheduler/example4/taskFileWriter.php?view=markup&rev=1.1
Index: phpruntests/code-samples/taskScheduler/example4/taskFileWriter.php
+++ phpruntests/code-samples/taskScheduler/example4/taskFileWriter.php
<?php
class taskFileWriter extends task implements taskInterface
{
private $id = NULL;
private $durations = 1;
private $sleep = 0;
private $txt = "Lorem ipsum dolor sit amet, consectetur adipisici elit,
sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi
consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.";
public function __construct($id, $durations, $sleep)
{
$this->id = $id;
$this->durations = $durations;
$this->sleep = $sleep;
}
public function run()
{
$name = 'example4/files/tmp_'.$this->id.'.txt';
$size = 0;
for ($i=0; $i<=$this->durations; $i++) {
$size += file_put_contents($name, $this->txt,
FILE_APPEND | LOCK_EX);
}
file_get_contents($name);
$x = exp(asin(atan2($size, microtime(true))));
sleep($this->sleep);
$y = sqrt(acosh(atan2($x, microtime(true))));
if ($x == $y) {
$this->setMessage('impossible...');
return false;
}
unlink($name);
return true;
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/code-samples/taskScheduler/example4/main.php?view=markup&rev=1.1
Index: phpruntests/code-samples/taskScheduler/example4/main.php
+++ phpruntests/code-samples/taskScheduler/example4/main.php
<?php
include 'taskFileWriter.php';
function createTaskList($lim=NULL)
{
if (is_null($lim)) $lim = 5;
$list = array();
for ($j=0; $j<$lim; $j++) {
$list[$j] = array();
$subLim = $lim*($j+1);
for ($i=0; $i<$subLim; $i++) {
$d = (($i+$j)%($lim*2));
$s = 0;
if ($d == 0) {
$s = 1;
$d++;
}
$d *= $lim;
$list[$j][$i] = new taskFileWriter($j.$i, $d, $s);
}
}
return $list;
}
?>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php