Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4366c45e
Unverified
Commit
4366c45e
authored
Jul 21, 2020
by
Binacs
Committed by
GitHub
Jul 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
les: make clientPool.connectedBias configurable (#21305)
parent
3a52c4dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
17 deletions
+28
-17
api.go
les/api.go
+12
-0
clientpool.go
les/clientpool.go
+14
-15
clientpool_test.go
les/clientpool_test.go
+2
-2
No files found.
les/api.go
View file @
4366c45e
...
...
@@ -202,6 +202,18 @@ func (api *PrivateLightServerAPI) SetDefaultParams(params map[string]interface{}
return
err
}
// SetConnectedBias set the connection bias, which is applied to already connected clients
// So that already connected client won't be kicked out very soon and we can ensure all
// connected clients can have enough time to request or sync some data.
// When the input parameter `bias` < 0 (illegal), return error.
func
(
api
*
PrivateLightServerAPI
)
SetConnectedBias
(
bias
time
.
Duration
)
error
{
if
bias
<
time
.
Duration
(
0
)
{
return
fmt
.
Errorf
(
"bias illegal: %v less than 0"
,
bias
)
}
api
.
server
.
clientPool
.
setConnectedBias
(
bias
)
return
nil
}
// Benchmark runs a request performance benchmark with a given set of measurement setups
// in multiple passes specified by passCount. The measurement time for each setup in each
// pass is specified in milliseconds by length.
...
...
les/clientpool.go
View file @
4366c45e
...
...
@@ -42,15 +42,7 @@ const (
persistCumulativeTimeRefresh
=
time
.
Minute
*
5
// refresh period of the cumulative running time persistence
posBalanceCacheLimit
=
8192
// the maximum number of cached items in positive balance queue
negBalanceCacheLimit
=
8192
// the maximum number of cached items in negative balance queue
// connectedBias is applied to already connected clients So that
// already connected client won't be kicked out very soon and we
// can ensure all connected clients can have enough time to request
// or sync some data.
//
// todo(rjl493456442) make it configurable. It can be the option of
// free trial time!
connectedBias
=
time
.
Minute
*
3
defaultConnectedBias
=
time
.
Minute
*
3
// the default connectedBias used in clientPool
)
// clientPool implements a client database that assigns a priority to each client
...
...
@@ -94,7 +86,7 @@ type clientPool struct {
freeClientCap
uint64
// The capacity value of each free client
startTime
mclock
.
AbsTime
// The timestamp at which the clientpool started running
cumulativeTime
int64
// The cumulative running time of clientpool at the start point.
disableBias
bool
//
Disable connection bias(used in testing)
connectedBias
time
.
Duration
// The connection bias. 0:
Disable connection bias(used in testing)
}
// clientPoolPeer represents a client peer in the pool.
...
...
@@ -171,6 +163,7 @@ func newClientPool(db ethdb.Database, freeClientCap uint64, clock mclock.Clock,
startTime
:
clock
.
Now
(),
cumulativeTime
:
ndb
.
getCumulativeTime
(),
stopCh
:
make
(
chan
struct
{}),
connectedBias
:
defaultConnectedBias
,
}
// If the negative balance of free client is even lower than 1,
// delete this entry.
...
...
@@ -279,11 +272,7 @@ func (f *clientPool) connect(peer clientPoolPeer, capacity uint64) bool {
newCount
--
return
newCapacity
>
f
.
capLimit
||
newCount
>
f
.
connLimit
})
bias
:=
connectedBias
if
f
.
disableBias
{
bias
=
0
}
if
newCapacity
>
f
.
capLimit
||
newCount
>
f
.
connLimit
||
(
e
.
balanceTracker
.
estimatedPriority
(
now
+
mclock
.
AbsTime
(
bias
),
false
)
-
kickPriority
)
>
0
{
if
newCapacity
>
f
.
capLimit
||
newCount
>
f
.
connLimit
||
(
e
.
balanceTracker
.
estimatedPriority
(
now
+
mclock
.
AbsTime
(
f
.
connectedBias
),
false
)
-
kickPriority
)
>
0
{
for
_
,
c
:=
range
kickList
{
f
.
connectedQueue
.
Push
(
c
)
}
...
...
@@ -371,6 +360,16 @@ func (f *clientPool) setDefaultFactors(posFactors, negFactors priceFactors) {
f
.
defaultNegFactors
=
negFactors
}
// setConnectedBias sets the connection bias, which is applied to already connected clients
// So that already connected client won't be kicked out very soon and we can ensure all
// connected clients can have enough time to request or sync some data.
func
(
f
*
clientPool
)
setConnectedBias
(
bias
time
.
Duration
)
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
connectedBias
=
bias
}
// dropClient removes a client from the connected queue and finalizes its balance.
// If kick is true then it also initiates the disconnection.
func
(
f
*
clientPool
)
dropClient
(
e
*
clientInfo
,
now
mclock
.
AbsTime
,
kick
bool
)
{
...
...
les/clientpool_test.go
View file @
4366c45e
...
...
@@ -91,7 +91,7 @@ func testClientPool(t *testing.T, connLimit, clientCount, paidCount int, randomD
}
pool
=
newClientPool
(
db
,
1
,
&
clock
,
disconnFn
)
)
pool
.
disableBias
=
true
pool
.
setConnectedBias
(
0
)
pool
.
setLimits
(
connLimit
,
uint64
(
connLimit
))
pool
.
setDefaultFactors
(
priceFactors
{
1
,
0
,
1
},
priceFactors
{
1
,
0
,
1
})
...
...
@@ -248,7 +248,7 @@ func TestPaidClientKickedOut(t *testing.T) {
clock
.
Run
(
time
.
Millisecond
)
}
clock
.
Run
(
time
.
Second
)
clock
.
Run
(
c
onnectedBias
)
clock
.
Run
(
defaultC
onnectedBias
)
if
!
pool
.
connect
(
poolTestPeer
(
11
),
0
)
{
t
.
Fatalf
(
"Free client should be accectped"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment