Commit 0f4738ca authored by Davide Aprea's avatar Davide Aprea
Browse files

add stress test

parent 45075765
......@@ -12,7 +12,104 @@ use View;
class Stresstest extends Controller
{
public function index(){
return ('placeholder');
public function index(Metager $metager){
$this->dummySearch($metager);
}
private function dummySearch(Metager $metager){
$timings = null;
$timings = ['starttime' => microtime(true)];
$time = microtime(true);
$spamEntries = [];
$spamEntry = null;
if (file_exists(config_path('spam.txt'))) {
$spamEntries = file(config_path('spam.txt'));
}
# If there is no query parameter we redirect to the startpage
$eingabe = "test";
# Mit gelieferte Formulardaten parsen und abspeichern:
$metager->insertDummyFormData();
if (!empty($timings)) {
$timings["insertDummyFormData"] = microtime(true) - $time;
}
# Suche für alle zu verwendenden Suchmaschinen als Job erstellen,
# auf Ergebnisse warten und die Ergebnisse laden
$metager->startSearch($timings);
$metager->waitForMainResults();
if (!empty($timings)) {
$timings["waitForMainResults"] = microtime(true) - $time;
}
$metager->retrieveResults();
if (!empty($timings)) {
$timings["retrieveResults"] = microtime(true) - $time;
}
# Alle Ergebnisse vor der Zusammenführung ranken:
$metager->rankAll();
if (!empty($timings)) {
$timings["rankAll"] = microtime(true) - $time;
}
# Ergebnisse der Suchmaschinen kombinieren:
$metager->prepareResults($timings);
$finished = true;
foreach ($metager->getEngines() as $engine) {
if ($engine->loaded) {
$engine->setNew(false);
$engine->markNew();
}
}
try {
Cache::put("loader_" . $metager->getSearchUid(), [
"metager" => [
"apiAuthorized" => $metager->isApiAuthorized(),
],
"adgoal" => [
"loaded" => $metager->isAdgoalLoaded(),
"adgoalHash" => $metager->getAdgoalHash(),
],
"engines" => $metager->getEngines(),
], 60 * 60);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
if (!empty($timings)) {
$timings["Filled resultloader Cache"] = microtime(true) - $time;
}
# Die Ausgabe erstellen:
//$resultpage = $metager->createView([]);
if (!empty($timings)) {
$timings["createView"] = microtime(true) - $time;
}
if ($timings) {
dd($timings);
}
$registry = \Prometheus\CollectorRegistry::getDefault();
$counter = $registry->getOrRegisterCounter('metager', 'result_counter', 'counts total number of returned results', []);
$counter->incBy(sizeof($metager->getResults()));
$counter = $registry->getOrRegisterCounter('metager', 'query_counter', 'counts total number of search queries', []);
$counter->inc();
// Splitting the response return into multiple parts.
// This might speed up page view time for users with slow network
$responseArray = str_split($resultpage->render(), 1024);
foreach ($responseArray as $responsePart) {
echo($responsePart);
flush();
}
$requestTime = microtime(true) - $time;
\App\PrometheusExporter::Duration($requestTime, "request_time");
}
}
\ No newline at end of file
......@@ -1023,6 +1023,69 @@ class MetaGer
* Ende Suchmaschinenerstellung und Ergebniserhalt
*/
public function insertDummyFormData(){
$this->headerPrinted = false;
$this->javascript = false;
$this->jskey = '';
$this->url = 'https://metager.de/meta/meta.ger3';
$this->fullUrl = 'https://metager.de/meta/meta.ger3?eingabe=test';
$this->fokus = 'web';
$this->sumaFile = config_path() . "/stress.json";
if (!file_exists($this->sumaFile)) {
die(trans('metaGer.formdata.cantLoad'));
} else {
$this->sumaFile = json_decode(file_get_contents($this->sumaFile));
}
$this->eingabe = 'test';
$this->q = $this->eingabe;
$this->framed = false;
$this->ip = '127.0.0.1';
$this->useragent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0';
if (isset($_SERVER['HTTP_LANGUAGE'])) {
$this->language = $_SERVER['HTTP_LANGUAGE'];
} else {
$this->language = "";
}
$this->page = 1;
$this->lang = "all";
$this->agent = new Agent();
$this->mobile = $this->agent->isMobile();
$this->sprueche = 'off';
$this->newtab = 'off';
$this->theme = 'default';
$this->resultCount = '20';
if ($this->resultCount <= 0 || $this->resultCount > 200) {
$this->resultCount = 1000;
}
$this->quicktips = false;
$this->queryFilter = [];
$this->verificationId = null;
$this->verificationCount = 0;
$this->apiKey = "";
$this->out = "html";
$this->canCache = false;
$this->shouldLog = false;
$this->fokus = 'web';
$sumaNames = $this->sumaFile->foki->{$this->fokus}->sumas;
$sumas = [];
foreach ($sumaNames as $sumaName) {
$sumas[$sumaName] = $this->sumaFile->sumas->{$sumaName};
}
$this->actuallyCreateSearchEngines($this->enabledSearchengines);
}
public function parseFormData(Request $request, $auth = true)
{
# Sichert, dass der request in UTF-8 formatiert ist
......
{
"sumas": {
"dummy": {
"host": "http://production-auto-deploy.dummy-engine-87.svc.cluster.local",
"path": "\/",
"port": 80,
"query-parameter": "q",
"input-encoding": "utf8",
"output-encoding": "utf8",
"parser-class": "Dummy",
"get-parameter": {},
"request-header": {},
"display-name": "dummy",
"engine-boost": 1,
"cache-duration": -1,
"disabled": false,
"filter-opt-in": false,
"homepage": "https:\/\/gitlab.metager.de\/open-source\/dummy-engine"
}
},
"foki": {
"web": {
"display-name": "index.foki.web",
"sumas": [
"dummy"
],
"main": [
"dummy"
]
}
},
"filter": {
"query-filter": {},
"parameter-filter": {
"count": {
"name": "metaGer.filter.count",
"desc": "",
"get-parameter": "count",
"values": {
"10": "10",
"20": "20",
"30": "30",
"40": "40",
"50": "50",
"100": "100"
},
"sumas": {
"dummy": {
"get-parameter": "count",
"values": {
"10": "10",
"20": "20",
"30": "30",
"40": "40",
"50": "50",
"100": "100"
}
}
}
},
"min": {
"name": "metaGer.filter.min",
"desc": "",
"get-parameter": "min",
"values": {
"nofilter" : "0",
"2": "2",
"4": "4",
"6": "6",
"8": "8",
"10": "10"
},
"sumas": {
"dummy": {
"get-parameter": "min",
"values": {
"nofilter" : "0",
"2": "2000",
"4": "4000",
"6": "6000",
"8": "8000",
"10": "10000"
}
}
}
},
"max": {
"name": "metaGer.filter.max",
"desc": "",
"get-parameter": "max",
"values": {
"nofilter" : "0",
"2": "2",
"4": "4",
"6": "6",
"8": "8",
"10": "10"
},
"sumas": {
"dummy": {
"get-parameter": "max",
"values": {
"nofilter" : "0",
"2": "2000",
"4": "4000",
"6": "6000",
"8": "8000",
"10": "10000"
}
}
}
}
}
}
}
\ No newline at end of file
Supports Markdown
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