feat: add some benchmarking stuff
parent
5d1574ffd4
commit
dd48b960c2
4
Makefile
4
Makefile
|
@ -43,6 +43,10 @@ prod: cmake-release
|
||||||
run: build
|
run: build
|
||||||
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test ./build/Debug/lander
|
@ 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
|
.PHONY: valgrind
|
||||||
valgrind: build
|
valgrind: build
|
||||||
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test \
|
@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test \
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
22
src/entry.c
22
src/entry.c
|
@ -2,28 +2,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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) {
|
uint64_t entry_new(Entry **entry_ptr, EntryType type, const char *string) {
|
||||||
size_t str_len = strlen(string);
|
size_t str_len = strlen(string);
|
||||||
uint64_t entry_size = sizeof(EntryType) + str_len + 1;
|
uint64_t entry_size = sizeof(EntryType) + str_len + 1;
|
||||||
|
|
|
@ -108,7 +108,7 @@ int main() {
|
||||||
mkdir("pastes", 0700);
|
mkdir("pastes", 0700);
|
||||||
|
|
||||||
crow::SimpleApp app;
|
crow::SimpleApp app;
|
||||||
app.loglevel(crow::LogLevel::Info);
|
app.loglevel(crow::LogLevel::Warning);
|
||||||
|
|
||||||
CROW_ROUTE(app, "/").methods(crow::HTTPMethod::Get)(
|
CROW_ROUTE(app, "/").methods(crow::HTTPMethod::Get)(
|
||||||
[]() { return crow::response("html", index_page); });
|
[]() { return crow::response("html", index_page); });
|
||||||
|
|
Loading…
Reference in New Issue