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

insight: count client connections and set max to 16384 #1481

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions api/insight/socket.io.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionG
return nil, err
}

// Set maximum number of connections.
server.SetMaxConnection(16384)

// Each address subscription uses its own room, which has the same name as
// the address. The number of subscribers for each room is tracked.
addrs := roomSubscriptionCounter{
Expand All @@ -97,15 +100,17 @@ func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionG
}

server.On("connection", func(so socketio.Socket) {
apiLog.Debug("New socket.io connection")
apiLog.Debugf("New socket.io connection. %d clients are connected.",
server.Count())
// New connections automatically join the inv and sync rooms.
so.Join("inv")
so.Join("sync")

// Disconnection decrements or deletes the subscriber counter for each
// address room to which the client was subscribed.
so.On("disconnection", func() {
apiLog.Debug("socket.io client disconnected")
apiLog.Debugf("socket.io client disconnected. %d clients are connected.",
server.Count())
addrs.Lock()
for _, str := range so.Rooms() {
if c, ok := addrs.c[str]; ok {
Expand Down Expand Up @@ -143,6 +148,9 @@ func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionG
apiLog.Errorf("Insight socket.io server error: %v", err)
})

apiLog.Infof("Started Insight socket.io server for up to %d clients.",
server.GetMaxConnection())

sockServ := SocketServer{
Server: *server,
params: params,
Expand Down