Skip to content

Commit c63a52e

Browse files
committed
Improve correctness for queries
1 parent 8bc7acb commit c63a52e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

frameworks/Lua/openresty/app.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ local mysqlconn = {
1818
password = "benchmarkdbpass"
1919
}
2020
return {
21+
db = function(ngx)
22+
local db = mysql:new()
23+
assert(db:connect(mysqlconn))
24+
ngx.print(encode(db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]))
25+
db:set_keepalive(0, 256)
26+
end,
2127
queries = function(ngx)
2228
local db = mysql:new()
2329
assert(db:connect(mysqlconn))
@@ -27,8 +33,8 @@ return {
2733
-- it doesn't matter. For me, after a small warmup, the performance
2834
-- is identical to a version without the branch
2935
-- http://wiki.luajit.org/Numerical-Computing-Performance-Guide
30-
if num_queries == 1 then
31-
ngx.print(encode(db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]))
36+
if num_queries < 2 then
37+
ngx.print(encode({db:query('SELECT * FROM World WHERE id = '..random(1,10000))[1]}))
3238
else
3339
local worlds = {}
3440
num_queries = min(500, num_queries)

frameworks/Lua/openresty/benchmark_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"setup_file": "setup",
66
"json_url": "/json",
77
"db_url": "/db",
8-
"query_url": "/db?queries=",
8+
"query_url": "/queries?queries=",
99
"fortune_url": "/fortunes",
1010
"plaintext_url": "/plaintext",
1111
"port": 8080,

frameworks/Lua/openresty/nginx.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ http {
2525
default_type "text/html; charset=UTF-8";
2626
content_by_lua 'app.fortunes(ngx)';
2727
}
28+
location /db {
29+
default_type "application/json";
30+
content_by_lua 'app.db(ngx)';
31+
}
2832
location / {
33+
default_type "application/json";
2934
content_by_lua 'app.queries(ngx)';
3035
}
3136
}

0 commit comments

Comments
 (0)