Skip to content

Commit

Permalink
Melhora configuração para testes e altera configuração do docker-comp…
Browse files Browse the repository at this point in the history
…ose (#1)

* added: Improve tests and change docker-compose configs

* added: Improve tests and change docker-compose configs

* remove: Remove arquivos de resultados

* remove: Remove arquivos de resultados

---------

Co-authored-by: Diego Ferreira <diegoferreira@PPM-SPO-015219.local>
  • Loading branch information
eudiegoborgs and Diego Ferreira committed Aug 18, 2023
1 parent 1b9cfc1 commit 78e6234
Show file tree
Hide file tree
Showing 9 changed files with 105,186 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ vendor/
.DS_Store
.phpunit*
*.cache
.vscode/
.vscode/
stress-test/user-files/results/
29 changes: 18 additions & 11 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@

use function Hyperf\Support\env;

$appEnv = env('APP_ENV', 'dev');

$logLevel = [
LogLevel::ALERT,
LogLevel::CRITICAL,
LogLevel::EMERGENCY,
LogLevel::ERROR,
LogLevel::INFO,
LogLevel::NOTICE,
LogLevel::WARNING,
];

if ($appEnv === 'dev') {
$logLevel[] = LogLevel::DEBUG;
}

return [
'app_name' => env('APP_NAME', 'rinha-de-backend'),
'app_env' => env('APP_ENV', 'dev'),
'app_env' => $appEnv,
'scan_cacheable' => env('SCAN_CACHEABLE', false),
StdoutLoggerInterface::class => [
'log_level' => [
LogLevel::ALERT,
LogLevel::CRITICAL,
LogLevel::DEBUG,
LogLevel::EMERGENCY,
LogLevel::ERROR,
LogLevel::INFO,
LogLevel::NOTICE,
LogLevel::WARNING,
],
'log_level' => $logLevel,
],
];
55 changes: 44 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
version: '3'
version: '3.5'

services:
api1: &api
container_name: rinha-de-backend-app1
image: rinha-de-backend
build:
context: .
args:
APP_STAGE: dev
environment:
DB_HOST: db
volumes:
- ./:/opt/www
depends_on:
- db
deploy:
resources:
limits:
cpus: '0.3'
memory: '0.5GB'

api2:
<<: *api
container_name: rinha-de-backend-app2

db:
container_name: rinha-de-backend-db
image: mysql:8.1
Expand All @@ -11,19 +35,28 @@ services:
- ./migrations.sql:/docker-entrypoint-initdb.d/migrations.sql
ports:
- 3306:3306
deploy:
resources:
limits:
cpus: '0.7'
memory: '1.5GB'

app:
container_name: rinha-de-backend-app
image: rinha-de-backend-app
build:
context: .
environment:
DB_HOST: db
nginx:
image: nginx
container_name: rinha-de-backend-nginx
volumes:
- ./:/opt/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api1
- api2
ports:
- 9501:9501
- 9999:9999
deploy:
resources:
limits:
cpus: '0.2'
memory: '0.5GB'

networks:
default:
name: rinha-de-backend
name: rinha-de-backend
27 changes: 27 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes auto;

events {
worker_connections 4096;
}

http {
access_log off;
#proxy_cache_path /tmp/cache keys_zone=cacherinha:100m max_size=1G use_temp_path=off;
#proxy_cache_valid any 15s;

upstream api {
server api1:9501;
server api2:9501;
}

server {
listen 9999;

location / {
proxy_pass http://api;

#proxy_cache cacherinha;
#proxy_cache_background_update on;
}
}
}
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
testdox="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./test</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing" force="true"/>
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
Expand Down
19 changes: 19 additions & 0 deletions stress-test/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Exemplos de requests
# curl -v -XPOST -H "content-type: application/json" -d '{"apelido" : "xpto", "nome" : "xpto xpto", "nascimento" : "2000-01-01", "stack": null}' "http://localhost:9999/pessoas"
# curl -v -XGET "http://localhost:9999/pessoas/1"
# curl -v -XGET "http://localhost:9999/pessoas?t=xpto"
# curl -v "http://localhost:9999/contagem-pessoas"

GATLING_BIN_DIR=$HOME/gatling/3.9.5/bin

WORKSPACE=$HOME/projects/rinha-de-backend-2023-q3/stress-test

sh $GATLING_BIN_DIR/gatling.sh -rm local -s RinhaBackendSimulation \
-rd "DESCRICAO" \
-rf $WORKSPACE/user-files/results \
-sf $WORKSPACE/user-files/simulations \
-rsf $WORKSPACE/user-files/resources \

sleep 3

curl -v "http://localhost:9999/contagem-pessoas"
100,001 changes: 100,001 additions & 0 deletions stress-test/user-files/resources/pessoas-payloads.tsv

Large diffs are not rendered by default.

Loading

0 comments on commit 78e6234

Please sign in to comment.