Caveats
- PostgREST performance worsen with more than 16 CPU cores. To be safe, you should use 8-16 threads or less by setting
GHCRTS="-N<x>"in environment variables and run multiple instances to sustain high throughput. (This may have improved lately.)
The numbers still donāt improve on 32, 48, 64 cores but now they maintain. Also not sure if thereās something else wrong with my benchmark setup in those. https://github.com/PostgREST/postgrest/issues/2294
-N āØxā©. Use āØxā© simultaneous threads when running the program. https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-concurrent.html#rts-flag-N-x
diff --git a/app/supabase/docker-compose.yml b/app/supabase/docker-compose.yml
index e46ba4a8..f393d22b 100644
--- a/app/supabase/docker-compose.yml
+++ b/app/supabase/docker-compose.yml
@@ -77,6 +77,8 @@ services:
environment:
KONG_DATABASE: "off"
KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml
+ KONG_DNS_VALID_TTL: 10
+ KONG_DNS_STALE_TTL: 3600
# https://github.com/supabase/cli/issues/14
KONG_DNS_ORDER: LAST,A,CNAME
KONG_PLUGINS: request-transformer,cors,key-auth,acl,basic-auth,request-termination,ip-restriction
@@ -161,13 +163,15 @@ services:
#--------------------------------------------------------------#
# https://supabase.com/docs/guides/getting-started/architecture#postgrest-api
rest:
- container_name: supabase-rest
image: postgrest/postgrest:v13.0.7
restart: unless-stopped
+ deploy:
+ replicas: 3
depends_on:
analytics:
condition: service_healthy
environment:
+ GHCRTS: "-N8"
PGRST_DB_URI: postgres://authenticator:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
PGRST_DB_SCHEMAS: ${PGRST_DB_SCHEMAS}
PGRST_DB_ANON_ROLE: anon
diff --git a/app/supabase/volumes/api/kong.yml b/app/supabase/volumes/api/kong.yml
index 673aa6db..2bd28ddc 100644
--- a/app/supabase/volumes/api/kong.yml
+++ b/app/supabase/volumes/api/kong.yml
@@ -30,6 +30,16 @@ basicauth_credentials:
username: $DASHBOARD_USERNAME
password: $DASHBOARD_PASSWORD
+###
+### Upstreams for load balancing
+###
+upstreams:
+ - name: rest-upstream
+ algorithm: least-connections
+ targets:
+ - target: rest:3000
+ weight: 100
+
###
### API Routes
###
@@ -87,7 +97,7 @@ services:
## Secure REST routes
- name: rest-v1
_comment: 'PostgREST: /rest/v1/* -> http://rest:3000/*'
- url: http://rest:3000/
+ url: http://rest-upstream/
routes:
- name: rest-v1-all
strip_path: true
@@ -108,7 +118,7 @@ services:
## Secure GraphQL routes
- name: graphql-v1
_comment: 'PostgREST: /graphql/v1/* -> http://rest:3000/rpc/graphql'
- url: http://rest:3000/rpc/graphql
+ url: http://rest-upstream/rpc/graphql
routes:
- name: graphql-v1-all
strip_path: true
@@ -280,4 +290,4 @@ services:
- name: cors
- name: basic-auth
config:
- hide_credentials: true
\ No newline at end of file
+ hide_credentials: true
- PostgRESTās
db-pool(PGRST_DB_POOL) size defaults to 10, which should be increased as necessary per https://docs.postgrest.org/en/v12/references/connection_pool.html#acquisition-timeout. - supabase/storage is written in Node.js and can only saturate 1 CPU core. You need multiple if it becomes a bottleneck.
- In high throughput scenarios with 10,000 or more RPS, you may need to increase connection reuse in Kong as documented in https://developer.konghq.com/gateway/performance/optimize/.
- Publishable and secret keys are only available on the Supabase hosted platform. https://supabase.com/docs/guides/api/api-keys
Setup process
Based on v3.6.1:
[Download] ===========================================
[ OK ] version = v3.6.1 (from default)
curl -fSL https://repo.pigsty.io/src/pigsty-v3.6.1.tgz -o /tmp/pigsty-v3.6.1.tgz
################################################################################ 100.0%
[ OK ] md5sums = 083d8680fa48e9fec3c3fcf481d25d2f /tmp/pigsty-v3.6.1.tgz
[Install] ===========================================
[ OK ] install = /home/ubuntu/pigsty, from /tmp/pigsty-v3.6.1.tgz
bash get
cd ~/pigsty
./configure -c supabase
patch -p1 < ...- Remove vector container in Supabase self-hosted docker compose stack. You should collect logs elsewhere.
- Preferably also remove the
analyticscontainer to save yourself from thesupa-kickcron job.
- Preferably also remove the
- Remove unused
timescaledbextension. - Disable
promtailandloki. (Now VictoriaLogs and Vector in v4.0) - Leave DNS alone with
node_dns_method: none. Supabase has its hosts entries set in Docker specs.- And
/etc/hostswithnode_write_etc_hosts: falseif you donāt need to self-host MinIO.
- And
- Comment out PKI files in
.gitignoreto manage them via Git.