How we reduced the CPU usage of our Lua code

Total CPU usage of one of the Openresty server over 24h
package.path = package.path .. ";/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua"
# the custom include path is already present 3 times/usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua
# I cut the central piece to avoid too much text, but after 1 000 requests, the custom paths were present 110 times./usr/local/openresty/site/lualib/?.ljbc;/usr/local/openresty/site/lualib/?/init.ljbc;/usr/local/openresty/lualib/?.ljbc;/usr/local/openresty/lualib/?/init.ljbc;/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua;./?.lua;/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?/init.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;;;;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;
[...]
;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua
# in nginx.conf, we added the following, in the http{} block:
lua_package_path '/usr/local/nginx/includes.d/?.lua;/home/user/lua/?.lua;/home/lua/?.lua;;';
The CPU usage went down after we removed the package.path concatenation

--

--

DevOps @ MindGeek Canada

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store