Skip to content

Reduce number of DB reads and writes #437

@Shimuuar

Description

@Shimuuar

Here are number of DB queries made in semi-realistic setting (4 nodes, H=633)

  79723 "SELECT MAX(height) FROM thm_blockchain"
   9099 "INSERT OR IGNORE INTO thm_wal VALUES (NULL,?,?)"
   5130 "SELECT valset FROM thm_validators WHERE height = ?"
   2193 "SELECT block FROM thm_blockchain WHERE height = ?"
   1660 "SELECT bid FROM thm_blockchain WHERE height = ?"
   1039 "SELECT round FROM thm_blockchain WHERE height = ?"
    633 "SELECT message FROM thm_wal WHERE height = ? ORDER BY id"
    633 "DELETE FROM thm_wal WHERE height < ?"
    632 "INSERT INTO thm_validators VALUES (?,?)"
    632 "INSERT INTO thm_commits VALUES (?,?)"
    632 "INSERT INTO thm_blockchain VALUES (?,?,?,?)"
    310 "SELECT cmt FROM thm_commits WHERE height = ?"

What could we see

  1. Querying blockchain height is largest number of queries by far. But it's very cheap query and relevant data is likely to sit in disk cache anyway
  2. Second is writing of WAL and if . We write about 14 messages per height. Absolute minimum is StepNewHeight + 1 propose + 4 prevotes + 4 precommits. There's not much we can do except
  1. Third is block requests. Luckily caching of block could be implemented in relatively straightforward manner thanks to BCH immutability

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions