Browse Source

Separate single and multiple queries in php raw (#4596)

* Separate single and multiple queries
And small changes

* Change comparison in updateraw

* Dbqueries with pgsql
Joan Miquel 6 years ago
parent
commit
379a4a37ce

+ 7 - 7
frameworks/PHP/php/benchmark_config.json

@@ -5,7 +5,7 @@
       "json_url": "/json.php",
       "json_url": "/json.php",
       "plaintext_url": "/plaintext.php",
       "plaintext_url": "/plaintext.php",
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -45,7 +45,7 @@
     },
     },
     "raw7": {
     "raw7": {
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -66,7 +66,7 @@
     },
     },
     "raw7-tcp": {
     "raw7-tcp": {
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -87,7 +87,7 @@
     },
     },
     "pgsql-raw": {
     "pgsql-raw": {
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -110,7 +110,7 @@
       "json_url": "/json.php",
       "json_url": "/json.php",
       "plaintext_url": "/plaintext.php",
       "plaintext_url": "/plaintext.php",
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -175,7 +175,7 @@
     },
     },
     "php5-raw": {
     "php5-raw": {
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,
@@ -198,7 +198,7 @@
       "json_url": "/json.php",
       "json_url": "/json.php",
       "plaintext_url": "/plaintext.php",
       "plaintext_url": "/plaintext.php",
       "db_url": "/dbraw.php",
       "db_url": "/dbraw.php",
-      "query_url": "/dbraw.php?queries=",
+      "query_url": "/dbquery.php?queries=",
       "fortune_url": "/fortune.php",
       "fortune_url": "/fortune.php",
       "update_url": "/updateraw.php?queries=",
       "update_url": "/updateraw.php?queries=",
       "port": 8080,
       "port": 8080,

+ 32 - 0
frameworks/PHP/php/dbquery.php

@@ -0,0 +1,32 @@
+<?php
+header('Content-type: application/json');
+
+// Database connection
+// http://www.php.net/manual/en/ref.pdo-mysql.php
+$pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
+    PDO::ATTR_PERSISTENT => true
+));
+
+// Read number of queries to run from URL parameter
+$query_count = 1;
+if ( isset($_GET['queries']) && $_GET['queries'] > 1) {
+  $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
+}
+
+// Create an array with the response string.
+$arr = array();
+
+// Define query
+$statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
+
+// For each query, store the result set values in the response array
+while (0 < $query_count--) {
+  $statement->execute(array( mt_rand(1, 10000)) );
+  
+  // Store result in array.
+  $arr[] = $statement->fetch(PDO::FETCH_ASSOC);
+}
+
+// Use the PHP standard JSON encoder.
+// http://www.php.net/manual/en/function.json-encode.php
+echo json_encode($arr);

+ 2 - 26
frameworks/PHP/php/dbraw.php

@@ -7,33 +7,9 @@ $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser',
     PDO::ATTR_PERSISTENT => true
     PDO::ATTR_PERSISTENT => true
 ));
 ));
 
 
-// Read number of queries to run from URL parameter
-$query_count = 1;
-$query_param = isset($_GET['queries']);
-if ($query_param && $_GET['queries'] > 0) {
-  $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
-}
-
-// Create an array with the response string.
-$arr = array();
-
 // Define query
 // Define query
-$statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = ?');
-
-// For each query, store the result set values in the response array
-$query_counter = $query_count;
-while (0 < $query_counter--) {
-  $id = mt_rand(1, 10000);
-  $statement->execute(array($id));
-  
-  // Store result in array.
-  $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
-}
+$statement = $pdo->query( 'SELECT id,randomNumber FROM World WHERE id = '. mt_rand(1, 10000) );
 
 
 // Use the PHP standard JSON encoder.
 // Use the PHP standard JSON encoder.
 // http://www.php.net/manual/en/function.json-encode.php
 // http://www.php.net/manual/en/function.json-encode.php
-if ($query_count === 1 && !$query_param) {
-      $arr = $arr[0];
-}
-
-echo json_encode($arr);
+echo json_encode($statement->fetch(PDO::FETCH_ASSOC));

+ 1 - 0
frameworks/PHP/php/php-pgsql-raw.dockerfile

@@ -13,6 +13,7 @@ ADD ./ /php
 WORKDIR /php
 WORKDIR /php
 
 
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" dbraw.php
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" dbraw.php
+RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" dbquery.php
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" fortune.php
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" fortune.php
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" updateraw.php
 RUN sed -i "s|PDO('mysql:|PDO('pgsql:|g" updateraw.php
 
 

+ 1 - 1
frameworks/PHP/php/updateraw.php

@@ -9,7 +9,7 @@ $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser',
 
 
 // Read number of queries to run from URL parameter
 // Read number of queries to run from URL parameter
 $query_count = 1;
 $query_count = 1;
-if (isset($_GET['queries']) && $_GET['queries'] > 0) {
+if (isset($_GET['queries']) && $_GET['queries'] > 1) {
   $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
   $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
 }
 }