Skip to content

Commit 029f269

Browse files
committed
insight: count client connections and set max to 16384
1 parent 6630dae commit 029f269

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

api/insight/socket.io.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionG
8989
return nil, err
9090
}
9191

92+
// Set maximum number of connections.
93+
server.SetMaxConnection(16384)
94+
9295
// Each address subscription uses its own room, which has the same name as
9396
// the address. The number of subscribers for each room is tracked.
9497
addrs := roomSubscriptionCounter{
@@ -97,15 +100,17 @@ func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionG
97100
}
98101

99102
server.On("connection", func(so socketio.Socket) {
100-
apiLog.Debug("New socket.io connection")
103+
apiLog.Debugf("New socket.io connection. %d clients are connected.",
104+
server.Count())
101105
// New connections automatically join the inv and sync rooms.
102106
so.Join("inv")
103107
so.Join("sync")
104108

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

151+
apiLog.Infof("Started Insight socket.io server for up to %d clients.",
152+
server.GetMaxConnection())
153+
146154
sockServ := SocketServer{
147155
Server: *server,
148156
params: params,

0 commit comments

Comments
 (0)