Skip to content

Commit

Permalink
Make hypervisor getVisors concurrent.
Browse files Browse the repository at this point in the history
  • Loading branch information
志宇 committed Feb 28, 2020
1 parent 18f482d commit 09c5eb7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/SkycoinProject/skywire-mainnet
go 1.13

require (
github.com/SkycoinProject/dmsg v0.0.0-20200226145926-514fc8d015a1
github.com/SkycoinProject/dmsg v0.0.0-20200227084433-7605a550f502
github.com/SkycoinProject/skycoin v0.27.0
github.com/SkycoinProject/yamux v0.0.0-20191213015001-a36efeefbf6a
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/SkycoinProject/dmsg v0.0.0-20200226145926-514fc8d015a1 h1:51rz38hyi2RKpNr/CEJgsVwjy22yt8gEess2WlzibmA=
github.com/SkycoinProject/dmsg v0.0.0-20200226145926-514fc8d015a1/go.mod h1:eCoemDDyfyfNTFrapYKNEItwtRIj54UGpu4Ffcznuds=
github.com/SkycoinProject/dmsg v0.0.0-20200227084433-7605a550f502 h1:fxCUIQ5EXmo0LpryqsqREysixAqtjSO6m60nDbe12iQ=
github.com/SkycoinProject/dmsg v0.0.0-20200227084433-7605a550f502/go.mod h1:eCoemDDyfyfNTFrapYKNEItwtRIj54UGpu4Ffcznuds=
github.com/SkycoinProject/skycoin v0.26.0 h1:8/ZRZb2VM2DM4YTIitRJMZ3Yo/3H1FFmbCMx5o6ekmA=
github.com/SkycoinProject/skycoin v0.26.0/go.mod h1:xqPLOKh5B6GBZlGA7B5IJfQmCy7mwimD9NlqxR3gMXo=
github.com/SkycoinProject/skycoin v0.27.0 h1:N3IHxj8ossHOcsxLYOYugT+OaELLncYHJHxbbYLPPmY=
Expand Down
38 changes: 24 additions & 14 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,33 @@ type summaryResp struct {
// provides summary of all visors.
func (m *Hypervisor) getVisors() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var summaries []summaryResp

m.mu.RLock()
for pk, c := range m.visors {
summary, err := c.RPC.Summary()
if err != nil {
log.Errorf("failed to obtain summary from Hypervisor with pk %s. Error: %v", pk, err)
wg := new(sync.WaitGroup)
wg.Add(len(m.visors))
summaries, i := make([]summaryResp, len(m.visors)), 0

summary = &visor.Summary{PubKey: pk}
}

summaries = append(summaries, summaryResp{
TCPAddr: c.Addr.String(),
Online: err == nil,
Summary: summary,
})
for pk, c := range m.visors {
go func(pk cipher.PubKey, c VisorConn, i int) {
log := log.WithField("visor_addr", c.Addr)
log.WithField("func", "c.RPC.Summary()").Debug("Calling RPC.")

summary, err := c.RPC.Summary()
if err != nil {
log.WithError(err).
Warn("Failed to obtain visor summary.")
summary = &visor.Summary{PubKey: pk}
}
summaries[i] = summaryResp{
TCPAddr: c.Addr.String(),
Online: err == nil,
Summary: summary,
}
wg.Done()
}(pk, c, i)
i++
}

wg.Wait()
m.mu.RUnlock()

httputil.WriteJSON(w, r, http.StatusOK, summaries)
Expand Down
3 changes: 2 additions & 1 deletion vendor/github.com/SkycoinProject/dmsg/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/SkycoinProject/dmsg/client_session.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/SkycoinProject/dmsg/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/SkycoinProject/dmsg v0.0.0-20200226145926-514fc8d015a1
# github.com/SkycoinProject/dmsg v0.0.0-20200227084433-7605a550f502
github.com/SkycoinProject/dmsg
github.com/SkycoinProject/dmsg/cipher
github.com/SkycoinProject/dmsg/disc
Expand Down

0 comments on commit 09c5eb7

Please sign in to comment.