blockfrost / blockfrost-bootstrap

Blockfrost bootstrap is a toolkit that helps you to deploy a Blockfrost cluster in minutes.
https://blockfrost.io/
GNU General Public License v3.0
4 stars 0 forks source link

Slow responese on /assets/{asset}/addresses endpoint. #3

Open Naiglos opened 1 year ago

Naiglos commented 1 year ago

Problem Description

Querying /assets/{asset}/addresses endpoint response time ranges form 7 to 35 seconds.

curl -w "@curl-format.txt" -o /dev/null -s "http://localhost:3000/assets/{$asset}/addresses"
     time_namelookup:  0.000014s
        time_connect:  0.032365s
     time_appconnect:  0.000000s
    time_pretransfer:  0.032393s
       time_redirect:  0.000000s
  time_starttransfer:  31.020171s
                     ----------
          time_total:  31.020421s

Environment

Hardware

Software

Applications version

Applications specific settings

  1. Directly executed query form source code got same result.
  2. Executed query using EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) Can be viewed here
sorki commented 1 year ago

Hi, thanks for the report!

Recent dbsync (13.1+) dropped some indices that affect our queries - you can (re)create these manually based on https://github.com/input-output-hk/cardano-db-sync/issues/1349#issuecomment-1416017488 and it should fix the sequential scan affecting this query.

Naiglos commented 1 year ago

Hello, thank you for your suggestion. I created indices mentioned in linked comment. Somehow, it got worse. Now it can hover between 47 and 189 seconds.

Once again i executed query directly with EXPLAIN:

in the meantime here some steps i took but without success:

  1. Rebooting server
  2. Running VACUUM ANALYZE and VACUUM
  3. Running VACUUM FULL and REINDEX on the tables involved in query.
mmahut commented 1 year ago

This is almost certainly due to low resources for the database. The 64GB is the bare minimum, try to increase it and play with the postgresql settings, that query is on a pretty large dataset and is probably doing the best it can.

That being said, if you find a way to optimize it, a PR is most certainly welcome!

Naiglos commented 1 year ago

Hello, I actually did some additional testing. @mmahut you where absolutely right about resource constrain. It turns out asset used for testing indeed contains abnormally large amount addresses compared to other assets. With other assets performance has increased dramatically, from 7sec to ~130ms.

Can I suggest adding those indices to README instructions? It could be a life-saver for some. And about resource estimation it could come in useful to have recommanded hardware spec listed per component .

Thank you for your time.

klntsky commented 1 year ago

Would it be possible to automate creation of these indexes on the Blockfrost side?

mmahut commented 6 months ago

Would it be possible to automate creation of these indexes on the Blockfrost side?

Yes, that's a good idea. We should add it to blockfrost-bootstrap.