mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
add more profiling
This commit is contained in:
parent
473d8139e8
commit
7fe7f4cb11
@ -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) {
|
||||
|
||||
@ -11,6 +11,8 @@ export type IndexType = {
|
||||
date: Date
|
||||
id: number
|
||||
}
|
||||
export let nanosBalanceForUser = 0
|
||||
const lastBalanceOfUserTimeUsed = new Profiler
|
||||
|
||||
export abstract class AbstractSyncRole<ItemType> {
|
||||
private items: ItemType[] = []
|
||||
@ -31,9 +33,10 @@ export abstract class AbstractSyncRole<ItemType> {
|
||||
|
||||
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<ItemType> {
|
||||
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) {
|
||||
|
||||
@ -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`)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user