Skip to content

Commit 2748d31

Browse files
author
Qi Xiao
committed
Move magic number to conf/limit
1 parent 9c90ce6 commit 2748d31

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

conf/limits.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ const (
2424
MaxPendingTxsPerAccount = 1000
2525
// MaxTransactionsPerBlock defines the limit of transactions per block.
2626
MaxTransactionsPerBlock = 10000
27+
// MaxRPCPoolPhysicalConnection defines max underlying physical connection for one node pair.
28+
MaxRPCPoolPhysicalConnection = 10
2729
)

rpc/pool.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ import (
2020
"net"
2121
"sync"
2222

23+
"github.com/CovenantSQL/CovenantSQL/conf"
2324
"github.com/CovenantSQL/CovenantSQL/proto"
2425
"github.com/pkg/errors"
2526
mux "github.com/xtaci/smux"
2627
)
2728

28-
// MaxPhysicalConnection defines max underlying physical connection for one node pair.
29-
const MaxPhysicalConnection = 10
30-
3129
// SessPool is the session pool interface
3230
type SessPool interface {
3331
Get(proto.NodeID) (net.Conn, error)
@@ -77,7 +75,7 @@ func (s *Session) Get() (conn net.Conn, err error) {
7775
s.Lock()
7876
defer s.Unlock()
7977
s.offset++
80-
s.offset %= MaxPhysicalConnection
78+
s.offset %= conf.MaxRPCPoolPhysicalConnection
8179

8280
var (
8381
sess *mux.Session

rpc/pool_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sync"
2323
"testing"
2424

25+
"github.com/CovenantSQL/CovenantSQL/conf"
2526
"github.com/CovenantSQL/CovenantSQL/proto"
2627
"github.com/CovenantSQL/CovenantSQL/utils"
2728
"github.com/CovenantSQL/CovenantSQL/utils/log"
@@ -32,7 +33,7 @@ import (
3233
const (
3334
localAddr = "127.0.0.1:4444"
3435
localAddr2 = "127.0.0.1:4445"
35-
concurrency = 15
36+
concurrency = conf.MaxRPCPoolPhysicalConnection + 1
3637
packetCount = 100
3738
)
3839

@@ -151,12 +152,12 @@ func TestNewSessionPool(t *testing.T) {
151152
}
152153

153154
wg.Wait()
154-
So(p.Len(), ShouldEqual, MaxPhysicalConnection)
155+
So(p.Len(), ShouldEqual, conf.MaxRPCPoolPhysicalConnection)
155156

156157
server(c, localAddr2, packetCount)
157158
_, err := p.Get(proto.NodeID(localAddr2))
158159
So(err, ShouldBeNil)
159-
So(p.Len(), ShouldEqual, MaxPhysicalConnection+1)
160+
So(p.Len(), ShouldEqual, conf.MaxRPCPoolPhysicalConnection+1)
160161

161162
wg2 := &sync.WaitGroup{}
162163
wg2.Add(concurrency)
@@ -181,10 +182,10 @@ func TestNewSessionPool(t *testing.T) {
181182
}
182183

183184
wg2.Wait()
184-
So(p.Len(), ShouldEqual, MaxPhysicalConnection*2)
185+
So(p.Len(), ShouldEqual, conf.MaxRPCPoolPhysicalConnection*2)
185186

186187
p.Remove(proto.NodeID(localAddr2))
187-
So(p.Len(), ShouldEqual, MaxPhysicalConnection)
188+
So(p.Len(), ShouldEqual, conf.MaxRPCPoolPhysicalConnection)
188189

189190
p.Close()
190191
So(p.Len(), ShouldEqual, 0)

0 commit comments

Comments
 (0)