Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
43fa0c25
Commit
43fa0c25
authored
6 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#1325
Do not always select the same nodes for P2P downloading
parent
65ebf762
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/modules/crawler/lib/sync/P2PSyncDownloader.ts
+6
-4
6 additions, 4 deletions
app/modules/crawler/lib/sync/P2PSyncDownloader.ts
app/modules/crawler/lib/sync/p2p/p2p-candidate.ts
+4
-0
4 additions, 0 deletions
app/modules/crawler/lib/sync/p2p/p2p-candidate.ts
with
10 additions
and
4 deletions
app/modules/crawler/lib/sync/P2PSyncDownloader.ts
+
6
−
4
View file @
43fa0c25
...
@@ -68,10 +68,7 @@ export class P2PSyncDownloader extends ASyncDownloader implements ISyncDownloade
...
@@ -68,10 +68,7 @@ export class P2PSyncDownloader extends ASyncDownloader implements ISyncDownloade
nodesAvailable
=
nodesAvailable
.
concat
(
readyNodes
)
nodesAvailable
=
nodesAvailable
.
concat
(
readyNodes
)
i
++
i
++
}
}
return
nodesAvailable
.
slice
(
0
,
needed
).
map
(
n
=>
{
return
nodesAvailable
n
.
reserve
()
return
n
})
}
}
/**
/**
...
@@ -81,12 +78,17 @@ export class P2PSyncDownloader extends ASyncDownloader implements ISyncDownloade
...
@@ -81,12 +78,17 @@ export class P2PSyncDownloader extends ASyncDownloader implements ISyncDownloade
*/
*/
private
async
getP2Pcandidates
(
chunkIndex
:
number
):
Promise
<
P2pCandidate
[]
>
{
private
async
getP2Pcandidates
(
chunkIndex
:
number
):
Promise
<
P2pCandidate
[]
>
{
return
this
.
fifoPromise
.
pushFIFOPromise
(
'
getP2Pcandidates_
'
+
getNanosecondsTime
(),
async
()
=>
{
return
this
.
fifoPromise
.
pushFIFOPromise
(
'
getP2Pcandidates_
'
+
getNanosecondsTime
(),
async
()
=>
{
const
needed
=
1
// We wait a bit to have some available nodes
// We wait a bit to have some available nodes
const
readyNodes
=
await
this
.
waitForAvailableNodesAndReserve
()
const
readyNodes
=
await
this
.
waitForAvailableNodesAndReserve
()
// We remove the nodes impossible to reach (timeout)
// We remove the nodes impossible to reach (timeout)
let
byAvgAnswerTime
=
Underscore
.
sortBy
(
readyNodes
,
p
=>
p
.
avgResponseTime
())
let
byAvgAnswerTime
=
Underscore
.
sortBy
(
readyNodes
,
p
=>
p
.
avgResponseTime
())
const
parallelMax
=
Math
.
min
(
this
.
PARALLEL_PER_CHUNK
,
byAvgAnswerTime
.
length
)
const
parallelMax
=
Math
.
min
(
this
.
PARALLEL_PER_CHUNK
,
byAvgAnswerTime
.
length
)
byAvgAnswerTime
=
byAvgAnswerTime
.
slice
(
0
,
parallelMax
)
byAvgAnswerTime
=
byAvgAnswerTime
.
slice
(
0
,
parallelMax
)
this
.
watcher
.
reserveNodes
(
byAvgAnswerTime
)
byAvgAnswerTime
.
slice
(
0
,
needed
).
forEach
(
n
=>
{
n
.
reserve
()
})
if
(
byAvgAnswerTime
.
length
===
0
)
{
if
(
byAvgAnswerTime
.
length
===
0
)
{
this
.
logger
.
warn
(
'
No node found to download chunk #%s.
'
,
chunkIndex
)
this
.
logger
.
warn
(
'
No node found to download chunk #%s.
'
,
chunkIndex
)
this
.
watcher
.
unableToDownloadChunk
(
chunkIndex
)
this
.
watcher
.
unableToDownloadChunk
(
chunkIndex
)
...
...
This diff is collapsed.
Click to expand it.
app/modules/crawler/lib/sync/p2p/p2p-candidate.ts
+
4
−
0
View file @
43fa0c25
...
@@ -43,6 +43,7 @@ export class P2pCandidate {
...
@@ -43,6 +43,7 @@ export class P2pCandidate {
return
Promise
.
race
([
return
Promise
.
race
([
// Wait for availablity
// Wait for availablity
(
async
()
=>
!
this
.
isExcluded
(
async
()
=>
!
this
.
isExcluded
&&
!
this
.
reserved
&&
(
this
.
apiPromise
.
isRejected
()
?
await
newResolveTimeoutPromise
(
maxWait
,
false
)
:
!!
(
await
this
.
apiPromise
))
&&
(
this
.
apiPromise
.
isRejected
()
?
await
newResolveTimeoutPromise
(
maxWait
,
false
)
:
!!
(
await
this
.
apiPromise
))
&&
(
this
.
dlPromise
.
isRejected
()
?
await
newResolveTimeoutPromise
(
maxWait
,
false
)
:
!!
(
await
this
.
dlPromise
)))(),
&&
(
this
.
dlPromise
.
isRejected
()
?
await
newResolveTimeoutPromise
(
maxWait
,
false
)
:
!!
(
await
this
.
dlPromise
)))(),
// Maximum wait trigger
// Maximum wait trigger
...
@@ -55,6 +56,9 @@ export class P2pCandidate {
...
@@ -55,6 +56,9 @@ export class P2pCandidate {
}
}
avgResponseTime
()
{
avgResponseTime
()
{
if
(
!
this
.
responseTimes
.
length
)
{
return
0
}
return
this
.
responseTimes
.
reduce
((
sum
,
rt
)
=>
sum
+
rt
,
0
)
/
this
.
responseTimes
.
length
return
this
.
responseTimes
.
reduce
((
sum
,
rt
)
=>
sum
+
rt
,
0
)
/
this
.
responseTimes
.
length
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment