tip: 281
title: Optimize the query of database
author: forfreeday@163.com
discussions to: https://github.com/tronprotocol/TIPs/issues/281
status: Final
type: Standards Track
category: Core
created: 2021-06-18
Optimize the performance of underlying database queries and remove query synchronization locks.
Optimize database queries to improve query efficiency. Remove unnecessary locking operations during queries to improve query efficiency for HTTP and RPC.
To locate important performance issues and find that it is possible to query without adding locks without affecting the correctness of the data and significantly improving the database query performance. Also, if locks exist, there is a certain probability of lock contention during HTTP or RPC queries, which affects the processing efficiency of other threads.
- Remove get method query lock 2.Remove has method lock
State-based storage is ultimately operated through the Chainbase class. Lock removal is achieved by removing the synchronized keyword from the get and getUncheck methods of this class.
- The main operation methods of the database, Manager#pushBlock, Manager#generateBlock, Manager#pushTransaction, are all modified by synchronized, so there is no security problem with the operations before each other.
- When calling the database interface to query data, there is no practical significance to add synchronized, because there is no security problem, and the methods of querying data do not use shared data, so there is no need to add synchronized.