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

Use a concurrent strategy to speed up BLS Public Keys and Signature aggregation #66

Closed
autholykos opened this issue Sep 3, 2019 · 2 comments
Labels
status:wontfix This will not be worked on type:rfc Changing the behaviour of something already defined

Comments

@autholykos
Copy link
Member

autholykos commented Sep 3, 2019

Benchmarks conducted on dusk-network/dusk-crypto#14 show a substantial performance improvement when parallelizing the aggregation operations. Given the criticality of such aggregation when creating Agreement messages, it would be good to apply the concurrent strategy to minimize event production time and avoid slacking behind when in terms of steps (or even round) just because Agreement creation is slow.

Following function should serve as an inspiration for exploiting concurrency when aggregating Signature:

func aggregateSignatures(sigs []*Signature) *Signature {
    const W = 4
    C := len(sigs)

    M := C / W
    R := C % W

    if C < M {
        return aggregateSignaturesSequential(sigs)
    }

    var wg sync.WaitGroup
    var last *Signature

    // goroutines will fill this slice concurrently
    sgs := make([]*Signature, W) 

    wg.Add(W)
    // w workers for n couples
    for w := 0; w < W; w++ {
        // each goroutine will execute a sequential Aggregation of M signatures
        lo, hi := w*M, (w+1)*M 

        go func(i int, set []*Signature) {
            sgs[i] = aggregateSignaturesSequential(set)
            wg.Done()
        }(w, sigs[lo:hi])
    }

    // aggregating the remaining chunks not fitting in the worker count
    if R > 0 { 
        last = aggregateSignaturesSequential(sigs[C-R:])
    }

    wg.Wait() // waiting for all the goroutines to be done

    if last != nil {
        sgs = append(sgs, last)
    }

    return aggregateSignaturesSequential(sgs)
}

func aggregateSignaturesSequential(sigs []*Signature) *Signature {
    s, sigmas := sigs[0], sigs[1:]
    for _, sig := range sigmas {
        s = s.Aggregate(sig)
    }
    return s
}
@jules jules added type:rfc Changing the behaviour of something already defined Node:Consensus labels Sep 3, 2019
@autholykos
Copy link
Member Author

This depends on the capability to benchmark the Reducer, which might be greatly simplified by #72

@autholykos
Copy link
Member Author

Although the proposal is actually valid, the Reducer no longer performs batch signature aggregation. Therefore, there is no opportunity for parallelizing signature aggregation through a worker mechanism.

@autholykos autholykos added the status:wontfix This will not be worked on label Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:wontfix This will not be worked on type:rfc Changing the behaviour of something already defined
Projects
None yet
Development

No branches or pull requests

2 participants