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
4f4bad5d
Commit
4f4bad5d
authored
6 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] sync: use less than 400MB of memory
parent
f3a7d2d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/modules/crawler/lib/sync/ChunkGetter.ts
+15
-8
15 additions, 8 deletions
app/modules/crawler/lib/sync/ChunkGetter.ts
with
15 additions
and
8 deletions
app/modules/crawler/lib/sync/ChunkGetter.ts
+
15
−
8
View file @
4f4bad5d
...
...
@@ -54,6 +54,8 @@ export class ChunkGetter {
private
parallelDownloads
=
cliprogram
.
slow
?
1
:
5
private
maxDownloadAdvance
=
10
// 10 chunks can be downloaded even if 10th chunk above is not completed
private
MAX_DOWNLOAD_TIMEOUT
=
15000
private
readDAL
:
FileDAL
private
writeDAL
:
FileDAL
constructor
(
private
currency
:
string
,
...
...
@@ -61,15 +63,17 @@ export class ChunkGetter {
private
to
:
number
,
private
toHash
:
string
,
private
peers
:
JSONDBPeer
[],
private
dal
:
FileDAL
,
dal
:
FileDAL
,
private
nocautious
:
boolean
,
private
watcher
:
Watcher
,
private
otherDAL
?:
FileDAL
,
otherDAL
?:
FileDAL
,
)
{
this
.
readDAL
=
otherDAL
||
dal
this
.
writeDAL
=
dal
const
nbBlocksToDownload
=
Math
.
max
(
0
,
to
-
localNumber
)
this
.
numberOfChunksToDownload
=
Math
.
ceil
(
nbBlocksToDownload
/
CommonConstants
.
CONST_BLOCKS_CHUNK
)
this
.
p2PDownloader
=
new
P2PSyncDownloader
(
localNumber
,
to
,
peers
,
this
.
watcher
,
logger
)
this
.
fsDownloader
=
new
FsSyncDownloader
(
localNumber
,
to
,
o
th
erDAL
||
dal
,
this
.
getChunkName
.
bind
(
this
),
this
.
getChunksDir
.
bind
(
this
))
this
.
fsDownloader
=
new
FsSyncDownloader
(
localNumber
,
to
,
th
is
.
readDAL
,
this
.
getChunkName
.
bind
(
this
),
this
.
getChunksDir
.
bind
(
this
))
this
.
resultsDeferers
=
Array
.
from
({
length
:
this
.
numberOfChunksToDownload
}).
map
(()
=>
({
resolve
:
()
=>
{
throw
Error
(
'
resolve should not be called here
'
)
},
...
...
@@ -170,8 +174,8 @@ export class ChunkGetter {
}
else
if
(
handler
.
downloader
!==
this
.
fsDownloader
)
{
// Store the file to avoid re-downloading
if
(
this
.
localNumber
<=
0
&&
chunk
.
length
===
CommonConstants
.
CONST_BLOCKS_CHUNK
)
{
await
this
.
dal
.
confDAL
.
coreFS
.
makeTree
(
this
.
currency
);
await
this
.
dal
.
confDAL
.
coreFS
.
writeJSON
(
fileName
,
{
blocks
:
chunk
.
map
((
b
:
any
)
=>
DBBlock
.
fromBlockDTO
(
b
))
});
await
this
.
writeDAL
.
confDAL
.
coreFS
.
makeTree
(
this
.
currency
);
await
this
.
writeDAL
.
confDAL
.
coreFS
.
writeJSON
(
fileName
,
{
blocks
:
chunk
.
map
((
b
:
any
)
=>
DBBlock
.
fromBlockDTO
(
b
))
});
}
}
else
{
logger
.
warn
(
"
Chunk #%s read from filesystem.
"
,
i
)
...
...
@@ -182,11 +186,14 @@ export class ChunkGetter {
// Chunk is COMPLETE
logger
.
warn
(
"
Chunk #%s is COMPLETE
"
,
i
)
;(
handler
as
any
).
state
=
'
COMPLETED
'
if
(
!
isTopChunk
)
{
(
handler
as
any
).
chunk
=
undefined
}
this
.
downloadedChunks
++
this
.
watcher
.
downloadPercent
(
parseInt
((
this
.
downloadedChunks
/
this
.
numberOfChunksToDownload
*
100
).
toFixed
(
0
)))
// We pre-save blocks only for non-cautious sync
if
(
this
.
nocautious
)
{
await
this
.
dal
.
blockchainArchiveDAL
.
archive
(
chunk
.
map
(
b
=>
{
await
this
.
writeDAL
.
blockchainArchiveDAL
.
archive
(
chunk
.
map
(
b
=>
{
const
block
=
DBBlock
.
fromBlockDTO
(
b
)
block
.
fork
=
false
return
block
...
...
@@ -198,9 +205,9 @@ export class ChunkGetter {
// Returns a promise of file content
this
.
resultsDeferers
[
i
].
resolve
(
async
()
=>
{
if
(
isTopChunk
)
{
return
chunk
return
await
handler
.
chunk
// don't return directly "chunk" as it would prevent the GC to collect it
}
return
(
await
this
.
dal
.
confDAL
.
coreFS
.
readJSON
(
fileName
)).
blocks
return
(
await
this
.
readDAL
.
confDAL
.
coreFS
.
readJSON
(
fileName
)).
blocks
})
}
}
else
{
...
...
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