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

Optimized peer authentication messages management #4420

Merged
merged 13 commits into from
Sep 1, 2022

Conversation

iulianpascalau
Copy link
Contributor

@iulianpascalau iulianpascalau commented Aug 31, 2022

Description of the reasoning behind the pull request

  • optimized peer authentication messages management by indexing the messages in the pool by their public key. In this way unnecessary get operations are not done on the resolvers.
  • simplified interceptedHeartbeat.go
  • fixed timeCacher implementation to use a put function instead of upsert as to properly override existing values with newer ones
  • removed unnecessary function from peerShardMapper that was previously used just in the peer authentication resolver that was simplified

Proposed Changes

  • code simplification as explained above

Testing procedure

  • standard testing procedure

@iulianpascalau iulianpascalau changed the title - optimized peer authentication messages management Optimized peer authentication messages management Aug 31, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2022

Codecov Report

Merging #4420 (3b74080) into rc/2022-july (8f960bd) will increase coverage by 0.01%.
The diff coverage is 95.08%.

@@               Coverage Diff                @@
##           rc/2022-july    #4420      +/-   ##
================================================
+ Coverage         73.92%   73.94%   +0.01%     
================================================
  Files               677      677              
  Lines             86884    86877       -7     
================================================
+ Hits              64230    64241      +11     
+ Misses            17855    17841      -14     
+ Partials           4799     4795       -4     
Impacted Files Coverage Δ
...esolverscontainer/baseResolversContainerFactory.go 86.72% <ø> (-0.19%) ⬇️
...esolverscontainer/metaResolversContainerFactory.go 82.32% <ø> (-0.09%) ⬇️
...solverscontainer/shardResolversContainerFactory.go 87.87% <ø> (-0.08%) ⬇️
sharding/networksharding/peerShardMapper.go 85.24% <ø> (+0.55%) ⬆️
process/heartbeat/interceptedHeartbeat.go 82.66% <50.00%> (-2.15%) ⬇️
factory/processComponents.go 53.56% <66.66%> (+<0.01%) ⬆️
...aRetriever/resolvers/peerAuthenticationResolver.go 96.34% <100.00%> (+1.04%) ⬆️
epochStart/bootstrap/process.go 85.61% <100.00%> (-0.02%) ⬇️
heartbeat/sender/peerAuthenticationSender.go 92.92% <100.00%> (+0.22%) ⬆️
process/heartbeat/interceptedPeerAuthentication.go 98.50% <100.00%> (+6.02%) ⬆️
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

sstanculeanu
sstanculeanu previously approved these changes Aug 31, 2022
@mariusmihaic mariusmihaic self-requested a review August 31, 2022 17:42
storage/timecache/timeCacheCore.go Outdated Show resolved Hide resolved
storage/timecache/timeCacheCore.go Outdated Show resolved Hide resolved
storage/timecache/timeCacheCore.go Outdated Show resolved Hide resolved
Comment on lines 123 to 126
return
}

return
Copy link
Contributor

Choose a reason for hiding this comment

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

This func always returns nothing. Is this intended?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, could've used logIfError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check that the function has named returned parameters. This is go idiomatic. log.LogIfError does not add sufficient context.
Removed one return, thus

@@ -58,7 +58,7 @@ func (tcc *timeCacheCore) upsert(key string, value interface{}, duration time.Du
}

// put will add the key, value and provided duration, overriding values if the data already existed
// It returns if the value existed before this call. It also operates on the locker so the call is concurrent safe
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe
func (tcc *timeCacheCore) put(key string, value interface{}, duration time.Duration) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have this func return true if the value existed, since in func (tc *timeCacher) Put you always return false and ignore if this one returns true?

Copy link
Contributor Author

@iulianpascalau iulianpascalau Aug 31, 2022

Choose a reason for hiding this comment

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

removed bool & optimized

Copy link
Collaborator

@andreibancioiu andreibancioiu Aug 31, 2022

Choose a reason for hiding this comment

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

timeCacheCore should normally not care about the existence, nor the logic of its caller (timeCacher). Therefore, it's alright to provide the information to the (any) caller - even if that piece of information isn't used.

andreibancioiu
andreibancioiu previously approved these changes Aug 31, 2022
@@ -81,7 +81,7 @@ func (tc *timeCacher) Clear() {

// Put adds a value to the cache. It will always return false since the eviction did not occur
func (tc *timeCacher) Put(key []byte, value interface{}, _ int) (evicted bool) {
_, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan)
_, err := tc.timeCache.put(string(key), value, tc.timeCache.defaultSpan)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So all callers of timeCacher.Put() will receive this fix. Should be only positive impact, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, this was the actual fix, a complete rewrite of the existing data

@@ -115,14 +115,15 @@ func (tc *timeCacher) Peek(key []byte) (value interface{}, ok bool) {
// HasOrAdd checks if a key is in the cache.
// If key exists, does not update the value. Otherwise, adds the key-value in the cache
func (tc *timeCacher) HasOrAdd(key []byte, value interface{}, _ int) (has, added bool) {
existed, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan)
var err error
has, added, err = tc.timeCache.hasOrAdd(string(key), value, tc.timeCache.defaultSpan)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So all callers of timeCacher.HasOrAdd() will receive this fix. Should be only positive impact, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right


_, found := tcc.data[key]
if found {
return found, false, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could have been true (for symmetry).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -115,14 +115,15 @@ func (tc *timeCacher) Peek(key []byte) (value interface{}, ok bool) {
// HasOrAdd checks if a key is in the cache.
// If key exists, does not update the value. Otherwise, adds the key-value in the cache
func (tc *timeCacher) HasOrAdd(key []byte, value interface{}, _ int) (has, added bool) {
existed, err := tc.timeCache.upsert(string(key), value, tc.timeCache.defaultSpan)
var err error
has, added, err = tc.timeCache.hasOrAdd(string(key), value, tc.timeCache.defaultSpan)
Copy link
Collaborator

@andreibancioiu andreibancioiu Aug 31, 2022

Choose a reason for hiding this comment

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

has and added are mutually exclusive, right? Bit of redundancy therefore, but it's good to be explicit (as it is now) 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they are exclusive. Since I have to implement the already existing and used interface, I had to return something.
Also, beside (true, false) and (false, true) we also have (false, false) when the provided key is nil or empty, so we had to encode 3 states.

andreibancioiu
andreibancioiu previously approved these changes Aug 31, 2022
mariusmihaic
mariusmihaic previously approved these changes Aug 31, 2022
@@ -57,6 +57,47 @@ func (tcc *timeCacheCore) upsert(key string, value interface{}, duration time.Du
return found, nil
}

// put will add the key, value and provided duration, overriding values if the data already existed
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe
Copy link
Collaborator

@sstanculeanu sstanculeanu Aug 31, 2022

Choose a reason for hiding this comment

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

Suggested change
// It returns true if the value existed before this call. It also operates on the locker so the call is concurrent safe
// It also operates on the locker so the call is concurrent safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed part of the comment

@@ -170,6 +170,9 @@ func (sender *peerAuthenticationSender) execute() (error, bool) {
return err, isTriggered
}

log.Debug("sending peer authentication message",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we keep this on Debug level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, one message at ~2hours. Helps the debugging a lot.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok


_, found := tcc.data[key]
if found {
return found, false, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return true, false, nil or at L100 return found, true, nil just to keep the same logic ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already done in last commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

sstanculeanu
sstanculeanu previously approved these changes Aug 31, 2022
andreibancioiu
andreibancioiu previously approved these changes Aug 31, 2022
mariusmihaic
mariusmihaic previously approved these changes Aug 31, 2022
# Conflicts:
#	process/heartbeat/interceptedHeartbeat.go
Copy link
Contributor

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed.

@gabi-vuls gabi-vuls merged commit 341ab3d into rc/2022-july Sep 1, 2022
@gabi-vuls gabi-vuls deleted the optimize-peer-auth-messages-management branch September 1, 2022 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants