Browse Source

Improve correctness for queries

Tor Hveem 10 years ago
parent
commit
c63a52eb03

+ 8 - 2
frameworks/Lua/openresty/app.lua

@@ -18,6 +18,12 @@ local mysqlconn = {
 	password = "benchmarkdbpass"
 }
 return {
+    db = function(ngx)
+        local db = mysql:new()
+        assert(db:connect(mysqlconn))
+        ngx.print(encode(db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]))
+        db:set_keepalive(0, 256)
+    end,
     queries = function(ngx)
         local db = mysql:new()
         assert(db:connect(mysqlconn))
@@ -27,8 +33,8 @@ return {
         -- it doesn't matter. For me, after a small warmup, the performance
         -- is identical to a version without the branch
         -- http://wiki.luajit.org/Numerical-Computing-Performance-Guide
-        if num_queries == 1 then
-            ngx.print(encode(db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]))
+        if num_queries < 2 then
+            ngx.print(encode({db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]}))
         else
             local worlds = {}
             num_queries = min(500, num_queries)

+ 1 - 1
frameworks/Lua/openresty/benchmark_config.json

@@ -5,7 +5,7 @@
       "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "fortune_url": "/fortunes",
       "plaintext_url": "/plaintext",
       "port": 8080,

+ 5 - 0
frameworks/Lua/openresty/nginx.conf

@@ -25,7 +25,12 @@ http {
             default_type "text/html; charset=UTF-8";
             content_by_lua 'app.fortunes(ngx)';
         }
+        location /db {
+            default_type "application/json";
+            content_by_lua 'app.db(ngx)';
+        }
         location / {
+            default_type "application/json";
             content_by_lua 'app.queries(ngx)';
         }
     }