From 7fe7f4cb11a87187d607f67ee295a4ebcdadab8f Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Sun, 25 Jan 2026 12:43:36 +0100 Subject: [PATCH] add more profiling --- .../db-v2.7.0_to_blockchain-v3.7/blockchain.ts | 5 +++++ .../syncDbWithBlockchain/AbstractSync.role.ts | 9 +++++++-- .../syncDbWithBlockchain/syncDbWithBlockchain.context.ts | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/blockchain.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/blockchain.ts index fd70dcca6..ffff61f1a 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/blockchain.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/blockchain.ts @@ -5,10 +5,13 @@ import { HieroAccountId, InMemoryBlockchain, LedgerAnchor, + Profiler, } from 'gradido-blockchain-js' import { NotEnoughGradidoBalanceError } from './errors' export const defaultHieroAccount = new HieroAccountId(0, 0, 2) +export let callTime: number = 0 +const timeUsed = new Profiler export function addToBlockchain( transaction: GradidoTransaction, @@ -18,11 +21,13 @@ export function addToBlockchain( ): boolean { try { + timeUsed.reset() const result = blockchain.createAndAddConfirmedTransactionExtern( transaction, ledgerAnchor, accountBalances, ) + callTime += timeUsed.nanos() return result } catch (error) { if (error instanceof Error) { diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/AbstractSync.role.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/AbstractSync.role.ts index 443c68b4a..bcdc133b5 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/AbstractSync.role.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/AbstractSync.role.ts @@ -11,6 +11,8 @@ export type IndexType = { date: Date id: number } +export let nanosBalanceForUser = 0 +const lastBalanceOfUserTimeUsed = new Profiler export abstract class AbstractSyncRole { private items: ItemType[] = [] @@ -31,9 +33,10 @@ export abstract class AbstractSyncRole { getLastBalanceForUser(publicKey: MemoryBlockPtr, blockchain: InMemoryBlockchain, communityId: string ): Balance { + lastBalanceOfUserTimeUsed.reset() if (publicKey.isEmpty()) { throw new Error('publicKey is empty') - } + } const lastSenderTransaction = blockchain.findOne(Filter.lastBalanceFor(publicKey)) if (!lastSenderTransaction) { return new Balance(publicKey, communityId) @@ -46,7 +49,9 @@ export abstract class AbstractSyncRole { if (!senderLastAccountBalance) { return new Balance(publicKey, communityId) } - return Balance.fromAccountBalance(senderLastAccountBalance, lastConfirmedTransaction.getConfirmedAt().getDate(), communityId) + const result = Balance.fromAccountBalance(senderLastAccountBalance, lastConfirmedTransaction.getConfirmedAt().getDate(), communityId) + nanosBalanceForUser += lastBalanceOfUserTimeUsed.nanos() + return result } logLastBalanceChangingTransactions(publicKey: MemoryBlockPtr, blockchain: InMemoryBlockchain, transactionCount: number = 5) { diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/syncDbWithBlockchain.context.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/syncDbWithBlockchain.context.ts index 8bc3b5a0b..6446e2600 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/syncDbWithBlockchain.context.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.7/interaction/syncDbWithBlockchain/syncDbWithBlockchain.context.ts @@ -8,6 +8,8 @@ import { RedeemTransactionLinksSyncRole } from './RedeemTransactionLinksSync.rol import { ContributionLinkTransactionSyncRole } from './ContributionLinkTransactionSync.role' import { DeletedTransactionLinksSyncRole } from './DeletedTransactionLinksSync.role' import { RemoteTransactionsSyncRole } from './RemoteTransactionsSync.role' +import { callTime } from '../../blockchain' +import { nanosBalanceForUser } from './AbstractSync.role' export async function syncDbWithBlockchainContext(context: Context, batchSize: number) { const timeUsedDB = new Profiler() @@ -28,6 +30,7 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n let transactionsCountSinceLastPrint = 0 let available = containers const isDebug = context.logger.isDebugEnabled() + let lastPrintedCallTime = 0 while (true) { timeUsedDB.reset() const results = await Promise.all(available.map((c) => c.ensureFilled(batchSize))) @@ -56,6 +59,8 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n transactionsCountSinceLastLog++ if (transactionsCountSinceLastLog >= batchSize) { context.logger.debug(`${transactionsCountSinceLastLog} transactions added to blockchain in ${timeUsedBlockchain.string()}`) + context.logger.info(`Time for createAndConfirm: ${((callTime - lastPrintedCallTime) / 1000 / 1000).toFixed(2)} milliseconds`) + lastPrintedCallTime = callTime timeUsedBlockchain.reset() transactionsCountSinceLastLog = 0 } @@ -69,4 +74,6 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n } process.stdout.write(`successfully added to blockchain: ${transactionsCount}\n`) context.logger.info(`Synced ${transactionsCount} transactions to blockchain in ${timeUsedAll.string()}`) + context.logger.info(`Time for createAndConfirm: ${(callTime / 1000 / 1000 / 1000).toFixed(2)} seconds`) + context.logger.info(`Time for call lastBalance of user: ${(nanosBalanceForUser / 1000 / 1000 / 1000).toFixed(2)} seconds`) }