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,
|
HieroAccountId,
|
||||||
InMemoryBlockchain,
|
InMemoryBlockchain,
|
||||||
LedgerAnchor,
|
LedgerAnchor,
|
||||||
|
Profiler,
|
||||||
} from 'gradido-blockchain-js'
|
} from 'gradido-blockchain-js'
|
||||||
import { NotEnoughGradidoBalanceError } from './errors'
|
import { NotEnoughGradidoBalanceError } from './errors'
|
||||||
|
|
||||||
export const defaultHieroAccount = new HieroAccountId(0, 0, 2)
|
export const defaultHieroAccount = new HieroAccountId(0, 0, 2)
|
||||||
|
export let callTime: number = 0
|
||||||
|
const timeUsed = new Profiler
|
||||||
|
|
||||||
export function addToBlockchain(
|
export function addToBlockchain(
|
||||||
transaction: GradidoTransaction,
|
transaction: GradidoTransaction,
|
||||||
@ -18,11 +21,13 @@ export function addToBlockchain(
|
|||||||
): boolean {
|
): boolean {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
timeUsed.reset()
|
||||||
const result = blockchain.createAndAddConfirmedTransactionExtern(
|
const result = blockchain.createAndAddConfirmedTransactionExtern(
|
||||||
transaction,
|
transaction,
|
||||||
ledgerAnchor,
|
ledgerAnchor,
|
||||||
accountBalances,
|
accountBalances,
|
||||||
)
|
)
|
||||||
|
callTime += timeUsed.nanos()
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
|||||||
@ -11,6 +11,8 @@ export type IndexType = {
|
|||||||
date: Date
|
date: Date
|
||||||
id: number
|
id: number
|
||||||
}
|
}
|
||||||
|
export let nanosBalanceForUser = 0
|
||||||
|
const lastBalanceOfUserTimeUsed = new Profiler
|
||||||
|
|
||||||
export abstract class AbstractSyncRole<ItemType> {
|
export abstract class AbstractSyncRole<ItemType> {
|
||||||
private items: ItemType[] = []
|
private items: ItemType[] = []
|
||||||
@ -31,9 +33,10 @@ export abstract class AbstractSyncRole<ItemType> {
|
|||||||
|
|
||||||
getLastBalanceForUser(publicKey: MemoryBlockPtr, blockchain: InMemoryBlockchain, communityId: string
|
getLastBalanceForUser(publicKey: MemoryBlockPtr, blockchain: InMemoryBlockchain, communityId: string
|
||||||
): Balance {
|
): Balance {
|
||||||
|
lastBalanceOfUserTimeUsed.reset()
|
||||||
if (publicKey.isEmpty()) {
|
if (publicKey.isEmpty()) {
|
||||||
throw new Error('publicKey is empty')
|
throw new Error('publicKey is empty')
|
||||||
}
|
}
|
||||||
const lastSenderTransaction = blockchain.findOne(Filter.lastBalanceFor(publicKey))
|
const lastSenderTransaction = blockchain.findOne(Filter.lastBalanceFor(publicKey))
|
||||||
if (!lastSenderTransaction) {
|
if (!lastSenderTransaction) {
|
||||||
return new Balance(publicKey, communityId)
|
return new Balance(publicKey, communityId)
|
||||||
@ -46,7 +49,9 @@ export abstract class AbstractSyncRole<ItemType> {
|
|||||||
if (!senderLastAccountBalance) {
|
if (!senderLastAccountBalance) {
|
||||||
return new Balance(publicKey, communityId)
|
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) {
|
logLastBalanceChangingTransactions(publicKey: MemoryBlockPtr, blockchain: InMemoryBlockchain, transactionCount: number = 5) {
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import { RedeemTransactionLinksSyncRole } from './RedeemTransactionLinksSync.rol
|
|||||||
import { ContributionLinkTransactionSyncRole } from './ContributionLinkTransactionSync.role'
|
import { ContributionLinkTransactionSyncRole } from './ContributionLinkTransactionSync.role'
|
||||||
import { DeletedTransactionLinksSyncRole } from './DeletedTransactionLinksSync.role'
|
import { DeletedTransactionLinksSyncRole } from './DeletedTransactionLinksSync.role'
|
||||||
import { RemoteTransactionsSyncRole } from './RemoteTransactionsSync.role'
|
import { RemoteTransactionsSyncRole } from './RemoteTransactionsSync.role'
|
||||||
|
import { callTime } from '../../blockchain'
|
||||||
|
import { nanosBalanceForUser } from './AbstractSync.role'
|
||||||
|
|
||||||
export async function syncDbWithBlockchainContext(context: Context, batchSize: number) {
|
export async function syncDbWithBlockchainContext(context: Context, batchSize: number) {
|
||||||
const timeUsedDB = new Profiler()
|
const timeUsedDB = new Profiler()
|
||||||
@ -28,6 +30,7 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n
|
|||||||
let transactionsCountSinceLastPrint = 0
|
let transactionsCountSinceLastPrint = 0
|
||||||
let available = containers
|
let available = containers
|
||||||
const isDebug = context.logger.isDebugEnabled()
|
const isDebug = context.logger.isDebugEnabled()
|
||||||
|
let lastPrintedCallTime = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
timeUsedDB.reset()
|
timeUsedDB.reset()
|
||||||
const results = await Promise.all(available.map((c) => c.ensureFilled(batchSize)))
|
const results = await Promise.all(available.map((c) => c.ensureFilled(batchSize)))
|
||||||
@ -56,6 +59,8 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n
|
|||||||
transactionsCountSinceLastLog++
|
transactionsCountSinceLastLog++
|
||||||
if (transactionsCountSinceLastLog >= batchSize) {
|
if (transactionsCountSinceLastLog >= batchSize) {
|
||||||
context.logger.debug(`${transactionsCountSinceLastLog} transactions added to blockchain in ${timeUsedBlockchain.string()}`)
|
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()
|
timeUsedBlockchain.reset()
|
||||||
transactionsCountSinceLastLog = 0
|
transactionsCountSinceLastLog = 0
|
||||||
}
|
}
|
||||||
@ -69,4 +74,6 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n
|
|||||||
}
|
}
|
||||||
process.stdout.write(`successfully added to blockchain: ${transactionsCount}\n`)
|
process.stdout.write(`successfully added to blockchain: ${transactionsCount}\n`)
|
||||||
context.logger.info(`Synced ${transactionsCount} transactions to blockchain in ${timeUsedAll.string()}`)
|
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