Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
dCache
cta
Commits
73e8f68f
Commit
73e8f68f
authored
6 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Improved retrieve queue insertion algorith selection.
parent
ea44f81f
No related branches found
Branches containing commit
Tags
v0.0-161
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
objectstore/RetrieveQueueShard.cpp
+58
-7
58 additions, 7 deletions
objectstore/RetrieveQueueShard.cpp
with
58 additions
and
7 deletions
objectstore/RetrieveQueueShard.cpp
+
58
−
7
View file @
73e8f68f
...
@@ -173,14 +173,65 @@ auto RetrieveQueueShard::getJobsSummary() -> JobsSummary {
...
@@ -173,14 +173,65 @@ auto RetrieveQueueShard::getJobsSummary() -> JobsSummary {
void
RetrieveQueueShard
::
addJobsBatch
(
JobsToAddSet
&
jobsToAdd
)
{
void
RetrieveQueueShard
::
addJobsBatch
(
JobsToAddSet
&
jobsToAdd
)
{
checkPayloadWritable
();
checkPayloadWritable
();
// Decide on the best algorithm. In place insertion implies 2*k*(N/2) copies
// Protect following algorithms against zero-sized array.
if
(
jobsToAdd
.
empty
())
return
;
// Decide on the best algorithm. In place insertion implies 3*k*(N/2) copies
// as we move the inserted job in place by swaps from the end (N/2 on average).
// as we move the inserted job in place by swaps from the end (N/2 on average).
// In practice, we can reduce the value of N by finding the last index imin
// at which fseq is smaller than the lowest fseq of the data to be inserted.
// We then know that the first element to insert take exactly Np = N-imin-1 swaps
// to move in place.
// If we make no assumption for the other jobs to insert, they will each require
// Np/2 swaps to move in place on average.
// The cost can then reduced to Np + (k-1)Np/2 = 3*(k+1)Np/2
// On the other hand, insertion through memory implies 2N+3k copies, N to copy
// On the other hand, insertion through memory implies 2N+3k copies, N to copy
// to a set, k copies to create the second set, k copies again during merge
// to a set, k copies to create the second set, k copies again during merge
// and then N+k copies to copy the merged set into payload.
// and then N+k copies to copy the merged set into payload.
// Find Np by bisection.
size_t
N
=
m_payload
.
retrievejobs_size
();
size_t
N
=
m_payload
.
retrievejobs_size
();
size_t
Np
=
N
;
auto
fSeqLimit
=
jobsToAdd
.
begin
()
->
fSeq
;
if
(
0
==
N
)
Np
=
0
;
else
if
(
1
==
N
)
Np
=
m_payload
.
retrievejobs
(
0
).
fseq
()
<=
fSeqLimit
?
0
:
1
;
else
{
size_t
iminmin
=
0
;
size_t
iminmax
=
N
-
1
;
size_t
imin
=
N
/
2
;
uint64_t
iminfseq
=
~
0
;
uint64_t
imin1fseq
=
~
0
;
while
(
true
)
{
iminfseq
=
m_payload
.
retrievejobs
(
imin
).
fseq
();
if
(
iminfseq
>
fSeqLimit
)
{
iminmax
=
imin
;
imin
=
(
iminmin
+
iminmax
)
/
2
;
// Did we reach the beginning of the array?
if
(
!
imin
)
{
Np
=
m_payload
.
retrievejobs
(
0
).
fseq
()
<=
fSeqLimit
?
N
-
1
:
N
;
break
;
}
}
else
{
// Before comparing, make sure we are not reaching the end of the set.
if
(
imin
>=
N
-
1
)
{
Np
=
m_payload
.
retrievejobs
(
N
-
1
).
fseq
()
<=
fSeqLimit
?
0
:
1
;
break
;
}
imin1fseq
=
m_payload
.
retrievejobs
(
imin
+
1
).
fseq
();
if
(
imin1fseq
>
fSeqLimit
)
{
// We found the right imin.
Np
=
N
-
imin
-
1
;
break
;
}
else
if
(
imin
+
1
==
N
-
1
)
{
Np
=
0
;
break
;
}
else
{
iminmin
=
imin
;
imin
=
(
iminmin
+
iminmax
)
/
2
;
}
}
}
}
size_t
k
=
jobsToAdd
.
size
();
size_t
k
=
jobsToAdd
.
size
();
if
(
k
*
N
>
2
*
N
+
3
*
k
)
if
(
3
*
(
k
+
1
)
*
Np
/
2
>
2
*
N
+
3
*
k
)
addJobsThroughCopy
(
jobsToAdd
);
addJobsThroughCopy
(
jobsToAdd
);
else
else
addJobsInPlace
(
jobsToAdd
);
addJobsInPlace
(
jobsToAdd
);
...
@@ -212,14 +263,14 @@ void RetrieveQueueShard::addJob(const RetrieveQueue::JobToAdd& jobToAdd) {
...
@@ -212,14 +263,14 @@ void RetrieveQueueShard::addJob(const RetrieveQueue::JobToAdd& jobToAdd) {
void
RetrieveQueueShard
::
addJobsThroughCopy
(
JobsToAddSet
&
jobsToAdd
)
{
void
RetrieveQueueShard
::
addJobsThroughCopy
(
JobsToAddSet
&
jobsToAdd
)
{
checkPayloadWritable
();
checkPayloadWritable
();
SerializedJobsToAddSet
jobs
Map
;
SerializedJobsToAddSet
jobs
Set
;
SerializedJobsToAddSet
serializedJobsToAdd
;
SerializedJobsToAddSet
serializedJobsToAdd
;
SerializedJobsToAddSet
::
iterator
i
=
jobs
Map
.
begin
();
SerializedJobsToAddSet
::
iterator
i
=
jobs
Set
.
begin
();
// Copy the request pointers in memory (in an ordered multi set)
// Copy the request pointers in memory (in an ordered multi set)
for
(
auto
&
j
:
m_payload
.
retrievejobs
())
for
(
auto
&
j
:
m_payload
.
retrievejobs
())
// As the queue is already sorted, we hit at the right
// As the queue is already sorted, we hit at the right
// location (in-order insertion).
// location (in-order insertion).
i
=
jobs
Map
.
insert
(
i
,
j
);
i
=
jobs
Set
.
insert
(
i
,
j
);
// Create a serialized version of the jobs to add.
// Create a serialized version of the jobs to add.
i
=
serializedJobsToAdd
.
begin
();
i
=
serializedJobsToAdd
.
begin
();
uint64_t
totalSize
=
m_payload
.
retrievejobstotalsize
();
uint64_t
totalSize
=
m_payload
.
retrievejobstotalsize
();
...
@@ -237,10 +288,10 @@ void RetrieveQueueShard::addJobsThroughCopy(JobsToAddSet& jobsToAdd) {
...
@@ -237,10 +288,10 @@ void RetrieveQueueShard::addJobsThroughCopy(JobsToAddSet& jobsToAdd) {
totalSize
+=
jobToAdd
.
fileSize
;
totalSize
+=
jobToAdd
.
fileSize
;
}
}
// Let STL do the heavy lifting of in-order insertion.
// Let STL do the heavy lifting of in-order insertion.
jobs
Map
.
insert
(
serializedJobsToAdd
.
begin
(),
serializedJobsToAdd
.
end
());
jobs
Set
.
insert
(
serializedJobsToAdd
.
begin
(),
serializedJobsToAdd
.
end
());
// Recreate the shard from the in-memory image (it's already sorted).
// Recreate the shard from the in-memory image (it's already sorted).
m_payload
.
mutable_retrievejobs
()
->
Clear
();
m_payload
.
mutable_retrievejobs
()
->
Clear
();
for
(
auto
&
j
:
jobs
Map
)
for
(
auto
&
j
:
jobs
Set
)
*
m_payload
.
add_retrievejobs
()
=
j
;
*
m_payload
.
add_retrievejobs
()
=
j
;
m_payload
.
set_retrievejobstotalsize
(
totalSize
);
m_payload
.
set_retrievejobstotalsize
(
totalSize
);
}
}
...
...
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