Skip to content

Commit 3c89345

Browse files
committed
CP-52880: Avoid O(N^2) behaviour in Xapi_vdi.update_allowed_operations
Activate old xapi_vdi.update_allowed_operations optimization: get_internal_records_where does a linear scan currently, so operating on N VDIs is O(N^2). Look at the VBD records directly, like before this 2013 commit which regressed it: 5097475 (We are going to optimize get_record separately so it doesn't go through serialization) For now only do this when run on the coordinator to avoid potentially large number of VBD round-trip database fetches. We'll need to optimize the 'get_internal_record_where' later to also speed up the pool case. ``` ╭─────────────────────────────────┬───────────────────────────┬───────────────────────────┬───────────────────────────╮ │name │ major-allocated │ minor-allocated │ monotonic-clock │ ├─────────────────────────────────┼───────────────────────────┼───────────────────────────┼───────────────────────────┤ │ update_allowed_operations/VDI │ 9205.8042 mjw/run│ 964577.0228 mnw/run│ 2868770.0725 ns/run│ ╰─────────────────────────────────┴───────────────────────────┴───────────────────────────┴───────────────────────────╯ update_allowed_operations/VDI (ns): { monotonic-clock per run = 2868770.072546 (confidence: 2947963.590731 to 2834338.835371); r² = Some 0.404284 } ``` Compared to the previous commit this is 18x faster. Signed-off-by: Edwin Török <edwin.torok@cloud.com>
1 parent 9c01fe4 commit 3c89345

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ocaml/xapi/xapi_vdi.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,15 @@ let update_allowed_operations_internal ~__context ~self ~sr_records ~pbd_records
476476
)
477477
in
478478
let all = Db.VDI.get_record_internal ~__context ~self in
479+
let vbd_records =
480+
match vbd_records with
481+
| None when Pool_role.is_master () ->
482+
all.Db_actions.vDI_VBDs
483+
|> List.rev_map (fun self -> Db.VBD.get_record_internal ~__context ~self)
484+
|> Option.some
485+
| v ->
486+
v
487+
in
479488
let allowed =
480489
let check x =
481490
match

0 commit comments

Comments
 (0)