From dad178bd0db4960828c7a3d1a713e695b8c5ccd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=A1=D0=B0?= =?UTF-8?q?=D0=B1=D0=B8=D0=BB=D0=B8=D0=BD?= Date: Thu, 23 Apr 2026 22:01:45 +0300 Subject: [PATCH] Load tests --- Makefile | 33 ++++++++++++++++ test/tsung/eventhub_http.xml | 64 +++++++++++++++++++++++++++++++ test/wrk/scripts/wrk_register.lua | 6 +++ 3 files changed, 103 insertions(+) create mode 100644 test/tsung/eventhub_http.xml create mode 100644 test/wrk/scripts/wrk_register.lua diff --git a/Makefile b/Makefile index afded40..e531170 100644 --- a/Makefile +++ b/Makefile @@ -160,6 +160,39 @@ test-all: eunit ## Запустить ВСЕ тесты (EUnit + API) @echo " ВСЕ ТЕСТЫ ПРОЙДЕНЫ!" @echo "========================================" +# ============================================================================ +# LOAD TESTING +#3. Мониторинг во время нагрузочного теста +#Во время теста полезно следить за состоянием ноды: +# +#Через Docker (если приложение в контейнере): +#bash +#docker stats eventhub +#docker exec eventhub /app/bin/eventhub remote_console +#Внутри консоли Erlang можно выполнить: +# +#erlang +#observer:start(). % графический мониторинг +#recon:proc_count(5). % топ-5 процессов по памяти (если установлен recon) +# ============================================================================ +tsung-test: ## Запустить нагрузочный тест Tsung + @echo "Запуск нагрузочного теста Tsung..." + @mkdir -p logs/tsung + @tsung -f test/tsung/eventhub_http.xml -l logs/tsung start + @echo "Отчёт: logs/tsung/*/report.html" + +wrk-register: ## Нагрузочный тест регистрации (wrk2) + @wrk -t4 -c100 -d30s -t100 -s test/wrk/scripts/wrk_register.lua http://localhost:8080/v1/register + +wrk-search: ## Нагрузочный тест поиска (wrk2) + @TOKEN=$$(curl -s -X POST http://localhost:8080/v1/register \ + -H "Content-Type: application/json" \ + -d '{"email":"wrktest@test.com","password":"pass"}' | \ + grep -o '"token":"[^"]*"' | cut -d'"' -f4); \ + wrk -t4 -c100 -d30s -R200 \ + -H "Authorization: Bearer $$TOKEN" \ + http://localhost:8080/v1/search?type=event\&q=test + # ============================================================================ # CODE QUALITY # ============================================================================ diff --git a/test/tsung/eventhub_http.xml b/test/tsung/eventhub_http.xml new file mode 100644 index 0000000..ab00973 --- /dev/null +++ b/test/tsung/eventhub_http.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/wrk/scripts/wrk_register.lua b/test/wrk/scripts/wrk_register.lua new file mode 100644 index 0000000..c003679 --- /dev/null +++ b/test/wrk/scripts/wrk_register.lua @@ -0,0 +1,6 @@ +counter = 0 +request = function() + counter = counter + 1 + local body = string.format('{"email":"load%d@test.com","password":"pass"}', counter) + return wrk.format("POST", "/v1/register", {["Content-Type"]="application/json"}, body) +end \ No newline at end of file