This is an example repository to provide a stress test the following features of Supabase:
The aim of these tests are to determine the scale of using Jobs with Supabase in production. The tests have been split into 3 scenarios but they contain the same core concept: make a POST request to an endpoint on a minutely basis.
You need an endpoint to test against. We recommend using Upstash Redis as it provides a REST API and allows you to store logic. When you create your Redis on Upstash, you will need to save the following:
UPSTASH_REDIS_REST_TOKENUPSTASH_REDIS_REST_URLto your database Vault.
Add them to your .env files using dotenvx
npx @dotenvx/dotenvx set UPSTASH_REDIS_REST_TOKEN "Bearer TOKEN" -f supabase/.env.production- In
config.tomladdupstash_redis_rest_token = "env(UPSTASH_REDIS_REST_TOKEN)"under thedb.vaultsection
npx @dotenvx/dotenvx set UPSTASH_REDIS_REST_TOKEN "Bearer TOKEN" -f supabase/.env.preview- In
config.tomladdUPSTASH_REDIS_REST_TOKEN = "env(UPSTASH_REDIS_REST_TOKEN)"under theedge_runtime.secretssection
Now you can run npx supabase@latest secrets set --env-file supabase/env.keys
Using the Cron integration, configure 1000 jobs to make a request to an endpoint every minute (where X is the number of jobs you want to run simultaneously)
The job is configured to call the Upstash endpoint directly with the Authorization header providing the UPSTASH_REDIS_REST_TOKEN.
Using the Cron integration, configure 1000 jobs to call an Edge Function every minute
The job is configured to call an Edge Function with the Authorization header. The Edge Function invoked is the redis-counter function that makes a call to Upstash and needs the same secrets as above in your Edge Functions.
Using the Cron integration, configure a job to call an Edge Function every minute that chains to call X Edge Functions as background tasks
This job is configured to call an Edge Function. The Edge Function invoked is the (main-chain)[supacron/supabase/functions/main-chain/index.ts] which invokes 1000 Edge Functions to make calls to Upstash.
This repo uses two extensions and the monitoring of each of these can be done in their own schemas
The cron schema has two tables:
jobs- This is all of the configured jobs forpg_cronto run, their frequency and the action they takejob_run_details- This contains the outcome of all of the jobs that have been executed bypg_cron
The net schema has two tables:
_http_response- This contains responses from calls made bypg_netin the last 6 hourshttp_request_queue- This contains the queue of requests waiting to be made bypg_net
- You can customize some Postgres settings, such as
max_parallel_workersusing the Supabase CLI - Testing different values of X
- Running on different instance sizes
There are multiple ways to run through these scenarios.
Using the scripts folder, you can apply each scenario using psql, running for a period of time and then stopping it with drop_jobs.sql. For example:
- `psql "$CONN_STRING" -f scripts/2_many_crons_one_function.sql`
- leave to run for X minutes
- `psql "$CONN_STRING" -f scripts/drop_jobs.sql`
- `psql "$CONN_STRING" -f scripts/get_job_details.sql`
Each scenario can be created as a separate branch within a Supabase project. Follow the Branching guide first and integrate with your github repo. For each branch, you will then need to add the scenario script as a migration. For example:
- `git checkout -b scenario/many_crons`
- `supabase migrations new many_crons`
- copy `scripts/1_many_crons.sql` into the new migration file
- commit the file and push, then open a new PR
- repeeat for each scenario and close the PRs when the tests are run.