hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
313 stars 136 forks source link

Learner virtual tree view processes teacher responses in a too synchronized manner #14067

Closed artemananiev closed 3 months ago

artemananiev commented 4 months ago

This is a part of https://github.com/hashgraph/hedera-services/issues/12108 and a follow-up for https://github.com/hashgraph/hedera-services/issues/13898.

After #13898 is implemented, the next bottleneck is on the learner side, this method in LearnerPullVirtualTreeView:

synchronized void responseReceived(final PullVirtualTreeResponse response) {}

There are many threads receiving responses from the teacher, but all of them in the end call the method above. Since the method is synchronized, all threads get stuck waiting to acquire the monitor.

The primary reason this method is synchronized is because it iterates over unsynchronized collections like responses or anticipatedPaths. This is needed to re-order teacher responses, so they are processed in the same order as they were originally sent by the learner. The order is not critical for internal nodes, but when it comes to leaves, they must be processed in ascending path order, this is the current restriction of virtual hasher.

A solution could be to change the method above to be not synchronized, and move leaf path ordering code to dirty leaf iterator. This is the iterator that supplies leaves to virtual hasher.

artemananiev commented 3 months ago

Changes are in the 12108-D-reconnect-parallel-vmaps branch, no more work is planned for this task.