Browse Source

Merge pull request #589 from nareshv/hhvm

HHVM Support
Mike Smith 11 years ago
parent
commit
b51b7bc8e0
18 changed files with 433 additions and 0 deletions
  1. 53 0
      hhvm/README.md
  2. 10 0
      hhvm/URLs
  3. 0 0
      hhvm/__init__.py
  4. 29 0
      hhvm/benchmark_config
  5. 9 0
      hhvm/db.php
  6. 44 0
      hhvm/deploy/config-debug.hdf
  7. 44 0
      hhvm/deploy/config.hdf
  8. 9 0
      hhvm/fortunes.php
  9. 7 0
      hhvm/json.php
  10. 136 0
      hhvm/once.php.inc
  11. 6 0
      hhvm/plaintext.php
  12. 18 0
      hhvm/queries.php
  13. 3 0
      hhvm/run-debug.sh
  14. 3 0
      hhvm/run.sh
  15. 31 0
      hhvm/setup.py
  16. 10 0
      hhvm/setup.sh
  17. 3 0
      hhvm/test.sh
  18. 18 0
      hhvm/updates.php

+ 53 - 0
hhvm/README.md

@@ -0,0 +1,53 @@
+#HHVM Benchmarking Test
+
+This is the [HHVM](http://github.com/facebook/hhvm) portion of a [benchmarking test suite](../)
+
+Supports the Following Benmarking URLs
+
+* 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
+
+### 1. Plaintext Test
+
+* [Plaintext - source](plaintext.php)
+
+### 2. Single database query
+
+* [Single database query - source](db.php)
+
+### 3. Multiple database queries
+
+* [Multiple database queries - source](queries.php)
+
+### 4. Fortune test
+
+* [Fortunes - source](fortunes.php)
+
+### 5. Database updates test
+
+* [Database updates - source](updates.php)
+
+### 6. Plaintext test
+
+* [Plaintext - source](plaintext.php)
+
+## Infrastructure Software Versions
+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
+

+ 0 - 0
hhvm/__init__.py


+ 29 - 0
hhvm/benchmark_config

@@ -0,0 +1,29 @@
+{
+  "framework": "hhvm",
+  "tests":
+    [{
+        "raw": {
+              "setup_file"     : "setup",
+              "json_url"       : "/json",
+              "db_url"         : "/db",
+              "query_url"      : "/queries?queries=",
+              "fortune_url"    : "/fortunes",
+              "update_url"     : "/updates?queries=",
+              "plaintext_url"  : "/plaintext",
+              "port"           : 8080,
+              "approach"       : "Realistic",
+              "classification" : "Platform",
+              "database"       : "MySQL",
+              "framework"      : "hhvm",
+              "language"       : "PHP",
+              "orm"            : "Raw",
+              "platform"       : "hhvm",
+              "webserver"      : "HPHP",
+              "os"             : "Linux",
+              "database_os"    : "Linux",
+              "display_name"   : "hhvm",
+              "notes"          : "",
+              "versus"         : "php"
+        }
+    }]
+}

+ 9 - 0
hhvm/db.php

@@ -0,0 +1,9 @@
+<?php
+//
+// 2. Single database query
+//
+
+require_once dirname(__FILE__).'/once.php.inc';
+
+$b = new Benchmark();
+$b->bench_db();

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

@@ -0,0 +1,44 @@
+# Debugging configuration file
+
+# Application PID File
+PidFile = /tmp/FrameworkBenchmarks/hhvm/hhvm.pid
+
+# Server settings
+Server {
+  Port = 8080
+  SourceRoot = /tmp/FrameworkBenchmarks/hhvm
+  DefaultDocument = index.php
+}
+
+# Enable debug logging
+Log {
+  UseSyslog = false
+  Level = Verbose
+}
+
+# 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
+            }
+        }
+    }
+}

+ 44 - 0
hhvm/deploy/config.hdf

@@ -0,0 +1,44 @@
+# main 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 {
+  UseSyslog = false
+  Level = Error
+}
+
+# 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
+            }
+        }
+    }
+}

+ 9 - 0
hhvm/fortunes.php

@@ -0,0 +1,9 @@
+<?php
+//
+// 4. Fortunes
+//
+
+require_once dirname(__FILE__).'/once.php.inc';
+
+$b = new Benchmark();
+$b->bench_fortunes();

+ 7 - 0
hhvm/json.php

@@ -0,0 +1,7 @@
+<?php
+//
+// 1. JSON Test
+//
+$data = json_encode(array('message' => 'Hello, World!'));
+header('Content-Type: application/json');
+echo $data;

+ 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;
+    }
+}

+ 6 - 0
hhvm/plaintext.php

@@ -0,0 +1,6 @@
+<?php
+//
+// 6. Plaintext Test
+//
+header('Content-Type: text/plain; charset=utf-8');
+echo 'Hello, World!';

+ 18 - 0
hhvm/queries.php

@@ -0,0 +1,18 @@
+<?php
+//
+// 3. Multiple database queries
+//
+
+require_once dirname(__FILE__).'/once.php.inc';
+
+// Read number of queries to run from URL parameter
+$query_count = 1;
+if (!empty($_GET['queries'])) {
+  $query_count = intval($_GET['queries']);
+}
+
+// Fix the queries limits
+$query_count = $query_count < 1 ? 1 : ($query_count > 500 ? 500 : $query_count);
+
+$b = new Benchmark();
+$b->bench_queries($query_count);

+ 3 - 0
hhvm/run-debug.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+hhvm --config ./deploy/config-debug.hdf -m server

+ 3 - 0
hhvm/run.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+hhvm --config ./deploy/config.hdf -m server

+ 31 - 0
hhvm/setup.py

@@ -0,0 +1,31 @@
+
+import subprocess
+import setup_util
+import os
+from os.path import expanduser
+
+home = expanduser("~")
+
+def start(args, logfile, errfile):
+  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")
+
+  try:
+    if os.name == 'nt':
+      # Not supported !
+      return 0
+    subprocess.check_call("sudo hhvm --config " + home + "/FrameworkBenchmarks/hhvm/deploy/config.hdf -m daemon", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop(logfile, errfile):
+  try:
+    if os.name == 'nt':
+      # Not Supported !
+      return 0
+    subprocess.call("sudo kill -QUIT $( cat hhvm/hhvm.pid )", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 10 - 0
hhvm/setup.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# 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

+ 18 - 0
hhvm/updates.php

@@ -0,0 +1,18 @@
+<?php
+//
+// 5. Database updates
+//
+
+require_once dirname(__FILE__).'/once.php.inc';
+
+// Read number of queries to run from URL parameter
+$query_count = 1;
+if (!empty($_GET['queries'])) {
+  $query_count = intval($_GET['queries']);
+}
+
+// Fix the queries limits
+$query_count = $query_count < 1 ? 1 : ($query_count > 500 ? 500 : $query_count);
+
+$b = new Benchmark();
+$b->bench_updates($query_count);