Created
January 14, 2016 17:40
-
-
Save siscia/d9d72086110c80d75ea6 to your computer and use it in GitHub Desktop.
Numerino Bench Mark for wrk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cjson = require('cjson') | |
| request_table = {} | |
| priorities = { | |
| {"1","2","3","4","5"}, | |
| {"1","2","3"}, | |
| {"critical", "urgent", "high", "medium", "low"}, | |
| {"high", "medium", "low"} | |
| } | |
| log_file = assert(io.open("log.txt", "w")) | |
| print(log_file) | |
| -- types = {"transient", "persistent"} | |
| types = {"transient"} | |
| -- types = {"persistent"} | |
| headers = {['Content-Type'] = "application/json"} | |
| function new_queue() | |
| new_type = types[math.random(#types)] | |
| ps = priorities[math.random(#priorities)] | |
| -- print(new_type) | |
| array = cjson.encode(ps) | |
| new_body = string.format("{\"type\" : \"%s\", \"priorities\" : %s}", new_type, array) | |
| return wrk.format("POST", "/" .. new_type, headers, new_body) | |
| end | |
| function generate_pop(name, ts) | |
| return wrk.format("GET", "/"..ts.."/"..name, headers, nil) | |
| end | |
| function generate_push(name, ts, p) | |
| message = "message for priority: " .. p .. " of type: " .. ts | |
| body = string.format("{\"priority\" : \"%s\", \"message\" : \"%s\"}", p, message) | |
| return wrk.format("POST", "/"..ts.."/"..name, headers, body) | |
| end | |
| function add_get_and_post(name, types, priorities) | |
| pop = generate_pop(name, types) | |
| push = {} | |
| for i = 1, #priorities do | |
| push[i] = generate_push(name, types, priorities[i]) | |
| end | |
| request_table[#request_table + 1] = {['pop'] = pop, ['push'] = push} | |
| -- print(#request_table) | |
| return | |
| end | |
| request = function() | |
| if #request_table < 5 then | |
| local new_queue = new_queue() | |
| log_file:write("\n\n == new == \n", new_queue, "\n") | |
| return new_queue | |
| end | |
| n = math.random(102) | |
| if n <= 2 then | |
| local new_queue = new_queue() | |
| log_file:write("\n\n == new == \n", new_queue, "\n") | |
| return new_queue | |
| end | |
| if n <= 10 then | |
| local pop = request_table[math.random(#request_table)]['pop'] | |
| log_file:write("\n\n == pop == \n", pop, "\n") | |
| return pop | |
| end | |
| index_queue = math.random(#request_table) | |
| index_prior = math.random(#request_table[index_queue]['push']) | |
| push = request_table[index_queue]['push'][index_prior] | |
| log_file:write("\n\n == push == \n", push, "\n") | |
| return push | |
| end | |
| response = function(status, headers, body) | |
| if status == 201 then | |
| local t = cjson.decode(body) | |
| local name = t['queue']['name'] | |
| local priorities = t['queue']['priorities'] | |
| local types = t['queue']['type'] | |
| print("Adding new request "..name) | |
| add_get_and_post(name, types, priorities) | |
| end | |
| log_file:write("\n\n == response == \n", status, "\n", cjson.encode(headers), "\n", body, "\n") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment