From 502d292f17310ed066d27a0f2be9cd2dd070edaf Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Tue, 13 Aug 2019 18:42:09 +0300 Subject: [PATCH] [examples] Update NGinx template and add wrk random paths script --- examples/nginx.conf | 6 +++--- examples/wrk-paths-from-file.lua | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 examples/wrk-paths-from-file.lua diff --git a/examples/nginx.conf b/examples/nginx.conf index 82d84eb..1243e5c 100644 --- a/examples/nginx.conf +++ b/examples/nginx.conf @@ -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; } diff --git a/examples/wrk-paths-from-file.lua b/examples/wrk-paths-from-file.lua new file mode 100644 index 0000000..ce8ee1d --- /dev/null +++ b/examples/wrk-paths-from-file.lua @@ -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 +