Skip to content

Instantly share code, notes, and snippets.

@moteus
Last active November 23, 2017 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moteus/b7cfbe39146de96da304 to your computer and use it in GitHub Desktop.
Save moteus/b7cfbe39146de96da304 to your computer and use it in GitHub Desktop.
Basic cache perfomance test for FusionPBX
-- to run test
-- * copy file to ${script_dir}\cache_perf.lua
-- * in some domain create varialble
-- category: test
-- subcategory: test
-- type: bool
-- value: false
-- * copy domain uuid to `domain_uuid` variable
-- * from fs_cli run `lua cache_perf.lua 1000`
-- (1000 is number of iteration)
local category, subcategory, name = 'test', 'test', 'bool'
local domain_uuid = '2a41891a-370d-4815-a652-65d84c79e33c'
require 'resources.functions.config'
local cache = require 'resources.functions.cache'
local Database = require 'resources.functions.database'
local function printf(...)
local str = string.format(...)
if freeswitch then
freeswitch.consoleLog("INFO", str .. "\n")
else
print(str)
end
end
local backend = freeswitch and 'native' or 'odbc'
local db = Database.backend[backend]('system')
local sql = "SELECT domain_setting_uuid,domain_setting_category,domain_setting_subcategory,domain_setting_name,domain_setting_value "
sql = sql .. "FROM v_domain_settings ";
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "'";
sql = sql .. "AND domain_setting_enabled = 'true' ";
sql = sql .. "AND domain_setting_category = '" .. category .."'";
sql = sql .. "AND domain_setting_subcategory = '" .. subcategory .. "'";
sql = sql .. "AND domain_setting_name = '" .. name .. "'";
sql = sql .. "AND domain_setting_value is not null ";
sql = sql .. "ORDER BY domain_setting_category, domain_setting_subcategory ASC ";
local N = tonumber(argv and argv[1]) or 10000
local start = os.clock()
for i = 1, N do
db:first_value(sql)
end
local elapsed = os.clock() - start
printf("Database: %.4f[s] %d[req/s]", elapsed, N/elapsed)
if cache.support() then
local key = table.concat({domain_uuid, category, subcategory, name}, ':')
cache.set(key, 'false')
local start = os.clock()
for i = 1, N do
cache.get(key)
end
local elapsed = os.clock() - start
printf("Memcache: %.4f[s] %d[req/s]", elapsed, N/elapsed)
cache.del(key)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment