diff --git a/Dockerfile b/Dockerfile index ebdeccfd..ebdd69e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,8 @@ ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \ # update RUN set -ex \ + && apk --no-cache add \ + && apk add php82-pdo_pgsql \ # show php version and extensions && php -v \ && php -m \ diff --git a/app/Process/AsyncQueueConsumer.php b/app/Process/AsyncQueueConsumer.php new file mode 100644 index 00000000..af0197ac --- /dev/null +++ b/app/Process/AsyncQueueConsumer.php @@ -0,0 +1,13 @@ +=5.0", + "hyperf/collection": "~3.0.0", + "hyperf/database": "~3.0.0", + "hyperf/support": "~3.0.0", + "hyperf/tappable": "~3.0.0", + "php": ">=8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + }, + "hyperf": { + "config": "Hyperf\\Database\\PgSQL\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Hyperf\\Database\\PgSQL\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A pgsql handler for hyperf/database.", + "homepage": "https://hyperf.io", + "keywords": [ + "database", + "hyperf", + "pgsql", + "php", + "swoole" + ], + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "time": "2023-05-31T02:10:17+00:00" + }, { "name": "hyperf/db-connection", "version": "v3.0.24", @@ -8724,7 +8781,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.0" + "php": ">=8.2" }, "platform-dev": [], "plugin-api-version": "2.3.0" diff --git a/config/autoload/async_queue.php b/config/autoload/async_queue.php index 27a58907..92c7a487 100644 --- a/config/autoload/async_queue.php +++ b/config/autoload/async_queue.php @@ -1,10 +1,20 @@ [ - 'driver' => Hyperf\AsyncQueue\Driver\RedisDriver::class, - 'channel' => 'queue', + 'driver' => RedisDriver::class, + 'redis' => [ + 'pool' => 'default', + ], + 'channel' => '{queue}', + 'timeout' => 2, 'retry_seconds' => 5, - 'processes' => 1, + 'handle_timeout' => 10, + 'processes' => 2, + 'concurrent' => [ + 'limit' => 1, + ], ], ]; \ No newline at end of file diff --git a/config/autoload/databases.php b/config/autoload/databases.php index 60531842..046d8477 100644 --- a/config/autoload/databases.php +++ b/config/autoload/databases.php @@ -19,14 +19,12 @@ 'port' => env('DB_PORT', 3306), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), - 'charset' => env('DB_CHARSET', 'utf8'), - 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), 'prefix' => env('DB_PREFIX', ''), 'pool' => [ 'min_connections' => 1, - 'max_connections' => 1000000, + 'max_connections' => 1000, 'connect_timeout' => 10.0, - 'wait_timeout' => 10.0, + 'wait_timeout' => 3, 'heartbeat' => -1, 'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60), ], diff --git a/docker-compose.yml b/docker-compose.yml index 0742182c..aa7e2628 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.9' services: api1: &api @@ -8,9 +8,8 @@ services: context: . args: APP_STAGE: dev - environment: - DB_HOST: db - REDIS_HOST: cache + env_file: + - .env volumes: - ./:/opt/www depends_on: @@ -43,6 +42,25 @@ services: cpus: '0.65' memory: '1.0GB' + # postgres + postgres: + container_name: rinha-de-backend-postgres + image: postgres:latest + environment: + POSTGRES_DB: ${DB_DATABASE} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_USER: ${DB_USERNAME} + PGDATA: /var/lib/postgresql/data/db-files/ + volumes: + - ./migration-postgres.sql:/docker-entrypoint-initdb.d/ddl.sql + ports: + - 5432:5432 + deploy: + resources: + limits: + cpus: '0.35' + memory: '0.7GB' + cache: container_name: rinha-de-backend-cache image: redis:latest diff --git a/migration-postgres.sql b/migration-postgres.sql new file mode 100644 index 00000000..e69de29b