4

I am trying to retrieve the operations for the transactions of a given ledger.

First retrieve the transactions:

   List<TransactionResponse> transactionResponses = this.server.horizonServer()
       .transactions()
       .forLedger(ledger)
       .execute()
       .getRecords();

Then retrieve the operations for each transactions:

 List<OperationResponse> operationResponses = this.server.horizonServer()
     .operations()
     .forTransaction(transactionHash)
     .execute()
     .getRecords();

The second call is one order of magnitude slower than the first one, for example:

[PERFORMANCE] getTransactions (10): 34 ms [PERFORMANCE] getOperations (1): 274 ms [PERFORMANCE] getOperations (1): 353 ms [PERFORMANCE] getOperations (1): 294 ms [PERFORMANCE] getOperations (1): 207 ms [PERFORMANCE] getOperations (1): 307 ms [PERFORMANCE] getOperations (1): 309 ms [PERFORMANCE] getOperations (1): 301 ms [PERFORMANCE] getOperations (1): 304 ms [PERFORMANCE] getOperations (1): 293 ms [PERFORMANCE] getOperations (1): 295 ms

Is there a better way of doings this? We are running our own Stellar node with the official Stellar docker image, so everything (database, stellar-code and horizon) is running locally.

2

My best guess is that your PostgreSQL db works inefficiently with indexes on a large collection. Usually it means that your server has not enough RAM and is unable to keep indexes and cache in memory.

In order to find a bottleneck, you can analyze query performance with built-in PostgreSQL tools.

2

If you need all operations per ledger you can use the Operations for Ledger endpoint. It won't necessarily be more performant per request but should reduce the number of requests you make.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.