[SERVER-10357] An update $push with sort is slower than expected Created: 26/Jul/13  Updated: 10/Dec/14  Resolved: 22/May/14

Status: Closed
Project: Core Server
Component/s: Performance, Write Ops
Affects Version/s: 2.5.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Andrew Emil (Inactive) Assignee: Andrew Emil (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File sortTest.js    
Issue Links:
Related
is related to SERVER-10159 Evaluate performance of new update fr... Closed
Operating System: ALL
Steps To Reproduce:

> db.brsort.drop()
true
> db.brsort.insert({_id : 1, list : []})
> sort
{
"ops" : [
{
"ns" : "test.brsort",
"op" : "update",
"query" :

{ "_id" : 1 }

,
"update" : {
"$push" : {
"list" : {
"$each" : [

{ "b" : 1 }

],
"$slice" : -100,
"$sort" :

{ "b" : 1 }

}
}
}
}
],
"parallel" : 1,
"seconds" : 10
}
>benchRun(sort)

Participants:

 Description   

Seems like adding a $sort to a $push + $slice commands results in an unreasonably large slowdown. A slowdown is expected for large arrays, but it is surprising to see a 5x change when sorting an already sorted array of length 100.

Note: I have only tested this on 2.5.0, dont have comparisons between versions

Results from reproduction code using benchRun on various array sizes:

Array length 1:
Sort: 18280
No sort: 19936
Change: 1.1x

Array length 10:
Sort: 15300
No sort: 19400
Change: 1.3x

Array length 100:
Sort: 3230
No sort: 16660
Change: 5.2x

Array length 1,000:
Sort: 230
No sort: 2176
Change: 9.5x

Array length 10,000:
Sort: 70
No sort: 450
Change: 6.4x

Array length: 100,000:
Sort: 30
No sort: 260
Change: 8.7x


Generated at Thu Feb 08 03:22:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.