Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache results in account witness domain #4953

Merged

Conversation

chimp1984
Copy link
Contributor

No description provided.

@chimp1984
Copy link
Contributor Author

chimp1984 commented Dec 15, 2020

Here are results from performance tests (based on live network data):

I used a loop for 5 iterations over each offer. For findWitness 10000 iterations.

Version of that PR:
652 offers. 6520000 calls of accountAgeWitnessService.findWitness(offer) took 783 ms (84% to master)
652 offers. 3260 calls of accountAgeWitnessService.getSignState(accountAgeWitness) took 2063 ms (71% to master)
652 offers. 3260 calls of accountAgeWitnessService.getWitnessSignAge(accountAgeWitness, now) took 4094 ms (78 %to master)
652 offers. 3260 calls of accountAgeWitnessService.getAccountAge(accountAgeWitness, now) took 4094 ms (78% to master)
652 offers. 3260 calls of signedWitnessService.getSignedWitnessSet(accountAgeWitness) took 4095 ms (74% to master)
652 offers. 3260 calls of signedWitnessService.getWitnessDateList(accountAgeWitness) took 4096 ms (70% to master)

Master version:
653 offers. 6530000 calls of accountAgeWitnessService.findWitness(offer) took 924 ms
653 offers. 3265 calls of accountAgeWitnessService.getSignState(accountAgeWitness) took 2873 ms
653 offers. 3265 calls of accountAgeWitnessService.getWitnessSignAge(accountAgeWitness, now) took 5226 ms
653 offers. 3265 calls of accountAgeWitnessService.getAccountAge(accountAgeWitness, now) took 5226 ms
653 offers. 3265 calls of signedWitnessService.getSignedWitnessSet(accountAgeWitness) took 5501 ms
653 offers. 3265 calls of signedWitnessService.getWitnessDateList(accountAgeWitness) took 5788 ms

I expected that the findWitness call is more expensive but seems thats not the bottleneck. So the optimization with accountAgeWitnessCache is prob. not making much difference. Though that is a pretty trivial one.
The optimization with getSignedWitnessSetCache seems to have a bit more impact.

I think it requires further investigations where the bottlenecks are in the tested methods.

Overall that PR brings still about a 20-30% improvement.
There are about 3000-5000 signedWitnessService.getSignedWitnessSet calls with normal user activity after a few minutes which accumulates to about 6-10 sec. cpu time in all.

As its a bit risky domain I have no strong opinion about to merge that PR or close it and delay for a later more broad investigation and improvement. Up to maintainers....

@chimp1984
Copy link
Contributor Author

Seems some Travis issue again: "Could not resolve com.google.api.grpc:proto-google-common-protos:1.12.0." Will force push...

The accountAgeWitnessMap is very large (70k items) and
access is a bit expensive. We usually only access less
than 100 items, those who have offers online. So we
use a cache for a fast lookup and only if
not found there we use the accountAgeWitnessMap and
put then the new item into our cache.
The getSignedWitnessSet is called very often and is a bit
expensive. We cache the result in that map but we
remove the cache entry if we get a matching SignedWitness
added to the signedWitnessMap.
directly and we did not remove the item from the cache)

- Add getSignedWitnessMapValues method for access to signedWitnessMap values
- Remove Getter for signedWitnessMap
- Add removeSignedWitness method (used in test only)
- Use addToMap in test instead of direct access to map
- Remove getSignedWitnessSetCache entry matching
signedWitness.getHashAsByteArray() as well.
See comment. @sqrrm: Can you cross check?
As the normal maps are not using a ConcurrentHashMap it is
likely unnecessary as well that I am not aware of a
multi-threaded access.
But as it does not show any difference in performance
it is likely the bit more safe option.
@chimp1984 chimp1984 force-pushed the cache-results-in-account-witness-domain branch from 71f3671 to f2273e6 Compare December 16, 2020 00:16
@chimp1984
Copy link
Contributor Author

Travis has issues again... happens quite often recently ;-( Will force push...

@ripcurlx ripcurlx requested a review from sqrrm December 16, 2020 18:56
@sqrrm
Copy link
Member

sqrrm commented Dec 20, 2020

@chimp1984 I'm waiting for your fixes before merging

Change comments (after understanding the domain usage better)
Maintain the set at add and remove methods
Use HashMap instead of ConcurrentHashMap as that class is only used
from UserThread and other fields are not threadsafe either.
anymore as we maintain the signedWitnessSetByAccountAgeWitnessHash
at each add/remove operation.
iterations over getSignedWitnessMapValues
Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@chimp1984 did you want to add anything else to this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants