Open
Conversation
kegsay
reviewed
Oct 5, 2020
| "gomatrixserverlib: key with ID %q for %q not valid at %d", | ||
| keyID, j.request.ServerName, j.request.AtTS, | ||
| ) | ||
| mu.Unlock() |
Member
There was a problem hiding this comment.
I'm not a fan of the shared variables across goroutines, it feels like a code smell as opposed to sharing data via channels. I'm aware we do this to maintain the index in the results array.
I think a better solution would be to add the parallelisation around VerifyJSON only, meaning you just need to pass information that is directly used without needing to access shared slices/maps. Something like:
type verifyJSONReq struct {
i int
serverName ServerName
keyID KeyID
pubKey ed25519.PublicKey
msg []byte
}
type verifyJSONRes struct {
i int
err error
}
reqCh := make(chan verifyJSONReq, 50)
resCh := make(chan verifyJSONRes, 50)
var wg sync.WaitGroup
wg.Add(procs)
for i := 0; i < procs; i++ {
go func() {
defer wg.Done()
for item := range reqCh {
err := VerifyJSON(item.serverName, item.keyID, item.pubKey, item.msg)
resCh <- verifyJSONRes{item.i, err}
}
}
}
for i := range requests {
// insert code that was there previously up to VerifyJSON
reqCh <- verifyJSONReq{i, other, func, args}
}
close(reqCh) // kill the goroutines after they process everything
// kill the response channel when we've got all the response
go func() {
wg.Wait()
close(resCh)
}()
for res := range resCh {
results[res.i].Error = res.err
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This speeds up signature checks by performing them across available CPU cores (less one, to not totally starve the system).
This might cause problems if lots of big signature checks are taking place concurrently though, so there's that.