Browse Source

Code re-organized and fixed the setup.py script to take proper hostname

nareshv 11 years ago
parent
commit
eb6ca1826b
12 changed files with 224 additions and 124 deletions
  1. 9 0
      hhvm/README.md
  2. 10 0
      hhvm/URLs
  3. 3 21
      hhvm/db.php
  4. 45 0
      hhvm/deploy/config-debug.hdf
  5. 2 0
      hhvm/deploy/config.hdf
  6. 3 37
      hhvm/fortunes.php
  7. 136 0
      hhvm/once.php.inc
  8. 3 24
      hhvm/queries.php
  9. 1 8
      hhvm/setup.py
  10. 6 0
      hhvm/setup.sh
  11. 3 0
      hhvm/test.sh
  12. 3 34
      hhvm/updates.php

+ 9 - 0
hhvm/README.md

@@ -42,3 +42,12 @@ Supports the Following Benmarking URLs
 The tests were run with:
 
 * [HHVM v2.2.0](http://github.com/facebook/hhvm)
+
+## Setting up a test environment
+
+1. Invoke the ./setup.sh script
+
+2. Invoke the ./run.sh script in another terminal
+
+3. Invoke the ./tests.sh script and see that you get a sample output from all
+    the urls mentions in the ./URLs file

+ 10 - 0
hhvm/URLs

@@ -0,0 +1,10 @@
+http://localhost:8080/json
+http://localhost:8080/db
+http://localhost:8080/db?queries=10
+http://localhost:8080/queries
+http://localhost:8080/queries?queries=10
+http://localhost:8080/fortunes
+http://localhost:8080/updates
+http://localhost:8080/updates?queries=10
+http://localhost:8080/plaintext
+

+ 3 - 21
hhvm/db.php

@@ -3,25 +3,7 @@
 // 2. Single database query
 //
 
-// Database connection
-$pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
-    PDO::ATTR_PERSISTENT => true
-));
-
-// Create an array with the response string.
-$arr = array();
-$id = mt_rand(1, 10000);
-
-// Define query
-$statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
-$statement->bindParam(':id', $id, PDO::PARAM_INT);
-$statement->execute();
-
-// Store result in array.
-$arr = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
-$id = mt_rand(1, 10000);
-
-// Send the required parameters
-header('Content-Type: application/json');
-echo json_encode($arr);
+require_once dirname(__FILE__).'/once.php.inc';
 
+$b = new Benchmark();
+$b->bench_db();

+ 45 - 0
hhvm/deploy/config-debug.hdf

@@ -0,0 +1,45 @@
+# Debugging configuration file
+
+# Application PID File
+PidFile = /tmp/FrameworkBenchmarks/hhvm/hhvm.pid
+
+# Server settings
+Server {
+  Port = 8080
+  SourceRoot = /tmp/FrameworkBenchmarks/hhvm
+  DefaultDocument = index.php
+}
+
+# Disable logging completely
+Log {
+  Level = Verbose
+  UseLogFile = false
+  UseSyslog = false
+}
+
+# Enable jit for production mode
+Eval {
+    Jit = true
+    CheckSymLink = false
+}
+
+# Repo file
+Repo {
+  Central {
+    Path = /tmp/FrameworkBenchmarks/hhvm/.hhvm.hhbc
+  }
+}
+
+# Setup basic rewrite
+VirtualHost {
+    * {
+        Pattern = .*
+        RewriteRules {
+            * {
+                pattern = ^(.*)$
+                to = $1.php
+                qsa = true
+            }
+        }
+    }
+}

+ 2 - 0
hhvm/deploy/config.hdf

@@ -1,3 +1,5 @@
+# main configuration file
+
 # Application PID File
 PidFile = /tmp/FrameworkBenchmarks/hhvm/hhvm.pid
 

+ 3 - 37
hhvm/fortunes.php

@@ -3,41 +3,7 @@
 // 4. Fortunes
 //
 
-// Database connection
-$pdo = new PDO('mysql:host=localhost;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass', array(
-    PDO::ATTR_PERSISTENT => true,
-    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
-));
+require_once dirname(__FILE__).'/once.php.inc';
 
-// Define query
-$statement = $pdo->query( 'SELECT id, message FROM Fortune' );
-
-// Store result in array.
-$arr = $statement->fetchAll(PDO::FETCH_KEY_PAIR);
-$arr[0] = 'Additional fortune added at request time.';
-
-asort($arr);
-header("Content-Type: text/html; charset=utf-8");
-?>
-<!DOCTYPE html>
-<html>
-<head>
-<title>Fortunes</title>
-</head>
-<body>
-<table>
-<tr>
-<th>id</th>
-<th>message</th>
-</tr>
-<?php
-foreach ( $arr as $id => &$fortune ) {
-?>
-<tr>
-<td><?php echo htmlspecialchars($id, ENT_QUOTES, 'utf-8'); ?></td>
-<td><?php echo htmlspecialchars($fortune, ENT_QUOTES, 'utf-8'); ?></td>
-</tr>
-<?php } ?>
-</table>
-</body>
-</html>
+$b = new Benchmark();
+$b->bench_fortunes();

+ 136 - 0
hhvm/once.php.inc

@@ -0,0 +1,136 @@
+<?php
+
+class Benchmark {
+    var $pdo;
+
+    public function setup_db()
+    {
+        $this->pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
+            PDO::ATTR_PERSISTENT => true,
+            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
+        ));
+    }
+
+    public function bench_db()
+    {
+        $this->setup_db();
+
+        // Create an array with the response string.
+        $arr = array();
+        $id = mt_rand(1, 10000);
+
+        // Define query
+        $statement = $this->pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
+        $statement->bindParam(':id', $id, PDO::PARAM_INT);
+        $statement->execute();
+
+        // Store result in array.
+        $arr = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
+        $id = mt_rand(1, 10000);
+
+        // Send the required parameters
+        header('Content-Type: application/json');
+        echo json_encode($arr);
+    }
+
+    public function bench_queries($query_count=1)
+    {
+        $this->setup_db();
+
+        // Create an array with the response string.
+        $arr = array();
+        $id = mt_rand(1, 10000);
+
+        // Define query
+        $statement = $this->pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
+        $statement->bindParam(':id', $id, PDO::PARAM_INT);
+
+        // For each query, store the result set values in the response array
+        while (0 < $query_count--) {
+          $statement->execute();
+
+          // Store result in array.
+          $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
+          $id = mt_rand(1, 10000);
+        }
+
+        // Send the required parameters
+        header('Content-Type: application/json');
+        echo json_encode($arr);
+    }
+
+    public function bench_updates($query_count)
+    {
+        $this->setup_db();
+
+        // Create an array with the response string.
+        $arr = array();
+        $id = mt_rand(1, 10000);
+        $randomNumber = mt_rand(1, 1000);
+
+        // Define query
+        $statement = $this->pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
+        $statement->bindParam(':id', $id, PDO::PARAM_INT);
+
+        $updateStatement = $this->pdo->prepare('UPDATE World SET randomNumber = :randomNumber WHERE id = :id');
+        $updateStatement->bindParam(':id', $id, PDO::PARAM_INT);
+        $updateStatement->bindParam(':randomNumber', $randomNumber, PDO::PARAM_INT);
+
+        // For each query, store the result set values in the response array
+        while (0 < $query_count--) {
+          $statement->execute();
+
+          // Store result in array.
+          $world = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
+          $world['randomNumber'] = $randomNumber;
+          $updateStatement->execute();
+
+          $arr[] = $world;
+          $id = mt_rand(1, 10000);
+          $randomNumber = mt_rand(1, 10000);
+        }
+
+        // Send the required parameters
+        header('Content-Type: application/json');
+        echo json_encode($arr);
+    }
+
+    public function bench_fortunes()
+    {
+        $this->setup_db();
+
+        // Define query
+        $statement = $this->pdo->query( 'SELECT id, message FROM Fortune' );
+
+        // Store result in array.
+        $arr = $statement->fetchAll(PDO::FETCH_KEY_PAIR);
+        $arr[0] = 'Additional fortune added at request time.';
+
+        asort($arr);
+        header("Content-Type: text/html; charset=utf-8");
+        echo <<<EOM
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+EOM;
+        foreach ( $arr as $id => &$fortune ) {
+            echo '<tr>';
+            echo '<td>'.htmlspecialchars($id, ENT_QUOTES, 'utf-8').'</td>';
+            echo '<td>'.htmlspecialchars($fortune, ENT_QUOTES, 'utf-8').'</td>';
+            echo '</tr>';
+        }
+echo <<<EOM
+</table>
+</body>
+</html>
+EOM;
+    }
+}

+ 3 - 24
hhvm/queries.php

@@ -3,10 +3,7 @@
 // 3. Multiple database queries
 //
 
-// Database connection
-$pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
-    PDO::ATTR_PERSISTENT => true
-));
+require_once dirname(__FILE__).'/once.php.inc';
 
 // Read number of queries to run from URL parameter
 $query_count = 1;
@@ -17,23 +14,5 @@ if (!empty($_GET['queries'])) {
 // Fix the queries limits
 $query_count = $query_count < 1 ? 1 : ($query_count > 500 ? 500 : $query_count);
 
-// Create an array with the response string.
-$arr = array();
-$id = mt_rand(1, 10000);
-
-// Define query
-$statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
-$statement->bindParam(':id', $id, PDO::PARAM_INT);
-
-// For each query, store the result set values in the response array
-while (0 < $query_count--) {
-  $statement->execute();
-
-  // Store result in array.
-  $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
-  $id = mt_rand(1, 10000);
-}
-
-// Send the required parameters
-header('Content-Type: application/json');
-echo json_encode($arr);
+$b = new Benchmark();
+$b->bench_queries($query_count);

+ 1 - 8
hhvm/setup.py

@@ -7,14 +7,7 @@ from os.path import expanduser
 home = expanduser("~")
 
 def start(args):
-  if not args.database_host:
-    args.database_host = "localhost"
-
-  setup_util.replace_text("hhvm/db.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
-  setup_util.replace_text("hhvm/queries.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
-  setup_util.replace_text("hhvm/fortunes.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
-  setup_util.replace_text("hhvm/updates.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
-
+  setup_util.replace_text("hhvm/once.php.inc", "host=.*;", "host=" + args.database_host + ";")
   setup_util.replace_text("hhvm/deploy/config.hdf", "SourceRoot = .*\/FrameworkBenchmarks", "SourceRoot = " + home + "/FrameworkBenchmarks")
   setup_util.replace_text("hhvm/deploy/config.hdf", "Path = .*\/.hhvm.hhbc", "Path = " + home + "/FrameworkBenchmarks/hhvm/.hhvm.bbhc")
   setup_util.replace_text("hhvm/deploy/config.hdf", "PidFile = .*\/hhvm.pid", "Path = " + home + "/FrameworkBenchmarks/hhvm/hhvm.pid")

+ 6 - 0
hhvm/setup.sh

@@ -2,3 +2,9 @@
 
 # Setup script
 cat ../config/create.sql | mysql -u root
+
+# for testing create a symlink
+WDIR=$(cd .. && pwd)
+cd /tmp/ && ln -s $WDIR FrameworkBenchmarks && cd -
+
+# next invoke ./run.sh

+ 3 - 0
hhvm/test.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+for u in `cat URLs`; do echo "working on : $u"; perl -le print = x 50; echo; curl $u; echo; echo; done

+ 3 - 34
hhvm/updates.php

@@ -3,10 +3,7 @@
 // 5. Database updates
 //
 
-// Database connection
-$pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
-    PDO::ATTR_PERSISTENT => true
-));
+require_once dirname(__FILE__).'/once.php.inc';
 
 // Read number of queries to run from URL parameter
 $query_count = 1;
@@ -17,33 +14,5 @@ if (!empty($_GET['queries'])) {
 // Fix the queries limits
 $query_count = $query_count < 1 ? 1 : ($query_count > 500 ? 500 : $query_count);
 
-// Create an array with the response string.
-$arr = array();
-$id = mt_rand(1, 10000);
-$randomNumber = mt_rand(1, 1000);
-
-// Define query
-$statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
-$statement->bindParam(':id', $id, PDO::PARAM_INT);
-
-$updateStatement = $pdo->prepare('UPDATE World SET randomNumber = :randomNumber WHERE id = :id');
-$updateStatement->bindParam(':id', $id, PDO::PARAM_INT);
-$updateStatement->bindParam(':randomNumber', $randomNumber, PDO::PARAM_INT);
-
-// For each query, store the result set values in the response array
-while (0 < $query_count--) {
-  $statement->execute();
-
-  // Store result in array.
-  $world = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
-  $world['randomNumber'] = $randomNumber;
-  $updateStatement->execute();
-
-  $arr[] = $world;
-  $id = mt_rand(1, 10000);
-  $randomNumber = mt_rand(1, 10000);
-}
-
-// Send the required parameters
-header('Content-Type: application/json');
-echo json_encode($arr);
+$b = new Benchmark();
+$b->bench_updates($query_count);