Skip to content

Instantly share code, notes, and snippets.

@TPXP
Last active June 9, 2025 19:38
Show Gist options
  • Save TPXP/598c9135a57e957dea2cf8b495a61562 to your computer and use it in GitHub Desktop.
Save TPXP/598c9135a57e957dea2cf8b495a61562 to your computer and use it in GitHub Desktop.
ProxySQL overflow queries test
services:
db_1:
image: postgres:17
command: postgres -c log_min_duration_statement=0 -c log_statement=all
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
db_2:
image: postgres:17
command: postgres -c log_min_duration_statement=0 -c log_statement=all
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
proxysql:
build: .
# image: proxysql/proxysql:3.0.1
depends_on:
- db_1
- db_2
volumes:
- ./proxysql.cnf:/etc/proxysql.cnf
ports:
- 8443:8443
- 8080:8080
healthcheck:
test: ["CMD", "bash", "-c", "mysqladmin ping -h localhost -P 6032 -u admin -padmin --skip-ssl"]
interval: 5s
timeout: 3s
retries: 10
node:
image: node:22
# $$ = escape for docker-compose to pass the variable to the container
entrypoint: ["bash", "-c", "echo 'ready'; trap 'kill $$SLEEP_PID; exit 0' SIGTERM; sleep infinity & SLEEP_PID=$!; wait $$SLEEP_PID"]
working_dir: /app
volumes:
- .:/app
FROM ubuntu:25.04 AS builder
RUN apt-get update && \
apt-get install -y build-essential pkg-config libssl-dev git patch gnutls-dev cmake automake autoconf libicu-dev libtool libevent-dev python3 zlib1g-dev uuid-dev \
&& git clone https://github.com/TPXP/proxysql.git \
&& cd proxysql \
&& git checkout v3.0-backup-srv \
&& make -j10
FROM ubuntu:25.04
RUN apt-get update && \
apt-get install -y zlib1g uuid gnutls-bin mariadb-client && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /var/lib/proxysql
COPY --from=builder /proxysql/src/proxysql /usr/local/bin/proxysql
CMD ["/usr/local/bin/proxysql", "--config", "/etc/proxysql.cnf", "--datadir", "/var/lib/proxysql", "--foreground", "--idle-threads"]
{
"dependencies": {
"pg": "^8.16.0"
}
}
datadir="/var/lib/proxysql"
admin_variables=
{
admin_credentials="admin:admin"
mysql_ifaces="127.0.0.1:6033"
web_enabled=false
restapi_enabled=false
}
pgsql_variables=
{
threads=10
max_connections=2048
default_query_delay=0
default_query_timeout=36000000
have_compress=true
interfaces="0.0.0.0:5432"
multiplexing=true
monitor_enabled=false
}
pgsql_users:
(
{
username = "user"
password = "password"
default_hostgroup = 10
frontend = 1
backend = 1
}
)
pgsql_servers:
(
{
hostgroup_id = 10
hostname = "db_1"
port = 5432
status = "ONLINE"
weight = 1
max_connections = 5
},
{
hostgroup_id = 10
hostname = "db_2"
port = 5432
status = "ONLINE"
# Don't pick this server unless we've reached max_connections
weight = 0
max_connections = 10000
}
)
// Run multiple tests: with 5, 20 and 5 workers again to make sure we don't mess up with the object in memory
const NUM_WORKERS = 20;
const { Pool } = require('pg');
const pool = new Pool({
host: 'proxysql',
port: 5432,
user: 'user',
password: 'password',
max: 20,
database: 'postgres',
});
async function worker() {
// Acquire a client from the pool
const client = await pool.connect();
const start = Date.now();
await client.query('SELECT pg_sleep(2)');
// Release the client back to the pool - don't forget this step!
console.log(`Worker finished after ${Date.now() - start} ms`);
client.release();
}
(async function() {
const promises = [];
for (let i = 0; i < NUM_WORKERS; i++) {
promises.push(worker());
}
await Promise.all(promises);
console.log('All done!');
// Shut down cleanly
await pool.end();
})();
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
pg-cloudflare@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/pg-cloudflare/-/pg-cloudflare-1.2.5.tgz#2e3649c38a7a9c74a7e5327c8098a2fd9af595bd"
integrity sha512-OOX22Vt0vOSRrdoUPKJ8Wi2OpE/o/h9T8X1s4qSkCedbNah9ei2W2765be8iMVxQUsvgT7zIAT2eIa9fs5+vtg==
pg-connection-string@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.9.0.tgz#f75e06591fdd42ec7636fe2c6a03febeedbec9bf"
integrity sha512-P2DEBKuvh5RClafLngkAuGe9OUlFV7ebu8w1kmaaOgPcpJd1RIFh7otETfI6hAR8YupOLFTY7nuvvIn7PLciUQ==
pg-int8@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
pg-pool@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.10.0.tgz#134b0213755c5e7135152976488aa7cd7ee1268d"
integrity sha512-DzZ26On4sQ0KmqnO34muPcmKbhrjmyiO4lCCR0VwEd7MjmiKf5NTg/6+apUEu0NF7ESa37CGzFxH513CoUmWnA==
pg-protocol@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.10.0.tgz#a473afcbb1c6e5dc3ac24869ba3dd563f8a1ae1b"
integrity sha512-IpdytjudNuLv8nhlHs/UrVBhU0e78J0oIS/0AVdTbWxSOkFUVdsHC/NrorO6nXsQNDTT1kzDSOMJubBQviX18Q==
pg-types@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3"
integrity sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==
dependencies:
pg-int8 "1.0.1"
postgres-array "~2.0.0"
postgres-bytea "~1.0.0"
postgres-date "~1.0.4"
postgres-interval "^1.1.0"
pg@^8.16.0:
version "8.16.0"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.16.0.tgz#40b08eedb5eb1834252cf3e3629503e32e6c6c04"
integrity sha512-7SKfdvP8CTNXjMUzfcVTaI+TDzBEeaUnVwiVGZQD1Hh33Kpev7liQba9uLd4CfN8r9mCVsD0JIpq03+Unpz+kg==
dependencies:
pg-connection-string "^2.9.0"
pg-pool "^3.10.0"
pg-protocol "^1.10.0"
pg-types "2.2.0"
pgpass "1.0.5"
optionalDependencies:
pg-cloudflare "^1.2.5"
pgpass@1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d"
integrity sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==
dependencies:
split2 "^4.1.0"
postgres-array@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==
postgres-bytea@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
integrity sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==
postgres-date@~1.0.4:
version "1.0.7"
resolved "https://registry.yarnpkg.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==
postgres-interval@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
integrity sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==
dependencies:
xtend "^4.0.0"
split2@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/split2/-/split2-4.2.0.tgz#c9c5920904d148bab0b9f67145f245a86aadbfa4"
integrity sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==
xtend@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment