File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed
Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ local mysqlconn = {
1818 password = " benchmarkdbpass"
1919}
2020return {
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 )
Original file line number Diff line number Diff line change 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 ,
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments