Browse Source

add octopus lua benchmark (#2328)

cyberz-eu 8 years ago
parent
commit
9d2dfe5413

+ 1 - 0
.travis.yml

@@ -118,6 +118,7 @@ env:
     - "TESTDIR=JavaScript/sailsjs"
     - "TESTDIR=Kotlin/hexagon"
     - "TESTDIR=Lua/lapis"
+    - "TESTDIR=Lua/octopus"
     - "TESTDIR=Lua/openresty"
     - "TESTDIR=Nim/jester"
     - "TESTDIR=Nim/nawak"

+ 1 - 0
frameworks/Lua/octopus/.gitignore

@@ -0,0 +1 @@
+octopus

+ 35 - 0
frameworks/Lua/octopus/README.md

@@ -0,0 +1,35 @@
+# Octopus (Nginx + LuaJIT)  Benchmark Test
+
+The test lua app is inside [app](app) directory.
+The configuration is in [config.lua](config.lua).
+Clones, compiles and runs nginx with ngx_lua module, see [openresty.org](http://openresty.org).
+Prerequisites: ```libssl-dev gcc g++ build-essential```.
+Requires [git](https://git-scm.com).
+Requires postgresql hostname specified as IP address, if not possible then add resolver conf to [config.lua](config.lua).
+The Octopus benchmark is using its ORM, and no raw queries.
+
+
+## Test URLs
+### Plaintext URL
+
+http://localhost:8080/plaintext
+
+### JSON Encoding 
+
+http://localhost:8080/json
+
+### Single Row Random Query
+
+http://localhost:8080/db
+
+### Multiple Row Query Test
+
+http://localhost:8080/queries?queries=2
+
+### Fortune URL
+
+http://localhost:8080/fortunes
+
+### DB Updates URL
+
+http://localhost:8080/update?queries=2

+ 16 - 0
frameworks/Lua/octopus/app/config.lua

@@ -0,0 +1,16 @@
+local config = {} -- extension configuration
+
+config.locations = {
+	{name = "/plaintext", script = "PlaintextController.lua"},
+	{name = "/json", script = "JsonSerializationController.lua"},
+	{name = "/db", script = "SingleQueryController.lua"},
+	{name = "/queries", script = "MultipleQueriesController.lua"},
+	{name = "/fortunes", script = "FortunesController.lua"},
+	{name = "/update", script = "UpdateController.lua"},
+}
+
+config.types = {
+	"types.lua"
+}
+
+return config -- return extension configuration

+ 34 - 0
frameworks/Lua/octopus/app/src/FortunesController.lua

@@ -0,0 +1,34 @@
+local json = require "json"
+local database = require "database"
+local exit = require "exit"
+
+local template = require'template'
+template.caching(false)
+-- Compile template, disable cache, enable plain text view to skip filesystem loading
+local view = template.compile([[<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{% for _,f in ipairs(fortunes) do %}<tr><td>{{ f.id }}</td><td>{{ f.message }}</td></tr>{% end %}</table></body></html>]], nil, true)
+
+
+local function process (db)
+	local fortunes = db:find({Fortune = {}})
+	table.insert(fortunes, {id = 0, message = "Additional fortune added at request time."})
+	table.sort(fortunes, function(a, b)
+		return a.message < b.message
+	end)
+    return fortunes
+end
+
+
+local status, db = pcall(database.connect)
+if not status then exit(db) end
+
+local status, res = pcall(process, db)
+db:close()
+
+if status then
+	local html = view({fortunes = res})
+	ngx.header.content_type = 'text/html; charset=utf-8'
+	ngx.header.content_length = #html
+	ngx.print(html)
+else
+	exit(res)
+end

+ 4 - 0
frameworks/Lua/octopus/app/src/JsonSerializationController.lua

@@ -0,0 +1,4 @@
+local json = require "json"
+
+ngx.header.content_type = 'application/json'
+ngx.print(json.encode({message = "Hello, World!"}))

+ 36 - 0
frameworks/Lua/octopus/app/src/MultipleQueriesController.lua

@@ -0,0 +1,36 @@
+local json = require "json"
+local database = require "database"
+local param = require "param"
+local exit = require "exit"
+
+
+local function process (db)
+	local op = db:operators()
+	
+	local num_queries = tonumber(param.queries) or 1
+	if num_queries < 1 then 
+		num_queries = 1 
+	elseif num_queries > 500 then
+		num_queries = 500
+	end
+	
+	local worlds = {}
+	for i=1, num_queries do
+		worlds[#worlds + 1] = db:findOne({World = {id = op.equal(math.random(1,10000))}})
+	end
+	return worlds
+end
+
+
+local status, db = pcall(database.connect)
+if not status then exit(db) end
+
+local status, res = pcall(process, db)
+db:close()
+
+if status then
+	ngx.header.content_type = 'application/json'
+	ngx.print(json.encode(res))
+else
+	exit(res)
+end

+ 2 - 0
frameworks/Lua/octopus/app/src/PlaintextController.lua

@@ -0,0 +1,2 @@
+ngx.header.content_type = 'text/plain'
+ngx.print("Hello, World!")

+ 24 - 0
frameworks/Lua/octopus/app/src/SingleQueryController.lua

@@ -0,0 +1,24 @@
+local json = require "json"
+local database = require "database"
+local exit = require "exit"
+
+
+local function process (db)
+	local op = db:operators()
+	
+	return db:findOne({World = {id = op.equal(math.random(1,10000))}})
+end
+
+
+local status, db = pcall(database.connect)
+if not status then exit(db) end
+
+local status, res = pcall(process, db)
+db:close()
+
+if status then
+	ngx.header.content_type = 'application/json'
+	ngx.print(json.encode(res))
+else
+	exit(res)
+end

+ 39 - 0
frameworks/Lua/octopus/app/src/UpdateController.lua

@@ -0,0 +1,39 @@
+local json = require "json"
+local database = require "database"
+local param = require "param"
+local exit = require "exit"
+
+
+local function process (db)
+	local op = db:operators()
+	
+	local num_queries = tonumber(param.queries) or 1
+	if num_queries < 1 then 
+		num_queries = 1 
+	elseif num_queries > 500 then
+		num_queries = 500
+	end
+	
+	local worlds = {}
+	for i=1, num_queries do
+		local world = db:findOne({World = {id = op.equal(math.random(1,10000))}})
+		world.randomNumber = math.random(1,10000)
+		db:update({World = world})
+		worlds[#worlds + 1] = world
+	end
+	return worlds
+end
+
+
+local status, db = pcall(database.connect)
+if not status then exit(db) end
+
+local status, res = pcall(process, db)
+db:close()
+
+if status then
+	ngx.header.content_type = 'application/json'
+	ngx.print(json.encode(res))
+else
+	exit(res)
+end

+ 12 - 0
frameworks/Lua/octopus/app/src/types.lua

@@ -0,0 +1,12 @@
+return {
+
+	World = {
+		-- id field is implicitly defined by the ORM
+		randomNumber = "integer",
+	},
+
+	Fortune = {
+		-- id field is implicitly defined by the ORM
+		message = "string",
+	},
+}

+ 28 - 0
frameworks/Lua/octopus/benchmark_config.json

@@ -0,0 +1,28 @@
+{
+  "framework": "octopus",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/update?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "Octopus",
+      "language": "Lua",
+      "orm": "Full",
+      "platform": "OpenResty",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Octopus",
+      "notes": "",
+      "versus": "openresty"
+    }
+  }]
+}

+ 39 - 0
frameworks/Lua/octopus/config.lua

@@ -0,0 +1,39 @@
+return {
+	extensions = {
+		{octopusExtensionsDir, "core"}, 
+		{octopusExtensionsDir, "baseline"}, 
+		{octopusExtensionsDir, "orm"}, 
+		{octopusExtensionsDir, "app"},
+	},
+	
+	octopusExtensionsDir = octopusExtensionsDir,
+	octopusHostDir = octopusHostDir,
+	port = 8080,
+	securePort = 38080,
+	luaCodeCache = "on",
+	serverName = "localhost",
+	errorLog = "error_log logs/error.log;",
+	accessLog = "access_log logs/access.log;",
+	includeDrop = [[#include drop.conf;]],
+	maxBodySize = "50k",
+	minifyJavaScript = false,
+	minifyCommand = [[java -jar ../yuicompressor-2.4.8.jar %s -o %s]],
+	
+	databaseConnection = {
+		rdbms       =   "mysql",
+		host        =   "DBHOSTNAME",
+		port        =   3306, 
+		database    =   "hello_world",
+		user        =   "benchmarkdbuser",
+		password    =   "benchmarkdbpass",
+		compact     =   false
+	},
+
+	globalParameters = {
+		octopusHostDir = octopusHostDir,
+		sourceCtxPath = "",
+		requireSecurity = false,
+		sessionTimeout = 3600,
+		usePreparedStatement = false,
+	},
+}

+ 13 - 0
frameworks/Lua/octopus/setup.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+
+rm -rf octopus
+git clone https://github.com/cyberz-eu/octopus.git
+cp -avr app octopus/extensions
+cp -vf config.lua octopus/extensions
+sed -i 's|DBHOSTNAME|'"${DBHOST}"'|g' octopus/extensions/config.lua
+
+cd octopus/bin/unix
+. ./server.sh install
+. ./server.sh build
+. ./server.sh start