Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LUA_INCLUDE_DIR ?= $(PREFIX)/include
LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
INSTALL ?= install

.PHONY: all test install
.PHONY: all test install stress_test clean

all: ;

Expand All @@ -17,3 +17,8 @@ install: all
test: all
PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t

stress_test:
make -C stress_test ITERATOR=8

clean:
make -C stress_test clean
56 changes: 56 additions & 0 deletions stress_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.PHONY: all clean
default : all

TARGZ_INPUTS := http://nginx.org/download/nginx-1.7.9.tar.gz \
https://github.com/cloudflare/lua-aho-corasick/archive/46f1a4146b8b9021b8df25a39572d1242ece899d.tar.gz

LOCALFILES := $(foreach f, $(TARGZ_INPUTS), $(call notdir, $f))
KEYFILES := $(patsubst %.tar.gz, %.key, $(LOCALFILES))
TMP_FILE := a.tmp
TMP_DIR := tmp

ITERATOR := 4
LUAJIT := luajit

######################################################################
#
# Download *.tar.gz files from Internet
#
######################################################################
#
define DOWNLOAD
$$(notdir $(1)) :
wget $(1) -O $$@
endef
$(foreach k,$(TARGZ_INPUTS),$(eval $(call DOWNLOAD,$(k))))

######################################################################
#
# generate files of keys from ther *.tar.gz downloaded from Internet
#
######################################################################
#
define GEN_KEY
$$(patsubst %.tar.gz, %.key, $(1)): $(1)
rm -rf $(TMP_DIR); \
mkdir $(TMP_DIR); \
tar -C $(TMP_DIR) -zxvf $(1); \
find $(TMP_DIR) -type f -exec cat {} \; > $(TMP_FILE); \
./key.py $(TMP_FILE) > $$@
rm -rf $(TMP_DIR) $(TMP_FILE)
endef
$(foreach k,$(LOCALFILES),$(eval $(call GEN_KEY,$(k))))

all:
@for f in $(KEYFILES); do \
echo "Testing with $${f}..."; \
for i in `seq $(ITERATOR)`; do \
echo "Iteration $${i}"; \
rm -f $${f}; \
$(MAKE) $${f} > /dev/null; \
$(LUAJIT) ./test.lua $${f}; \
done; \
done

clean:
rm -rf $(LOCALFILES) $(KEYFILES) $(TMP_FILE) $(TMP_DIR)
30 changes: 30 additions & 0 deletions stress_test/key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

import random
import fileinput
import sys
import os

def print_usage(prog):
print ("%s [list of files]" % prog)
return

if len(sys.argv) == 1:
print_usage(sys.argv[0])
sys.exit(1)

for f in sys.argv[1:]:
if not os.access(f, os.R_OK):
print "file '%s' is not readable" % f
sys.exit(1)

for line in fileinput.input():
columns = line.split()
cn = len(columns)
if cn > 0:
col_idx = int(random.random() * cn + 0.5)
if col_idx == cn:
col_idx = 0
print columns[col_idx]

sys.exit(0)
67 changes: 67 additions & 0 deletions stress_test/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local argv = {...}
if #argv ~= 1 then
print ("Usage test.lua key-file")
os.exit(1)
end

local keyfile = io.open(argv[1])
if not keyfile then
io.write(string.format("Fail to open key file '%s'\n", argv[1]))
os.exit(1)
end

ngx = {}
ngx.new = function() return os.time() end

package.path = "../lib/resty/?.lua;../lib/resty/lrucache/?.lua;" .. package.path
lruffi = require "pureffi"
lru = require "lrucache"

local key_num = 128
local lru_inst = lru.new(key_num)
local lruffi_inst = lruffi.new(key_num, 0.5)

local key_vect = {}
local key_idx = 0
local key_cnt = 0

local function compare()
for i = 1, key_idx do
local key = key_vect[i]
local val1 = lru_inst:get(key)
local val2 = lruffi_inst:get(key)
-- print(key, val1, val2)
if val1 ~= val2 then
io.write(
string.format("disagree on key '%s', values are %d vs %d\n",
key, val1, val2))
os.exit(1)
end
end
end

local function main()
for line in keyfile:lines() do

lru_inst:set(line, key_cnt)
lruffi_inst:set(line, key_cnt)

key_cnt = key_cnt + 1
key_idx = key_idx + 1
key_vect[key_idx] = line

if key_idx == key_num then
compare()
for i = 1, key_idx do
key_vect[i] = nil
end
key_idx = 0
end
end

compare()
end

main()

os.exit(0)