feat: add some benchmarking stuff

generic-data-trie
Jef Roosens 2022-12-10 20:03:14 +01:00
parent 5d1574ffd4
commit dd48b960c2
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
6 changed files with 74 additions and 23 deletions

View File

@ -43,6 +43,10 @@ prod: cmake-release
run: build
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test ./build/Debug/lander
.PHONY: run-prod
run-prod: prod
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test ./build/Release/lander
.PHONY: valgrind
valgrind: build
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test \

13
bench.lua 100644
View File

@ -0,0 +1,13 @@
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
request = function()
path = "/"
for i = 1,4 do
local rint = math.random(1, #chars)
path = path .. chars:sub(rint, rint)
end
return wrk.format(nil, path)
end

32
bench.sh 100755
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
function random_string {
chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for i in {1..4} ; do
echo -n "${chars:RANDOM%${#chars}:1}"
done
}
data_dir="$(mktemp -d)"
# make prod
# LANDER_DATA_DIR="${data_dir}" \
# LANDER_BASE_URL=http://localhost:18080/ \
# LANDER_API_KEY=test \
# ./build/Release/lander &
# # Just to make sure the server has started
sleep 1
# Populate server with data
for x in {1..100000} ; do
path="$(random_string)"
curl \
-XPOST \
-H 'X-Api-Key: test' \
-d "http://example.com/thisisalongurl" \
-s \
"http://localhost:18080/s/${path}" > /dev/null
done

24
post.lua 100644
View File

@ -0,0 +1,24 @@
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
request = function()
path = "/s/"
for i = 1,16 do
local rint = math.random(1, #chars)
path = path .. chars:sub(rint, rint)
end
body = "https://example.com/"
for i = 1,32 do
local rint = math.random(1, #chars)
body = body .. chars:sub(rint, rint)
end
wrk.path = path
wrk.method = "POST"
wrk.body = body
wrk.headers["X-Api-Key"] = "test"
return wrk.format()
end

View File

@ -2,28 +2,6 @@
#include <stdlib.h>
#include <string.h>
EntryType entry_type_from_char(char c) {
switch (c) {
case '0':
return Redirect;
case '1':
return Paste;
default:
return Unknown;
}
}
char entry_type_to_char(EntryType et) {
switch (et) {
case Redirect:
return '0';
case Paste:
return '1';
default:
return '\0';
}
}
uint64_t entry_new(Entry **entry_ptr, EntryType type, const char *string) {
size_t str_len = strlen(string);
uint64_t entry_size = sizeof(EntryType) + str_len + 1;

View File

@ -108,7 +108,7 @@ int main() {
mkdir("pastes", 0700);
crow::SimpleApp app;
app.loglevel(crow::LogLevel::Info);
app.loglevel(crow::LogLevel::Warning);
CROW_ROUTE(app, "/").methods(crow::HTTPMethod::Get)(
[]() { return crow::response("html", index_page); });