Skip to content

Commit

Permalink
Add ProxySQL (#167)
Browse files Browse the repository at this point in the history
Adds ProxySQL to the stack, which acts as a connection pool
and provides the ability to route queries to different physical
MySQL machines, e.g. for schema-based sharding #119.

Applications communicate with ProxySQL via unix domain sockets,
which means that it will be deployed as a sidecar.
There are no query rules defined for the environments yet.
ProxySQL will pay of during load tests #118.

ProxySQL is optionally configurable via the PROXYSQL_CONFIG
environment variable, which is required for the Play with Docker
environment because the stack file must be self-contained.
  • Loading branch information
marein authored Apr 5, 2023
1 parent 5f4abbe commit 7f5ebe2
Show file tree
Hide file tree
Showing 10 changed files with 4,805 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
# dev|prod
APP_ENVIRONMENT=dev
APP_KERNEL_SECRET=ThisTokenIsNotSoSecretChangeIt
APP_WAIT_FOR=mysql:3306,redis:6379,rabbit-mq:5672,nchan:81
APP_WAIT_FOR=unix:///var/run/proxysql/proxysql.sock,mysql:3306,redis:6379,rabbit-mq:5672,nchan:81
APP_RABBIT_MQ_DSN=amqp://guest:guest@rabbit-mq:5672?receive_method=basic_consume&qos_prefetch_count=10&heartbeat=60

############################
# Chat Context #
############################
APP_CHAT_DOCTRINE_DBAL_URL=mysqli://root:password@mysql:3306/chat?persistent=1
APP_CHAT_DOCTRINE_DBAL_URL=mysqli://root:password@localhost/chat?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock
APP_CHAT_RUN_MIGRATIONS=1

############################
# Connect Four Context #
############################
APP_CONNECT_FOUR_DOCTRINE_DBAL_URL=mysqli://root:password@mysql:3306?persistent=1
APP_CONNECT_FOUR_DOCTRINE_DBAL_URL=mysqli://root:password@localhost?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock
APP_CONNECT_FOUR_DOCTRINE_DBAL_DATABASE=connect-four
APP_CONNECT_FOUR_DOCTRINE_DBAL_SHARDS=connect-four
APP_CONNECT_FOUR_RUN_MIGRATIONS=1
Expand All @@ -25,7 +25,7 @@ APP_CONNECT_FOUR_PREDIS_CLIENT_URL=redis://redis:6379?persistent=1
############################
# Identity Context #
############################
APP_IDENTITY_DOCTRINE_DBAL_URL=mysqli://root:password@mysql:3306/identity?persistent=1
APP_IDENTITY_DOCTRINE_DBAL_URL=mysqli://root:password@localhost/identity?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock
APP_IDENTITY_RUN_MIGRATIONS=1

############################
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ or in this context, the directory structure.

Some other technologies:
* [MySQL](https://www.mysql.com) as the main storage of the contexts.
* [ProxySQL](https://proxysql.com) as a connection pool and for query routing / database sharding.
* [Redis](https://redis.io) for the query models or as a caching layer. Also the user sessions are stored here.
* [Rabbit Mq](https://www.rabbitmq.com) as the message broker.
* [Nchan](https://nchan.io) for real-time browser notifications.
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ x-php-container:
APP_ENVIRONMENT: prod
depends_on:
- mysql
- proxysql
- redis
- rabbit-mq
- nchan
volumes:
- proxysql.sock:/var/run/proxysql
restart: on-failure

services:
Expand All @@ -34,6 +37,31 @@ services:
volumes:
- mysql:/var/lib/mysql
restart: on-failure
proxysql:
image: marein/php-gaming-website:proxysql
environment:
PROXYSQL_CONFIG: |
admin_variables: {
restapi_enabled="true"
}
mysql_variables: {
interfaces="/var/run/proxysql/proxysql.sock"
server_version="8.0"
monitor_username="root"
monitor_password="password"
auto_increment_delay_multiplex=0
}
mysql_servers: (
{hostgroup=1,address="mysql",port=3306,max_connections=100}
)
mysql_users: (
{username="root",password="password",default_hostgroup=1}
)
depends_on:
- mysql
volumes:
- proxysql.sock:/var/run/proxysql
restart: on-failure
redis:
image: marein/php-gaming-website:redis
command: redis-server --appendonly yes
Expand Down Expand Up @@ -96,5 +124,6 @@ services:

volumes:
mysql:
proxysql.sock:
redis:
rabbit-mq:
41 changes: 37 additions & 4 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ x-php-container:
environment:
APP_ENVIRONMENT: "prod"
APP_KERNEL_SECRET: "ThisTokenIsNotSoSecretChangeIt"
APP_WAIT_FOR: "mysql:3306,redis:6379,rabbit-mq:5672,nchan:81"
APP_WAIT_FOR: "unix:///var/run/proxysql/proxysql.sock,mysql:3306,redis:6379,rabbit-mq:5672,nchan:81"
APP_RABBIT_MQ_DSN: "amqp://guest:guest@rabbit-mq:5672?receive_method=basic_consume&qos_prefetch_count=10&heartbeat=60"
APP_CHAT_DOCTRINE_DBAL_URL: "mysqli://root:password@mysql:3306/chat?persistent=1"
APP_CHAT_DOCTRINE_DBAL_URL: "mysqli://root:password@localhost/chat?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock"
APP_CHAT_RUN_MIGRATIONS: "1"
APP_CONNECT_FOUR_DOCTRINE_DBAL_URL: "mysqli://root:password@mysql:3306?persistent=1"
APP_CONNECT_FOUR_DOCTRINE_DBAL_URL: "mysqli://root:password@localhost?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock"
APP_CONNECT_FOUR_DOCTRINE_DBAL_DATABASE: "connect-four"
APP_CONNECT_FOUR_DOCTRINE_DBAL_SHARDS: "connect-four"
APP_CONNECT_FOUR_RUN_MIGRATIONS: "1"
APP_CONNECT_FOUR_PREDIS_CLIENT_URL: "redis://redis:6379?persistent=1"
APP_IDENTITY_DOCTRINE_DBAL_URL: "mysqli://root:password@mysql:3306/identity?persistent=1"
APP_IDENTITY_DOCTRINE_DBAL_URL: "mysqli://root:password@localhost/identity?persistent=1&unix_socket=/var/run/proxysql/proxysql.sock"
APP_IDENTITY_RUN_MIGRATIONS: "1"
APP_WEB_INTERFACE_PREDIS_CLIENT_URL: "redis://redis:6379?persistent=1"
APP_WEB_INTERFACE_NCHAN_BASE_URL: "http://nchan:81"
depends_on:
- mysql
- proxysql
- redis
- rabbit-mq
- nchan
volumes:
- proxysql.sock:/var/run/proxysql
restart: on-failure

services:
Expand Down Expand Up @@ -85,6 +88,35 @@ services:
labels:
- "prometheus-job=mysql"
- "prometheus-port=9104"
proxysql:
image: marein/php-gaming-website:proxysql
environment:
PROXYSQL_CONFIG: |
admin_variables: {
restapi_enabled="true"
}
mysql_variables: {
interfaces="/var/run/proxysql/proxysql.sock"
server_version="8.0"
monitor_username="root"
monitor_password="password"
auto_increment_delay_multiplex=0
}
mysql_servers: (
{hostgroup=1,address="mysql",port=3306,max_connections=100}
)
mysql_users: (
{username="root",password="password",default_hostgroup=1}
)
depends_on:
- mysql
volumes:
- proxysql.sock:/var/run/proxysql
labels:
- "prometheus-job=proxysql"
- "prometheus-port=6070"
- "prometheus-path=/metrics"
restart: on-failure
redis:
image: marein/php-gaming-website:redis
command: redis-server --appendonly yes
Expand Down Expand Up @@ -155,6 +187,7 @@ services:

volumes:
mysql:
proxysql.sock:
redis:
rabbit-mq:
prometheus:
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ x-php-container:
env_file: ./.env
depends_on:
- mysql
- proxysql
- redis
- rabbit-mq
- nchan
volumes:
- ./config:/project/config:delegated
- ./src:/project/src:delegated
- vendor:/project/vendor
- proxysql.sock:/var/run/proxysql
restart: on-failure

services:
Expand Down Expand Up @@ -86,6 +88,37 @@ services:
labels:
- "prometheus-job=mysql"
- "prometheus-port=9104"
proxysql:
build:
context: .
dockerfile: ./docker/proxysql/Dockerfile
environment:
PROXYSQL_CONFIG: |
admin_variables: {
restapi_enabled="true"
}
mysql_variables: {
interfaces="/var/run/proxysql/proxysql.sock"
server_version="8.0"
monitor_username="root"
monitor_password="password"
auto_increment_delay_multiplex=0
}
mysql_servers: (
{hostgroup=1,address="mysql",port=3306,max_connections=100}
)
mysql_users: (
{username="root",password="password",default_hostgroup=1}
)
depends_on:
- mysql
volumes:
- proxysql.sock:/var/run/proxysql
labels:
- "prometheus-job=proxysql"
- "prometheus-port=6070"
- "prometheus-path=/metrics"
restart: on-failure
redis:
build:
context: .
Expand Down Expand Up @@ -142,6 +175,7 @@ services:
- ./var:/project/var:delegated
- ./web:/project/web:delegated
- vendor:/project/vendor
- proxysql.sock:/var/run/proxysql
labels:
- "traefik.enable=true"
- "traefik.http.routers.php-fpm.priority=10"
Expand Down Expand Up @@ -213,6 +247,7 @@ services:
volumes:
vendor:
mysql:
proxysql.sock:
redis:
rabbit-mq:
prometheus:
Loading

0 comments on commit 7f5ebe2

Please sign in to comment.