Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 3.82 KB

tip-290.md

File metadata and controls

56 lines (41 loc) · 3.82 KB
tip: 290
title: Dynamic store optimization
author: [email protected]
discussions to: https://github.com/tronprotocol/TIPs/issues/290
status: Final
category: Core
created: 2021-07-12

Simple Summary

This TIP is to optimize dynamic store query performance.

Abstract

Through analysis, a lot of time is spent on dynamic store queries during block processing.

A total of 304 blocks were counted, including 36044 transactions, the number of dynamic store queries reached 1119525, and the number of queries hitting the cache was 340416. It can be analyzed through the statistical results that, on average, each transaction requires 1119525/36044 = 31 dynamic store queries, and two-thirds of the queries cannot hit the cache, that is, 20 dynamic store queries for each transaction cannot hit the cache.

In block synchronization, the cost of failing to hit the cache is very high. In the block synchronization logic, after 500 blocks are synchronized, the flash operation will be performed. Before flashing, each block will produce one session (cache). The query logic starts from the outermost cache. If the key is not in the cache, each query needs to be traversed 500 times and then retrieved from the DB.

This article describes the query optimization of the dynamic store.

Motivation

In order to reduce block processing time, improve the performance of the blockchain, increase the TPS, it is necessary to optimize dynamic store query performance.

Implementation

Due to the particularity of the dynamic store, the key of the entire database is limited. You can consider loading all the data of the dynamic store into the first-level cache, so that the performance will rise sharply.

Performance Testing:

block count: 8000, transaction count:903262

Before optimization:

dynamic store query times cache hits cache hit probability
26588491 8582259 32.28%

After optimization:

dynamic store query times cache hits cache hit probability
26588491 26588232 99.999%


Time-consuming comparison of block processing:

Before optimization: total cost Before optimization: average cost After optimization: total cost After optimization: average cost
1476636 184 1085780 135
1399791 174 1066748 133

Before optimization average cost: 179, After optimization average cost: 134 Performance improvement: (179 - 134) / 134 = 33.58%