[examples] Update NGinx template and add wrk random paths script

This commit is contained in:
Ciprian Dorin Craciun 2019-08-13 18:42:09 +03:00
parent 95f1a119ea
commit 502d292f17
2 changed files with 40 additions and 3 deletions

View file

@ -20,7 +20,7 @@ http {
server {
listen 127.0.0.1:8080 default_server bind reuseport backlog=4096;
listen 127.0.0.1:8080 default_server bind backlog=65536;
server_name nginx;
server_name_in_redirect off;
@ -69,7 +69,7 @@ http {
worker_processes 2;
worker_rlimit_nofile 8192;
worker_rlimit_nofile 131072;
working_directory @{nginx}/empty;
error_log /dev/stderr notice;
@ -79,7 +79,7 @@ daemon off;
events {
use epoll;
worker_connections 4224;
worker_connections 16640;
accept_mutex off;
multi_accept off;
}

View file

@ -0,0 +1,37 @@
local _generated_requests = {}
function init (_arguments)
for _index, _argument in ipairs (_arguments) do
_generate_requests (_generated_requests, _argument)
end
end
function request ()
local _index = math.random (#_generated_requests)
return _generated_requests[_index]
end
function _generate_requests (_requests, _path)
local _tid = wrk.thread.tindex .. "/" .. wrk.thread.tcount
print ("[ii] [" .. _tid .. "] loading paths from `" .. _path .. "`...")
local _index = 0
local _wrk_path_prefix = wrk.path:gsub ("/$", "")
for _wrk_path_suffix in io.lines (_path) do
if math.fmod (_index, wrk.thread.tcount) == wrk.thread.tindex then
if not _wrk_path_suffix:match ("/$") then
_wrk_path_suffix = _wrk_path_suffix:gsub ("^/", "")
_wrk_path = _wrk_path_prefix .. "/" .. _wrk_path_suffix
_request = wrk.format (wrk.method, _wrk_path, wrk.headers, wrk.body)
table.insert (_generated_requests, _request)
end
end
_index = _index + 1
end
print ("[ii] [" .. _tid .. "] loaded `" .. #_generated_requests .. '` of `' .. _index .. "` paths.")
end