Repository navigation
Stream the zip file listing with a plan for its whole result - #1662
Conversation
Django reads the listing through a server side cursor, and postgres plans a cursor for a cheap first row, assuming only cursor_tuple_fraction (default 0.1) of the rows will be fetched. The listing always fetches every row, and the first-row plan took several times longer. The transaction the view opened ended when the view returned, before the response streamed, so it never covered the listing. It now opens in the writer, around the filename check and the listing, and sets cursor_tuple_fraction to 1.0. The count query that only decided the filename and the separate licenses query are gone: two ids answer the filename, and the licenses are collected while streaming. Rows are fetched 20,000 at a time, and the per-row work is trimmed. Minimum of the benchmark rounds on one machine. The fixed dataset has 100,000 images: search images before after speedup medium collection 10,000 88.9 ms 34.6 ms 2.6x malignant 4,991 73.2 ms 22.4 ms 3.3x all public 46,001 172.5 ms 111.2 ms 1.6x everything, staff 100,000 367.3 ms 222.6 ms 1.6x With BENCHMARK_EXTRA_IMAGES=1000000 the dataset has 1,100,000 images, and the same searches match more of them, except the collection: search images before after speedup medium collection 10,000 767 ms 117 ms 6.6x malignant 55,868 3,932 ms 611 ms 6.4x all public 506,854 5,217 ms 1,528 ms 3.4x everything, staff 1,100,000 10,766 ms 2,890 ms 3.7x EXPLAIN ANALYZE DECLARE CURSOR of the staff listing at 1,100,000 images takes 7.0 s with the default cursor_tuple_fraction and 1.0 s with 1.0.
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
Django reads the listing through a server side cursor, and postgres plans a cursor for a cheap first row, assuming only
cursor_tuple_fraction(default 0.1) of the rows will be fetched. The listing always fetches every row, and the first-row plan took several times longer. The transaction the view opened ended when the view returned, before the response streamed, so it never covered the listing. It now opens in the writer, around the filename check and the listing, and setscursor_tuple_fractionto 1.0.The count query that only decided the filename and the separate licenses query are gone: two ids answer the filename, and the licenses are collected while streaming. Rows are fetched 20,000 at a time, and the per-row work is trimmed.
Minimum of the benchmark rounds on one machine. The fixed dataset has 100,000 images:
With
BENCHMARK_EXTRA_IMAGES=1000000the dataset has 1,100,000 images, and the same searches match more of them, except the collection:EXPLAIN ANALYZE DECLARE CURSORof the staff listing at 1,100,000 images takes 7.0 s with the defaultcursor_tuple_fractionand 1.0 s with 1.0.Summary by CodeRabbit