diff --git a/Makefile b/Makefile index 0afe5ab..673d088 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/bench.lua b/bench.lua new file mode 100644 index 0000000..f9a3359 --- /dev/null +++ b/bench.lua @@ -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 diff --git a/bench.sh b/bench.sh new file mode 100755 index 0000000..da030d6 --- /dev/null +++ b/bench.sh @@ -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 diff --git a/post.lua b/post.lua new file mode 100644 index 0000000..4140c22 --- /dev/null +++ b/post.lua @@ -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 diff --git a/src/entry.c b/src/entry.c index e4747df..d3d1179 100644 --- a/src/entry.c +++ b/src/entry.c @@ -2,28 +2,6 @@ #include #include -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; diff --git a/src/main.cpp b/src/main.cpp index fd1036b..2b88f8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); });