Browse Source

micro optimizations/upgraded fat-free code, optimized nginx settings (#5589)

* micro optimizations to fat-free code, upgraded fat-free, and optimized nginx settings

* fat-free, fat-free-raw: reverted nginx, converted fortune to raw and orm
Austin 5 years ago
parent
commit
48f83e9399

+ 6 - 0
frameworks/PHP/fat-free/README.md

@@ -23,3 +23,9 @@ http://localhost/db/5
 
 ORM:
 http://localhost/db-orm/5
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Fat-Free Version 3.7.1](https://github.com/bcosca/fatfree)
+* [PHP Version 7.4](http://www.php.net/) with FPM

+ 3 - 2
frameworks/PHP/fat-free/benchmark_config.json

@@ -4,7 +4,8 @@
     "default": {
       "json_url": "/json",
       "plaintext_url": "/plaintext",
-      "db_url": "/db-orm",
+	  "db_url": "/db-orm",
+	  "fortune_url": "/fortune-orm",
       "query_url": "/db-orm-multiple/",
       "update_url": "/update-orm/",
       "port": 8080,
@@ -26,7 +27,7 @@
     "raw": {
       "db_url": "/db",
       "query_url": "/db-multiple/",
-      "fortune_url": "/fortune",
+      "fortune_url": "/fortune-raw",
       "update_url": "/update-raw/",
       "port": 8080,
       "approach": "Realistic",

+ 1 - 1
frameworks/PHP/fat-free/deploy/nginx.conf

@@ -63,4 +63,4 @@ http {
             include        /etc/nginx/fastcgi_params;
         }
     }
-}
+}

+ 1 - 1
frameworks/PHP/fat-free/fat-free-raw.dockerfile

@@ -14,7 +14,7 @@ WORKDIR /fat-free
 
 ENV F3DIR="/fat-free/src"
 
-RUN git clone -b 3.6.5 --single-branch --depth 1 "https://github.com/bcosca/fatfree-core.git" src
+RUN git clone -b 3.7.1 --single-branch --depth 1 "https://github.com/bcosca/fatfree-core.git" src
 
 RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.4/fpm/php-fpm.conf ; fi;
 

+ 1 - 1
frameworks/PHP/fat-free/fat-free.dockerfile

@@ -14,7 +14,7 @@ WORKDIR /fat-free
 
 ENV F3DIR="/fat-free/src"
 
-RUN git clone -b 3.6.5 --single-branch --depth 1 "https://github.com/bcosca/fatfree-core.git" src
+RUN git clone -b 3.7.1 --single-branch --depth 1 "https://github.com/bcosca/fatfree-core.git" src
 
 RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.4/fpm/php-fpm.conf ; fi;
 

+ 46 - 29
frameworks/PHP/fat-free/index.php

@@ -1,16 +1,16 @@
 <?php
 // drop startup errors
-if (function_exists('error_clear_last'))
-    error_clear_last();
+// if (function_exists('error_clear_last'))
+//     error_clear_last();
    
-error_reporting(0);
+// error_reporting(0);
 
 /** @var Base $f3 */
 $f3=require('src/base.php');
 
 error_reporting(-1);
 
-$f3->set('DEBUG',2);
+$f3->set('DEBUG',0);
 $f3->set('HIGHLIGHT',false);
 $f3->set('CACHE','folder=tmp/cache/');
 $f3->set('UI','ui/');
@@ -18,29 +18,29 @@ $f3->set('ONERROR',function($f3){
     echo $f3->get('ERROR.code').': '.$f3->get('ERROR.text')."\n".$f3->get('ERROR.trace');
 });
 
-$f3->set('DBS',array('mysql:host=tfb-database;port=3306;dbname=hello_world','benchmarkdbuser','benchmarkdbpass',[PDO::ATTR_PERSISTENT => true]));
+$f3->set('DBS',array('mysql:host=tfb-database;port=3306;dbname=hello_world','benchmarkdbuser','benchmarkdbpass',[ \PDO::ATTR_PERSISTENT => TRUE ]));
 // http: //www.techempower.com/benchmarks/#section=code
 
 // JSON test
 $f3->route('GET /json',function($f3) {
     /** @var Base $f3 */
-    header("Content-type: application/json");
+    header('Content-type: application/json');
     echo json_encode(array('message' => 'Hello, World!'));
 });
 
 
 // DB RAW test database-single-query
-$f3->route('GET /db', function ($f3,$params) {
+$f3->route('GET /db', function ($f3) {
         /** @var Base $f3 */
         $dbc = $f3->get('DBS');
-        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
         $id = mt_rand(1, 10000);
         $res = $db->exec('SELECT id, randomNumber FROM World WHERE id = ?',$id,0,false);
         $result = array(
             'id' => (int) $res[0]['id'],
             'randomNumber' => (int) $res[0]['randomNumber'],
         );
-        header("Content-type: application/json");
+        header('Content-type: application/json');
         echo json_encode($result);
     }
 );
@@ -58,9 +58,9 @@ $f3->route(array(
             $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
         }
         $dbc = $f3->get('DBS');
-        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
         $result = array();
-        for ($i = 0; $i < $queries; $i++) {
+        for ($i = 0; $i < $queries; ++$i) {
             $id = mt_rand(1, 10000);
             $res = $db->exec('SELECT id, randomNumber FROM World WHERE id = ?',$id,0,false);
             $result[] = array(
@@ -68,20 +68,20 @@ $f3->route(array(
                 'randomNumber' => (int) $res[0]['randomNumber'],
             );
         }
-        header("Content-type: application/json");
+        header('Content-type: application/json');
         echo json_encode($result);
     }
 );
 
 // DB ORM test database-single-query
-$f3->route('GET /db-orm', function ($f3, $params) {
+$f3->route('GET /db-orm', function ($f3) {
         /** @var Base $f3 */
         $dbc = $f3->get('DBS');
-        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
         $mapper = new \DB\SQL\Mapper($db,'World');
         $id = mt_rand(1, 10000);
         $mapper->load(array('id = ?',$id));
-        header("Content-type: application/json");
+        header('Content-type: application/json');
         echo json_encode($mapper->cast());
     }
 );
@@ -100,30 +100,47 @@ $f3->route(
             $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
         }
         $dbc = $f3->get('DBS');
-        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+        $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
         $mapper = new \DB\SQL\Mapper($db,'World');
         $result = array();
-        for ($i = 0; $i < $queries; $i++) {
+        for ($i = 0; $i < $queries; ++$i) {
             $id = mt_rand(1, 10000);
             $mapper->load(array('id = ?',$id));
             $result[] = $mapper->cast();
         }
-        header("Content-type: application/json");
+        header('Content-type: application/json');
         echo json_encode($result);
     }
 );
 
 
-$f3->route('GET /plaintext', function ($f3) {
-    header("Content-type: text/plain");
-    echo "Hello, World!";
+$f3->route('GET /plaintext', function () {
+    header('Content-type: text/plain');
+    echo 'Hello, World!';
 });
 
 
-$f3->route('GET /fortune', function ($f3) {
+$f3->route('GET /fortune-orm', function ($f3) {
+    /** @var Base $f3 */
+	$dbc = $f3->get('DBS');
+	$db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
+	$mapper = new \DB\SQL\Mapper($db,'Fortune');
+    $result = $mapper->find();
+    //$result = $db->exec('SELECT id, message FROM Fortune');
+    $result[] = [
+        'id' => 0,
+        'message' => 'Additional fortune added at request time.'
+	];
+    $mtx = \Matrix::instance();
+    $mtx->sort($result,'message');
+    $f3->set('result',$result);
+    echo \Template::instance()->render('fortune.html');
+});
+
+$f3->route('GET /fortune-raw', function ($f3) {
     /** @var Base $f3 */
     $dbc = $f3->get('DBS');
-    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
     $result = $db->exec('SELECT id, message FROM Fortune');
     $result[] = array(
         'id'=>0,
@@ -147,10 +164,10 @@ $f3->route(array(
         $queries = ( $queries < 1 ) ? 1 : ( ( $queries > 500 ) ? 500 : $queries );
     }
     $dbc = $f3->get('DBS');
-    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
 
     $result = array();
-    for ($i = 0; $i < $queries; $i++) {
+    for ($i = 0; $i < $queries; ++$i) {
         $id = mt_rand(1, 10000);
         $row = array(
             'id'=>$id,
@@ -161,7 +178,7 @@ $f3->route(array(
         $db->exec('UPDATE World SET randomNumber = :ranNum WHERE id = :id', array(':ranNum'=>$rnu,':id'=>$id),0,false);
         $result[] = $row;
     }
-    header("Content-type: application/json");
+    header('Content-type: application/json');
     echo json_encode($result);
 });
 
@@ -177,18 +194,18 @@ $f3->route(array(
         $queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
     }
     $dbc = $f3->get('DBS');
-    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
+    $db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],$dbc[3]);
     $world = new \DB\SQL\Mapper($db,'World');
 
     $result = array();
-    for ($i = 0; $i < $queries; $i++) {
+    for ($i = 0; $i < $queries; ++$i) {
         $id = mt_rand(1, 10000);
         $world->load(array('id = ?', $id));
         $world->randomNumber = mt_rand(1, 10000);
         $world->save();
         $result[] = $world->cast();
     }
-    header("Content-type: application/json");
+    header('Content-type: application/json');
     echo json_encode($result);
 });