云搜索服务 CSS-Elasticsearch向量检索的性能测试和比较:脚本“perf.lua”

时间:2025-01-06 15:21:22

脚本“perf.lua”

local random = math.random

local reqs = {}
local cnt = 0

-- 压测数据文件名称根据需要调整。
for line in io.lines("sift_requests.txt") do
    table.insert(reqs, line)
    cnt = cnt + 1
end


local addrs = {}
local counter = 0
function setup(thread)
   local append = function(host, port)
      for i, addr in ipairs(wrk.lookup(host, port)) do
         if wrk.connect(addr) then
            addrs[#addrs+1] = addr
         end
      end
   end

   if #addrs == 0 then
      -- 根据集群的实际地址进行修改。
      append("192.168.0.84", 9200)
      append("192.168.0.32", 9200)
      append("192.168.0.49", 9200)
   end

   local index = counter % #addrs + 1
   counter = counter + 1
   thread.addr = addrs[index]
end

-- 索引名称根据需要调整。
wrk.path = "/index_sift_graph/_search?request_cache=false&preference=_local"
wrk.method = "GET"
wrk.headers["Content-Type"] = "application/json"


function request()
    return wrk.format(wrk.method, wrk.path, wrk.headers, reqs[random(cnt)])
end
support.huaweicloud.com/bestpractice-css/css_07_0050.html