bestinslot-xyz / OPI

Open Protocol Indexer, OPI, is the best-in-slot open-source indexing client for meta-protocols on Bitcoin.
Apache License 2.0
202 stars 110 forks source link

Add `DB_MAX_CONNECTIONS` env variable #1

Closed t4t5 closed 10 months ago

t4t5 commented 10 months ago

When running the main index module, I quickly ran into the following Postgres error: Sorry, too many clients already!

It probably makes sense to let the user decide how many concurrent connections their database can handle! 👍

decentraliser commented 10 months ago

The root cause seems to be with the promise_limit variable. Tweaking DB_MAX_CONNECTIONS didn't do the job, and I managed to have the indexer run by lowering this variable.

https://github.com/bestinslot-xyz/OPI/blob/main/modules/main_index/index.js#L22

samedcildir commented 10 months ago

@t4t5 Adding DB_MAX_CONNECTIONS makes sense 👍 can you also add the same variable to brc20_api and bitmap_api since they'll also complain about this if there are a lot of simultaneous requests made to the API

@decentraliser promise_limit shouldn't cause a database problem since pg pool will limit and wait after max connections has been reached. However, it may cause some problems if you don't have enough memory and lowering it should help in that case.

t4t5 commented 10 months ago

@t4t5 Adding DB_MAX_CONNECTIONS makes sense 👍 can you also add the same variable to brc20_api and bitmap_api since they'll also complain about this if there are a lot of simultaneous requests made to the API

Added!