Commit e0887af5 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Die erste stabile Version

Die Anzahl der Fetcher reguliert sich nun von alleine. Fehlerfrei ist es aber noch nicht.
parent 86121d20
......@@ -33,7 +33,6 @@ class Searcher implements ShouldQueue
$this->name = $name;
$this->pid = getmypid();
// Submit this worker to the Redis System
Redis::set($this->name, "running");
Redis::expire($this->name, 5);
}
......@@ -51,6 +50,7 @@ class Searcher implements ShouldQueue
while(true){
// Update the expire
Redis::expire($this->name, 5);
Redis::expire($this->name . ".stats", 5);
// One Searcher can handle a ton of requests to the same server
// Each search to the server of this Searcher will be submitted to a queue
// stored in redis which has the same name as this searchengine appended by a ".queue"
......@@ -65,7 +65,6 @@ class Searcher implements ShouldQueue
$mission = $mission[1];
$this->counter++;#
$poptime = microtime(true) - $time;
$time = microtime(true);
}
// The mission is a String which can be divided to retrieve two informations:
......@@ -81,6 +80,16 @@ class Searcher implements ShouldQueue
$this->storeResult($result, $poptime, $hashValue);
if($this->counter === 3){
Redis::set($this->name, "running");
}
// Reset the time of the last Job so we can calculate
// the time we have spend waiting for a new job
// We submit that calculation to the Redis systemin the method
// storeResult()
$time = microtime(true);
// In sync mode every Searcher may only retrieve one result because it would block
// the execution of the remaining code otherwise:
if(getenv("QUEUE_DRIVER") === "sync" || $this->counter > $this->MAX_REQUESTS){
......
......@@ -156,10 +156,19 @@ abstract class Searchengine
// Now we have to check if the current count is enough to fetch all the
// searches or if it needs help.
// Let's hardcode a minimum of 100ms between every search job.
die(var_dump($searcherData));
// First calculate the median of all Times
$median = 0;
foreach($searcherData as $pid => $data){
$data = explode(";", $data);
$median += floatval($data[1]);
}
$median /= sizeof($searcherData);
if($median < 100){
$needSearcher = true;
}
}
if($needSearcher){
if($needSearcher && Redis::get($this->name) !== "locked"){
Redis::set($this->name, "locked");
$this->dispatch(new Searcher($this->name));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment