Skip to content

Commit

Permalink
Adds duration to repostore logs for getBlock and putBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
benbierens committed Jan 13, 2025
1 parent 0cffa02 commit 35a93cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-dist-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
name: Build and Push
uses: ./.github/workflows/docker-reusable.yml
with:
nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_enable_log_counter=true -d:verify_circuit=true'
nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_enable_log_counter=true -d:verify_circuit=true -d:codex_enable_repostore_timinglogs=true'
nat_ip_auto: true
tag_latest: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }}
tag_suffix: dist-tests
Expand Down
23 changes: 22 additions & 1 deletion codex/stores/repostore/store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import ../../logutils
import ../../merkletree
import ../../utils

const
codex_enable_repostore_timinglogs* {.booldefine.} = false

when codex_enable_repostore_timinglogs:
import std/monotimes

export blocktype, cid

logScope:
Expand All @@ -51,14 +57,22 @@ method getBlock*(self: RepoStore, cid: Cid): Future[?!Block] {.async.} =
trace "Error getting key from provider", err = err.msg
return failure(err)

when codex_enable_repostore_timinglogs:
let startTime = getMonoTime().ticks

Check warning on line 62 in codex/stores/repostore/store.nim

View check run for this annotation

Codecov / codecov/patch

codex/stores/repostore/store.nim#L61-L62

Added lines #L61 - L62 were not covered by tests
without data =? await self.repoDs.get(key), err:
if not (err of DatastoreKeyNotFound):
trace "Error getting block from datastore", err = err.msg, key
return failure(err)

return failure(newException(BlockNotFoundError, err.msg))

trace "Got block for cid", cid
when codex_enable_repostore_timinglogs:
let durationUs = (getMonoTime().ticks - startTime) div 1000

Check warning on line 71 in codex/stores/repostore/store.nim

View check run for this annotation

Codecov / codecov/patch

codex/stores/repostore/store.nim#L70-L71

Added lines #L70 - L71 were not covered by tests
trace "Got block for cid", cid, durationUs
else:

Check warning on line 73 in codex/stores/repostore/store.nim

View check run for this annotation

Codecov / codecov/patch

codex/stores/repostore/store.nim#L73

Added line #L73 was not covered by tests
trace "Got block for cid", cid

return Block.new(cid, data, verify = true)

method getBlockAndProof*(self: RepoStore, treeCid: Cid, index: Natural): Future[?!(Block, CodexProof)] {.async.} =
Expand Down Expand Up @@ -176,6 +190,9 @@ method putBlock*(

let expiry = self.clock.now() + (ttl |? self.blockTtl).seconds

when codex_enable_repostore_timinglogs:
let startTime = getMonoTime().ticks

without res =? await self.storeBlock(blk, expiry), err:
return failure(err)

Expand All @@ -195,6 +212,10 @@ method putBlock*(
else:
trace "Block already exists"

when codex_enable_repostore_timinglogs:
let durationUs = (getMonoTime().ticks - startTime) div 1000
trace "putBlock", durationUs

return success()

method delBlock*(self: RepoStore, cid: Cid): Future[?!void] {.async.} =
Expand Down

0 comments on commit 35a93cc

Please sign in to comment.