Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimized copyfile #37

Closed
wants to merge 6 commits into from
Closed

optimized copyfile #37

wants to merge 6 commits into from

Conversation

skshetry
Copy link
Member

No description provided.

@skshetry skshetry force-pushed the optimize-copyfile branch from 1b3ed2c to e035a50 Compare June 1, 2022 15:30
@skshetry
Copy link
Member Author

skshetry commented Jun 5, 2022

Okay, using sendfile in linux is a bit slower than using read/write, which is unexpected. It might be because of the small buffer size in OS (someone corroborates this). Using copy_file_range is much faster, at least in btrfs (need to test in ext4).

I am still unsure about why fcopyfile is slow in MacOS. Need further investigation.

In the future, we can do ficlone > copy_file_range > sendfile > read/write copy in userspace.

@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2022

Codecov Report

Merging #37 (ef91fd6) into main (d6606c9) will increase coverage by 0.94%.
The diff coverage is 73.80%.

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   45.42%   46.36%   +0.94%     
==========================================
  Files          44       46       +2     
  Lines        2435     2586     +151     
  Branches      296      323      +27     
==========================================
+ Hits         1106     1199      +93     
- Misses       1308     1363      +55     
- Partials       21       24       +3     
Impacted Files Coverage Δ
src/dvc_objects/fs/utils.py 44.53% <44.44%> (+2.61%) ⬆️
src/dvc_objects/fs/fastcopy.py 66.66% <66.66%> (ø)
tests/benchmarks/test_copy.py 88.88% <88.88%> (ø)
src/dvc_objects/fs/system.py 27.94% <0.00%> (-44.12%) ⬇️
src/dvc_objects/fs/callbacks.py 77.02% <0.00%> (+4.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6606c9...ef91fd6. Read the comment docs.

@skshetry skshetry force-pushed the optimize-copyfile branch from 2316a7d to ef91fd6 Compare June 6, 2022 12:37
@skshetry
Copy link
Member Author

skshetry commented Jun 7, 2022

Ran on btrfs filesystem. cc @dtrifiro @efiop

Note that the left side of the hypen is different copyfile strategies, where:

sendfile Uses linux's sendfile syscall
reflink Uses FICLONE/reflink
copy_file_range Uses copy_file_range syscall
fastcopy Chooses best option: platform-specific option first, fallbacks to read/write.
readinto Uses readinto to bytearray
shutil_copy Uses shutil.copyfile
read Uses read/write with 1MB buffer size
64k Uses read/write with 64k buffer size

The right side is the file size.

Benchmarks
------------------------------------------------------------------------------------------------------------------- benchmark: 150 tests -------------------------------------------------------------------------------------------------------------------
Name (time in us)                                    Min                        Max                       Mean                    StdDev                     Median                        IQR            Outliers         OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_sendfile[sendfile-1KB]                     104.2420 (1.0)             316.9160 (1.17)            132.9782 (1.10)            12.6870 (1.28)            129.8920 (1.09)              1.6605 (1.24)      204;693  7,520.0284 (0.91)       4477           1
test_sendfile[reflink-100MB]                    107.4650 (1.03)            275.4060 (1.01)            131.5661 (1.09)             9.9115 (1.0)             129.9460 (1.10)              1.3360 (1.0)       183;344  7,600.7425 (0.92)       4137           1
test_sendfile[copy_file_range-100KB]            108.0340 (1.04)            356.7440 (1.31)            127.8211 (1.06)            13.7578 (1.39)            128.8940 (1.09)             12.3510 (9.24)       190;69  7,823.4330 (0.94)       4101           1
test_sendfile[copy_file_range-100MB]            109.4640 (1.05)            312.7630 (1.15)            120.5902 (1.0)             13.2138 (1.33)            122.7775 (1.03)             13.7970 (10.33)      166;74  8,292.5490 (1.0)        3844           1
test_sendfile[copy_file_range-10KB]             109.8230 (1.05)            635.4210 (2.34)            126.7092 (1.05)            23.8793 (2.41)            118.6550 (1.0)               9.4083 (7.04)      265;284  7,892.0892 (0.95)       2949           1
test_sendfile[reflink-1MB]                      112.9910 (1.08)            331.8680 (1.22)            145.3437 (1.21)            13.8361 (1.40)            144.7875 (1.22)              2.2630 (1.69)     188;1212  6,880.2429 (0.83)       4596           1
test_sendfile[fastcopy-1KB]                     117.0230 (1.12)            381.4240 (1.40)            142.8680 (1.18)            33.4791 (3.38)            125.5250 (1.06)             32.1202 (24.04)     465;313  6,999.4659 (0.84)       2827           1
test_sendfile[fastcopy-10KB]                    118.3400 (1.14)            574.6800 (2.11)            139.8856 (1.16)            23.6936 (2.39)            137.1850 (1.16)             16.9420 (12.68)     168;153  7,148.6969 (0.86)       2817           1
test_sendfile[fastcopy-100MB]                   119.6370 (1.15)            381.7330 (1.40)            146.7969 (1.22)            28.1790 (2.84)            142.9505 (1.20)             31.6680 (23.70)     234;115  6,812.1318 (0.82)       2494           1
test_sendfile[copy_file_range-1MB]              119.8540 (1.15)            505.5630 (1.86)            136.2386 (1.13)            16.6932 (1.68)            131.6900 (1.11)              3.2337 (2.42)      450;604  7,340.0649 (0.89)       3653           1
test_sendfile[reflink-10MB]                     120.1120 (1.15)            315.4180 (1.16)            134.1551 (1.11)            13.1939 (1.33)            129.2250 (1.09)             11.4700 (8.59)      194;100  7,454.0581 (0.90)       4187           1
test_sendfile[copy_file_range-10MB]             120.8930 (1.16)            688.9960 (2.53)            137.1604 (1.14)            25.2877 (2.55)            131.5475 (1.11)              3.5345 (2.65)      119;842  7,290.7320 (0.88)       3804           1
test_sendfile[fastcopy-100KB]                   121.1880 (1.16)            495.6810 (1.82)            167.9851 (1.39)            43.6692 (4.41)            156.4150 (1.32)             48.3733 (36.21)     798;171  5,952.9106 (0.72)       3669           1
test_sendfile[1M-1KB]                           122.2960 (1.17)            633.4240 (2.33)            140.5569 (1.17)            22.2992 (2.25)            134.7440 (1.14)              9.4152 (7.05)        53;62  7,114.5579 (0.86)       1121           1
test_sendfile[reflink-100KB]                    125.0040 (1.20)            289.0810 (1.06)            145.8775 (1.21)            10.6826 (1.08)            144.1770 (1.22)              1.7000 (1.27)      159;280  6,855.0661 (0.83)       3477           1
test_sendfile[reflink-10KB]                     126.2490 (1.21)            623.4220 (2.29)            139.6797 (1.16)            14.8075 (1.49)            135.3290 (1.14)             10.3465 (7.74)       112;86  7,159.2389 (0.86)       3419           1
test_sendfile[copy_file_range-1KB]              126.6430 (1.21)            313.9750 (1.16)            160.5912 (1.33)            28.4780 (2.87)            163.8270 (1.38)             49.5212 (37.07)        61;1  6,226.9914 (0.75)        167           1
test_sendfile[100M-1KB]                         131.5360 (1.26)          1,006.4520 (3.70)            147.5570 (1.22)            38.5916 (3.89)            135.5940 (1.14)              7.7880 (5.83)      132;198  6,777.0418 (0.82)       1294           1
test_sendfile[128k-1KB]                         131.6530 (1.26)            650.5700 (2.39)            173.5006 (1.44)            35.3782 (3.57)            169.1480 (1.43)             30.4932 (22.82)      188;89  5,763.6687 (0.70)       1427           1
test_sendfile[fastcopy-1MB]                     134.4470 (1.29)            627.2400 (2.31)            177.9610 (1.48)            42.7793 (4.32)            161.7130 (1.36)             43.4090 (32.49)     479;196  5,619.2085 (0.68)       3104           1
test_sendfile[64k-1KB]                          134.9790 (1.29)          3,397.0240 (12.50)           160.3568 (1.33)            84.2574 (8.50)            146.3285 (1.23)             10.9430 (8.19)       20;302  6,236.0952 (0.75)       1650           1
test_sendfile[256k-1KB]                         137.0570 (1.31)            764.7870 (2.81)            169.5649 (1.41)            29.3828 (2.96)            161.4800 (1.36)              9.2410 (6.92)      194;251  5,897.4469 (0.71)       1426           1
test_sendfile[reflink-1KB]                      140.0760 (1.34)            324.5860 (1.19)            178.9071 (1.48)            35.5747 (3.59)            179.1080 (1.51)             60.3582 (45.18)        48;1  5,589.4936 (0.67)        133           1
test_sendfile[read-1KB]                         140.2470 (1.35)            374.3430 (1.38)            163.0689 (1.35)            29.0020 (2.93)            152.5950 (1.29)             27.6193 (20.67)     302;168  6,132.3756 (0.74)       2473           1
test_sendfile[4M-1KB]                           141.5740 (1.36)            715.3160 (2.63)            160.8491 (1.33)            38.7070 (3.91)            155.0635 (1.31)              4.5880 (3.43)       15;135  6,217.0077 (0.75)        406           1
test_sendfile[fastcopy-10MB]                    143.2280 (1.37)            572.7630 (2.11)            197.1655 (1.64)            49.2908 (4.97)            181.3030 (1.53)             65.7138 (49.19)      398;33  5,071.8809 (0.61)       1841           1
test_sendfile[512k-1KB]                         145.7740 (1.40)            814.5280 (3.00)            171.0797 (1.42)            55.7001 (5.62)            152.6120 (1.29)             24.1850 (18.10)       10;26  5,845.2282 (0.70)        234           1
test_sendfile[10M-1KB]                          153.2300 (1.47)            884.1130 (3.25)            179.8507 (1.49)            46.5416 (4.70)            159.5190 (1.34)             33.9055 (25.38)       84;55  5,560.1686 (0.67)        824           1
test_sendfile[shutil_copy-1KB]                  155.7170 (1.49)            349.4810 (1.29)            172.9835 (1.43)            17.7116 (1.79)            174.2650 (1.47)             17.3920 (13.02)     231;149  5,780.8969 (0.70)       3353           1
test_sendfile[readinto-1KB]                     156.5030 (1.50)            552.1580 (2.03)            219.3806 (1.82)            45.9455 (4.64)            211.0550 (1.78)             69.0090 (51.65)      297;10  4,558.2891 (0.55)       1063           1
test_sendfile[copy_file_range-1GB]              161.6340 (1.55)            321.4100 (1.18)            170.2703 (1.41)            13.7138 (1.38)            164.1610 (1.38)             14.9705 (11.21)       33;17  5,873.0160 (0.71)        635           1
test_sendfile[fastcopy-1GB]                     168.4910 (1.62)            387.2880 (1.42)            191.2885 (1.59)            16.1059 (1.62)            189.3205 (1.60)              3.1900 (2.39)     870;1158  5,227.7055 (0.63)       3220           1
test_sendfile[reflink-1GB]                      189.4920 (1.82)            271.8100 (1.0)             197.8796 (1.64)            10.0421 (1.01)            195.2310 (1.65)              1.5025 (1.12)        10;18  5,053.5771 (0.61)        129           1
test_sendfile[100M-10KB]                        202.7090 (1.94)          1,875.6260 (6.90)            275.6304 (2.29)           105.1846 (10.61)           250.3355 (2.11)             20.1180 (15.06)       24;60  3,628.0473 (0.44)        430           1
test_sendfile[sendfile-10KB]                    207.2180 (1.99)          2,547.8910 (9.37)            240.6230 (2.00)            91.6517 (9.25)            222.4210 (1.87)              7.4860 (5.60)       49;150  4,155.8780 (0.50)        922           1
test_sendfile[shutil_copy-10KB]                 224.4560 (2.15)            499.6700 (1.84)            278.4038 (2.31)            47.4416 (4.79)            275.5540 (2.32)             33.1692 (24.83)       26;12  3,591.9047 (0.43)        129           1
test_sendfile[256k-10KB]                        234.2160 (2.25)          2,939.7450 (10.82)           334.9096 (2.78)           230.5207 (23.26)           277.7380 (2.34)             57.3513 (42.93)        2;26  2,985.8804 (0.36)        153           1
test_sendfile[128k-10KB]                        240.0310 (2.30)            547.9860 (2.02)            300.2040 (2.49)            92.9497 (9.38)            254.5220 (2.15)             39.2968 (29.41)       22;23  3,331.0678 (0.40)        123           1
test_sendfile[4M-10KB]                          243.0280 (2.33)            639.4580 (2.35)            283.3208 (2.35)            39.7921 (4.01)            272.0300 (2.29)             31.6943 (23.72)       32;22  3,529.5674 (0.43)        357           1
test_sendfile[512k-10KB]                        243.2630 (2.33)          3,551.9690 (13.07)           393.4684 (3.26)           442.0095 (44.60)           266.3000 (2.24)             33.7370 (25.25)       33;77  2,541.5001 (0.31)        528           1
test_sendfile[reflink-2GB]                      244.4070 (2.34)            363.3960 (1.34)            253.7722 (2.10)            12.1449 (1.23)            248.5480 (2.09)              3.3523 (2.51)      473;604  3,940.5414 (0.48)       2725           1
test_sendfile[copy_file_range-2GB]              250.2750 (2.40)            641.1690 (2.36)            273.2328 (2.27)            15.3867 (1.55)            275.6450 (2.32)              2.7130 (2.03)      777;936  3,659.8830 (0.44)       2936           1
test_sendfile[1M-10KB]                          251.5820 (2.41)            582.5600 (2.14)            304.1135 (2.52)            68.1269 (6.87)            278.0810 (2.34)             51.4090 (38.48)       12;10  3,288.2458 (0.40)        114           1
test_sendfile[read-10KB]                        251.9430 (2.42)            841.4980 (3.10)            336.5215 (2.79)           107.6708 (10.86)           292.9770 (2.47)            101.9960 (76.34)        19;9  2,971.5783 (0.36)        114           1
test_sendfile[64k-10KB]                         252.7180 (2.42)            968.7080 (3.56)            363.9052 (3.02)           130.4601 (13.16)           299.7635 (2.53)            175.9195 (131.68)       25;2  2,747.9686 (0.33)        116           1
test_sendfile[10M-10KB]                         275.3800 (2.64)            704.1580 (2.59)            337.5673 (2.80)            90.0291 (9.08)            298.6040 (2.52)             39.1185 (29.28)       29;33  2,962.3719 (0.36)        227           1
test_sendfile[fastcopy-2GB]                     285.8200 (2.74)            634.2100 (2.33)            337.5199 (2.80)            46.0254 (4.64)            322.0065 (2.71)             81.2100 (60.79)       391;9  2,962.7880 (0.36)       1186           1
test_sendfile[readinto-10KB]                    296.9900 (2.85)            842.9260 (3.10)            422.9017 (3.51)           133.4261 (13.46)           369.1345 (3.11)             99.9880 (74.84)       18;15  2,364.6159 (0.29)        116           1
test_sendfile[sendfile-100KB]                   350.1200 (3.36)          5,892.8330 (21.68)           692.7103 (5.74)           182.6340 (18.43)           652.2210 (5.50)             68.9905 (51.64)      67;154  1,443.6049 (0.17)       1289           1
test_sendfile[reflink-5GB]                      437.8250 (4.20)          1,132.8820 (4.17)            460.6803 (3.82)            18.9734 (1.91)            456.4405 (3.85)              3.1735 (2.38)      137;346  2,170.7025 (0.26)       1924           1
test_sendfile[1M-100KB]                         440.3240 (4.22)         21,148.5440 (77.81)           827.2958 (6.86)           685.6812 (69.18)           745.1215 (6.28)             63.9050 (47.83)      15;134  1,208.7576 (0.15)        958           1
test_sendfile[256k-100KB]                       460.3450 (4.42)          5,679.9040 (20.90)           776.5718 (6.44)           210.4849 (21.24)           732.6680 (6.17)             63.2783 (47.36)      44;121  1,287.7110 (0.16)        843           1
test_sendfile[128k-100KB]                       472.5820 (4.53)          2,942.9840 (10.83)           803.1411 (6.66)           209.5748 (21.14)           743.1300 (6.26)             52.3405 (39.18)      59;147  1,245.1112 (0.15)        912           1
test_sendfile[100M-100KB]                       499.7090 (4.79)          3,011.8320 (11.08)           880.0202 (7.30)           227.4388 (22.95)           823.1750 (6.94)             77.2740 (57.84)      49;147  1,136.3376 (0.14)        999           1
test_sendfile[read-100KB]                       500.2990 (4.80)          3,132.0810 (11.52)           870.1818 (7.22)           221.1126 (22.31)           809.5290 (6.82)            139.7600 (104.61)      50;36  1,149.1851 (0.14)        833           1
test_sendfile[512k-100KB]                       502.0550 (4.82)          4,264.1100 (15.69)         1,015.7472 (8.42)           406.2233 (40.99)           919.7500 (7.75)            268.3213 (200.84)      34;29    984.4969 (0.12)        447           1
test_sendfile[shutil_copy-100KB]                517.0040 (4.96)          2,305.2140 (8.48)            799.3650 (6.63)           115.3712 (11.64)           759.4890 (6.40)             91.5270 (68.51)     199;131  1,250.9929 (0.15)       1193           1
test_sendfile[fastcopy-5GB]                     535.4470 (5.14)          1,277.7900 (4.70)            587.7048 (4.87)            60.7119 (6.13)            591.5440 (4.99)             60.7800 (45.49)      151;37  1,701.5346 (0.21)       1414           1
test_sendfile[copy_file_range-5GB]              547.9210 (5.26)            765.9400 (2.82)            576.6236 (4.78)            28.8011 (2.91)            558.1240 (4.70)             47.6953 (35.70)      164;10  1,734.2334 (0.21)       1449           1
test_sendfile[10M-100KB]                        551.2960 (5.29)          3,018.3140 (11.10)           990.8926 (8.22)           224.4403 (22.64)           933.8110 (7.87)            148.1440 (110.89)      45;31  1,009.1911 (0.12)        710           1
test_sendfile[64k-100KB]                        552.1530 (5.30)          2,925.2860 (10.76)           893.3651 (7.41)           200.7759 (20.26)           825.2120 (6.95)             88.4132 (66.18)      74;126  1,119.3631 (0.13)        817           1
test_sendfile[4M-100KB]                         552.6290 (5.30)          3,059.7400 (11.26)           972.0162 (8.06)           211.8740 (21.38)           920.1985 (7.76)            153.1735 (114.65)      50;38  1,028.7894 (0.12)        688           1
test_sendfile[readinto-100KB]                   590.5140 (5.66)          3,488.2880 (12.83)           948.4419 (7.87)           281.8375 (28.44)           908.4565 (7.66)            243.4930 (182.26)      79;30  1,054.3609 (0.13)        716           1
test_sendfile[copy_file_range-10GB]           1,196.5110 (11.48)         1,371.4040 (5.05)          1,215.3845 (10.08)           23.4081 (2.36)          1,208.4880 (10.18)            12.9630 (9.70)        16;17    822.7849 (0.10)        282           1
test_sendfile[fastcopy-10GB]                  1,458.6220 (13.99)         1,924.1810 (7.08)          1,577.0737 (13.08)           83.4757 (8.42)          1,536.7240 (12.95)           145.1262 (108.63)      175;4    634.0858 (0.08)        555           1
test_sendfile[reflink-10GB]                   1,803.9340 (17.31)         1,965.9220 (7.23)          1,864.7031 (15.46)           15.8234 (1.60)          1,862.2490 (15.69)            14.9308 (11.18)       94;28    536.2784 (0.06)        515           1
test_sendfile[readinto-1MB]                   2,043.3290 (19.60)         7,658.2650 (28.18)         5,460.1949 (45.28)          630.3618 (63.60)         5,369.6130 (45.25)           588.8405 (440.75)      43;16    183.1436 (0.02)        203           1
test_sendfile[sendfile-1MB]                   2,085.0980 (20.00)         6,745.5030 (24.82)         5,256.3420 (43.59)          327.0422 (33.00)         5,212.6640 (43.93)           354.4537 (265.31)       26;2    190.2464 (0.02)        227           1
test_sendfile[128k-1MB]                       2,428.8580 (23.30)         7,760.8490 (28.55)         5,364.1015 (44.48)          624.2757 (62.99)         5,443.6800 (45.88)           697.0263 (521.73)      61;12    186.4245 (0.02)        211           1
test_sendfile[256k-1MB]                       2,457.0510 (23.57)        11,019.8030 (40.54)         5,707.1786 (47.33)        1,053.7069 (106.31)        5,484.7920 (46.22)           437.6222 (327.56)      39;42    175.2179 (0.02)        207           1
test_sendfile[1M-1MB]                         2,472.6150 (23.72)         9,447.1590 (34.76)         5,517.7441 (45.76)          766.0526 (77.29)         5,451.9160 (45.95)           646.4305 (483.86)      56;18    181.2335 (0.02)        189           1
test_sendfile[100M-1MB]                       2,867.1130 (27.50)         7,728.6480 (28.43)         5,454.1424 (45.23)          706.7680 (71.31)         5,537.1010 (46.67)         1,011.2625 (756.93)       64;6    183.3469 (0.02)        192           1
test_sendfile[4M-1MB]                         2,896.7210 (27.79)        10,083.4720 (37.10)         6,425.3989 (53.28)          724.5125 (73.10)         6,379.3050 (53.76)           661.0330 (494.79)      41;14    155.6324 (0.02)        202           1
test_sendfile[shutil_copy-1MB]                2,897.8230 (27.80)         8,299.4550 (30.53)         6,241.1154 (51.75)          431.5376 (43.54)         6,268.7185 (52.83)           415.7000 (311.15)       33;6    160.2278 (0.02)        190           1
test_sendfile[64k-1MB]                        2,969.2450 (28.48)         7,766.7470 (28.57)         5,809.5900 (48.18)          734.7574 (74.13)         5,985.7670 (50.45)           756.8520 (566.51)       63;4    172.1292 (0.02)        207           1
test_sendfile[10M-1MB]                        2,972.7300 (28.52)        11,065.2090 (40.71)         6,720.6108 (55.73)          681.7736 (68.79)         6,534.0310 (55.07)           370.6700 (277.45)      22;23    148.7960 (0.02)        174           1
test_sendfile[512k-1MB]                       3,285.9920 (31.52)        10,359.3430 (38.11)         6,160.0196 (51.08)          846.1259 (85.37)         5,905.1160 (49.77)           517.6110 (387.43)      21;21    162.3371 (0.02)        160           1
test_sendfile[read-1MB]                       3,461.2640 (33.20)         8,901.6540 (32.75)         6,719.0203 (55.72)          777.2082 (78.41)         6,505.0460 (54.82)           920.3400 (688.88)       36;5    148.8312 (0.02)        149           1
test_sendfile[readinto-10MB]                 22,402.3340 (214.91)       33,085.0170 (121.72)       29,608.9138 (245.53)       1,917.8025 (193.49)       29,578.2100 (249.28)        2,560.0885 (>1000.0)      12;1     33.7736 (0.00)         43           1
test_sendfile[64k-10MB]                      22,503.5180 (215.88)       31,952.1920 (117.55)       28,538.2954 (236.66)       1,342.1373 (135.41)       28,423.0460 (239.54)        1,136.6350 (850.78)        9;3     35.0406 (0.00)         49           1
test_sendfile[512k-10MB]                     22,669.9650 (217.47)       40,030.4290 (147.27)       33,282.3218 (276.00)       2,888.1862 (291.40)       32,697.3055 (275.57)        3,375.4985 (>1000.0)       6;1     30.0460 (0.00)         36           1
test_sendfile[256k-10MB]                     22,791.8960 (218.64)       35,210.0910 (129.54)       30,494.7610 (252.88)       1,905.2643 (192.23)       30,360.2380 (255.87)        2,060.5215 (>1000.0)       9;2     32.7925 (0.00)         44           1
test_sendfile[128k-10MB]                     23,463.6050 (225.09)       39,696.5420 (146.05)       30,923.6914 (256.44)       2,568.4797 (259.14)       30,379.9210 (256.04)        3,390.5528 (>1000.0)      10;2     32.3377 (0.00)         47           1
test_sendfile[1M-10MB]                       23,556.2470 (225.98)       35,381.4960 (130.17)       30,393.4772 (252.04)       2,199.6154 (221.93)       30,171.5055 (254.28)        3,001.8010 (>1000.0)      11;1     32.9018 (0.00)         46           1
test_sendfile[100M-10MB]                     23,784.7620 (228.17)       34,274.9340 (126.10)       29,069.0829 (241.06)       1,816.1063 (183.23)       29,174.8305 (245.88)        2,227.5420 (>1000.0)      12;2     34.4008 (0.00)         44           1
test_sendfile[sendfile-10MB]                 24,955.6800 (239.40)       34,286.3460 (126.14)       28,328.3275 (234.91)       1,984.4385 (200.22)       28,005.5835 (236.03)        2,161.5150 (>1000.0)       8;3     35.3004 (0.00)         42           1
test_sendfile[read-10MB]                     25,724.4450 (246.78)       35,657.0360 (131.18)       31,777.5357 (263.52)       2,303.4521 (232.40)       31,706.3520 (267.21)        3,674.2340 (>1000.0)      12;0     31.4688 (0.00)         39           1
test_sendfile[shutil_copy-10MB]              26,321.6430 (252.51)       34,062.7460 (125.32)       28,985.1021 (240.36)       1,546.4629 (156.03)       28,636.6660 (241.34)        1,637.6740 (>1000.0)      12;1     34.5005 (0.00)         40           1
test_sendfile[4M-10MB]                       27,241.1660 (261.33)       39,965.6040 (147.04)       33,407.7217 (277.04)       2,437.5400 (245.93)       33,467.1310 (282.05)        2,797.3108 (>1000.0)      12;3     29.9332 (0.00)         41           1
test_sendfile[10M-10MB]                      28,204.6360 (270.57)       35,632.7290 (131.09)       31,731.0947 (263.13)       1,811.0827 (182.73)       31,616.8620 (266.46)        2,436.0510 (>1000.0)      12;0     31.5148 (0.00)         38           1
test_sendfile[sendfile-100MB]               238,978.8750 (>1000.0)     277,516.1290 (>1000.0)     255,219.6860 (>1000.0)     14,175.1609 (>1000.0)     253,873.2660 (>1000.0)      15,438.3880 (>1000.0)       2;0      3.9182 (0.00)          5           1
test_sendfile[readinto-100MB]               241,907.6720 (>1000.0)     263,303.8630 (968.71)      252,040.4162 (>1000.0)      7,727.7172 (779.67)      252,063.9800 (>1000.0)       8,471.4252 (>1000.0)       2;0      3.9676 (0.00)          5           1
test_sendfile[100M-100MB]                   243,241.4060 (>1000.0)     262,757.4020 (966.70)      255,582.5534 (>1000.0)      8,526.1152 (860.23)      259,987.1440 (>1000.0)      13,580.6588 (>1000.0)       1;0      3.9126 (0.00)          5           1
test_sendfile[shutil_copy-100MB]            243,592.3670 (>1000.0)     264,986.9610 (974.90)      252,452.0992 (>1000.0)      8,117.5950 (819.01)      250,352.3430 (>1000.0)      10,358.9523 (>1000.0)       2;0      3.9611 (0.00)          5           1
test_sendfile[512k-100MB]                   250,130.0120 (>1000.0)     299,330.5960 (>1000.0)     273,903.3400 (>1000.0)     21,877.6739 (>1000.0)     279,448.4080 (>1000.0)      39,261.6485 (>1000.0)       2;0      3.6509 (0.00)          5           1
test_sendfile[read-100MB]                   254,233.1570 (>1000.0)     308,052.2270 (>1000.0)     268,781.1080 (>1000.0)     22,426.6014 (>1000.0)     262,639.5110 (>1000.0)      20,771.7488 (>1000.0)       1;1      3.7205 (0.00)          5           1
test_sendfile[256k-100MB]                   254,290.0310 (>1000.0)     271,112.5530 (997.43)      260,811.9644 (>1000.0)      7,663.0603 (773.15)      256,188.6780 (>1000.0)      12,725.3635 (>1000.0)       1;0      3.8342 (0.00)          5           1
test_sendfile[64k-100MB]                    255,381.5060 (>1000.0)     284,264.4500 (>1000.0)     271,835.0380 (>1000.0)     13,950.2207 (>1000.0)     277,257.9990 (>1000.0)      26,278.3748 (>1000.0)       1;0      3.6787 (0.00)          5           1
test_sendfile[128k-100MB]                   255,494.4770 (>1000.0)     276,864.9700 (>1000.0)     266,082.2526 (>1000.0)      8,689.0835 (876.67)      266,112.2310 (>1000.0)      14,442.4760 (>1000.0)       2;0      3.7582 (0.00)          5           1
test_sendfile[1M-100MB]                     256,321.5530 (>1000.0)     275,379.2910 (>1000.0)     267,057.5810 (>1000.0)      8,393.7661 (846.87)      267,707.5240 (>1000.0)      15,120.3648 (>1000.0)       1;0      3.7445 (0.00)          5           1
test_sendfile[4M-100MB]                     272,857.4280 (>1000.0)     294,565.5420 (>1000.0)     281,321.8414 (>1000.0)      8,042.2476 (811.41)      279,474.4250 (>1000.0)       7,537.2375 (>1000.0)       2;0      3.5546 (0.00)          5           1
test_sendfile[10M-100MB]                    277,625.1000 (>1000.0)     296,928.1470 (>1000.0)     289,515.8280 (>1000.0)      7,667.6586 (773.61)      289,484.7540 (>1000.0)      10,505.1375 (>1000.0)       1;0      3.4540 (0.00)          5           1
test_sendfile[readinto-1GB]               2,084,084.5020 (>1000.0)   2,438,398.4650 (>1000.0)   2,197,301.0592 (>1000.0)    142,138.6919 (>1000.0)   2,134,839.8380 (>1000.0)     154,188.8320 (>1000.0)       1;0      0.4551 (0.00)          5           1
test_sendfile[sendfile-1GB]               2,172,968.0860 (>1000.0)   2,457,547.8090 (>1000.0)   2,272,466.5044 (>1000.0)    108,271.1914 (>1000.0)   2,250,076.8420 (>1000.0)      87,493.9055 (>1000.0)       1;1      0.4401 (0.00)          5           1
test_sendfile[read-1GB]                   2,195,911.3830 (>1000.0)   2,558,438.0390 (>1000.0)   2,311,477.1188 (>1000.0)    152,551.9031 (>1000.0)   2,242,994.1520 (>1000.0)     207,180.3455 (>1000.0)       1;0      0.4326 (0.00)          5           1
test_sendfile[shutil_copy-1GB]            2,221,805.6810 (>1000.0)   2,536,153.0550 (>1000.0)   2,357,506.8376 (>1000.0)    127,121.2875 (>1000.0)   2,377,585.5010 (>1000.0)     194,392.5967 (>1000.0)       2;0      0.4242 (0.00)          5           1
test_sendfile[256k-1GB]                   2,301,720.2500 (>1000.0)   2,706,682.1310 (>1000.0)   2,433,506.5300 (>1000.0)    160,333.1203 (>1000.0)   2,370,562.8400 (>1000.0)     166,585.5620 (>1000.0)       1;0      0.4109 (0.00)          5           1
test_sendfile[64k-1GB]                    2,317,294.9720 (>1000.0)   2,656,156.6610 (>1000.0)   2,406,214.6318 (>1000.0)    141,730.0028 (>1000.0)   2,360,196.5000 (>1000.0)     122,083.1162 (>1000.0)       1;1      0.4156 (0.00)          5           1
test_sendfile[1M-1GB]                     2,335,081.0950 (>1000.0)   2,763,514.4360 (>1000.0)   2,455,212.3660 (>1000.0)    182,511.2113 (>1000.0)   2,354,265.1890 (>1000.0)     211,922.6413 (>1000.0)       1;0      0.4073 (0.00)          5           1
test_sendfile[100M-1GB]                   2,340,037.7660 (>1000.0)   2,661,528.2750 (>1000.0)   2,424,672.7804 (>1000.0)    138,408.1157 (>1000.0)   2,344,004.9000 (>1000.0)     149,895.8130 (>1000.0)       1;0      0.4124 (0.00)          5           1
test_sendfile[128k-1GB]                   2,375,681.3030 (>1000.0)   2,742,343.1690 (>1000.0)   2,471,148.9316 (>1000.0)    154,986.1603 (>1000.0)   2,397,488.2120 (>1000.0)     147,668.2485 (>1000.0)       1;0      0.4047 (0.00)          5           1
test_sendfile[4M-1GB]                     2,396,454.5620 (>1000.0)   2,902,831.8540 (>1000.0)   2,611,781.5068 (>1000.0)    183,855.0553 (>1000.0)   2,581,110.3190 (>1000.0)     176,107.4457 (>1000.0)       2;0      0.3829 (0.00)          5           1
test_sendfile[512k-1GB]                   2,411,071.6980 (>1000.0)   3,296,702.7210 (>1000.0)   2,785,802.0530 (>1000.0)    333,554.8546 (>1000.0)   2,697,980.2560 (>1000.0)     419,019.8048 (>1000.0)       2;0      0.3590 (0.00)          5           1
test_sendfile[10M-1GB]                    2,693,982.2440 (>1000.0)   3,122,073.6100 (>1000.0)   2,844,831.3906 (>1000.0)    163,971.6374 (>1000.0)   2,797,832.3510 (>1000.0)     160,766.6325 (>1000.0)       1;0      0.3515 (0.00)          5           1
test_sendfile[sendfile-2GB]               4,039,492.1770 (>1000.0)   4,602,809.4740 (>1000.0)   4,334,962.1604 (>1000.0)    275,479.8902 (>1000.0)   4,422,167.7620 (>1000.0)     530,731.3870 (>1000.0)       2;0      0.2307 (0.00)          5           1
test_sendfile[readinto-2GB]               4,048,891.7170 (>1000.0)   4,836,991.9390 (>1000.0)   4,395,800.1074 (>1000.0)    332,154.2399 (>1000.0)   4,463,418.9110 (>1000.0)     546,611.3460 (>1000.0)       2;0      0.2275 (0.00)          5           1
test_sendfile[read-2GB]                   4,064,324.7630 (>1000.0)   4,764,526.5380 (>1000.0)   4,380,050.2234 (>1000.0)    276,851.8677 (>1000.0)   4,339,180.0800 (>1000.0)     428,333.3127 (>1000.0)       2;0      0.2283 (0.00)          5           1
test_sendfile[256k-2GB]                   4,217,057.9570 (>1000.0)   5,192,607.2780 (>1000.0)   4,691,862.5322 (>1000.0)    389,567.1814 (>1000.0)   4,705,193.3560 (>1000.0)     626,191.4767 (>1000.0)       2;0      0.2131 (0.00)          5           1
test_sendfile[shutil_copy-2GB]            4,242,948.6450 (>1000.0)   5,070,357.0800 (>1000.0)   4,646,238.7042 (>1000.0)    297,624.6954 (>1000.0)   4,633,990.4480 (>1000.0)     321,166.1833 (>1000.0)       2;0      0.2152 (0.00)          5           1
test_sendfile[64k-2GB]                    4,305,994.3420 (>1000.0)   5,154,078.1800 (>1000.0)   4,661,551.1544 (>1000.0)    330,295.7698 (>1000.0)   4,704,568.2530 (>1000.0)     447,596.1327 (>1000.0)       2;0      0.2145 (0.00)          5           1
test_sendfile[100M-2GB]                   4,339,214.6010 (>1000.0)   5,246,863.8760 (>1000.0)   4,665,614.3608 (>1000.0)    357,585.2784 (>1000.0)   4,650,153.7960 (>1000.0)     434,185.2415 (>1000.0)       1;0      0.2143 (0.00)          5           1
test_sendfile[1M-2GB]                     4,443,393.3120 (>1000.0)   5,256,025.3090 (>1000.0)   4,717,370.3002 (>1000.0)    311,882.9069 (>1000.0)   4,635,786.5670 (>1000.0)     225,745.7635 (>1000.0)       1;1      0.2120 (0.00)          5           1
test_sendfile[128k-2GB]                   4,459,354.2150 (>1000.0)   5,315,988.5380 (>1000.0)   4,802,164.5164 (>1000.0)    320,953.3195 (>1000.0)   4,690,019.1490 (>1000.0)     349,161.8328 (>1000.0)       2;0      0.2082 (0.00)          5           1
test_sendfile[4M-2GB]                     4,604,105.3350 (>1000.0)   5,550,289.4550 (>1000.0)   4,952,977.3698 (>1000.0)    404,491.0474 (>1000.0)   4,801,017.9320 (>1000.0)     644,883.2263 (>1000.0)       1;0      0.2019 (0.00)          5           1
test_sendfile[512k-2GB]                   4,649,405.5650 (>1000.0)   5,520,226.1960 (>1000.0)   5,003,789.0304 (>1000.0)    317,693.8801 (>1000.0)   4,929,602.8910 (>1000.0)     265,830.1723 (>1000.0)       2;0      0.1998 (0.00)          5           1
test_sendfile[10M-2GB]                    4,909,324.1120 (>1000.0)   5,845,645.2680 (>1000.0)   5,389,101.1308 (>1000.0)    372,332.4266 (>1000.0)   5,500,372.9250 (>1000.0)     568,903.6238 (>1000.0)       2;0      0.1856 (0.00)          5           1
test_sendfile[read-5GB]                   9,357,449.1680 (>1000.0)  16,897,070.4200 (>1000.0)  11,284,498.5594 (>1000.0)  3,157,751.1129 (>1000.0)   9,951,985.4430 (>1000.0)   2,263,143.9330 (>1000.0)       1;1      0.0886 (0.00)          5           1
test_sendfile[readinto-5GB]               9,445,023.4720 (>1000.0)  17,872,727.3640 (>1000.0)  11,171,058.4458 (>1000.0)  3,746,589.6734 (>1000.0)   9,537,303.1690 (>1000.0)   2,164,445.4980 (>1000.0)       1;1      0.0895 (0.00)          5           1
test_sendfile[shutil_copy-5GB]            9,640,802.1410 (>1000.0)  16,728,977.9280 (>1000.0)  11,937,492.4560 (>1000.0)  2,837,251.8270 (>1000.0)  10,651,714.0990 (>1000.0)   3,106,447.8137 (>1000.0)       1;0      0.0838 (0.00)          5           1
test_sendfile[sendfile-5GB]               9,907,547.1160 (>1000.0)  16,135,911.2740 (>1000.0)  11,603,215.2956 (>1000.0)  2,568,631.0144 (>1000.0)  10,609,786.1680 (>1000.0)   2,122,839.9405 (>1000.0)       1;1      0.0862 (0.00)          5           1
test_sendfile[128k-5GB]                  10,162,250.9310 (>1000.0)  17,132,536.4840 (>1000.0)  11,821,291.5056 (>1000.0)  2,987,507.3059 (>1000.0)  10,779,588.6990 (>1000.0)   2,269,236.6732 (>1000.0)       1;1      0.0846 (0.00)          5           1
test_sendfile[256k-5GB]                  10,214,295.2970 (>1000.0)  17,349,377.6920 (>1000.0)  12,060,984.8906 (>1000.0)  2,980,896.6878 (>1000.0)  10,944,697.7560 (>1000.0)   2,276,426.9297 (>1000.0)       1;1      0.0829 (0.00)          5           1
test_sendfile[100M-5GB]                  10,233,556.0780 (>1000.0)  17,304,591.6880 (>1000.0)  11,801,363.5548 (>1000.0)  3,087,528.9791 (>1000.0)  10,308,500.0710 (>1000.0)   2,212,878.0127 (>1000.0)       1;1      0.0847 (0.00)          5           1
test_sendfile[1M-5GB]                    10,261,936.1050 (>1000.0)  17,443,812.2830 (>1000.0)  11,905,063.1574 (>1000.0)  3,106,039.3581 (>1000.0)  10,488,208.8620 (>1000.0)   2,181,835.7453 (>1000.0)       1;1      0.0840 (0.00)          5           1
test_sendfile[64k-5GB]                   10,278,696.4930 (>1000.0)  17,209,748.2750 (>1000.0)  11,869,615.7080 (>1000.0)  2,991,941.5507 (>1000.0)  10,625,233.2120 (>1000.0)   2,019,809.3850 (>1000.0)       1;1      0.0842 (0.00)          5           1
test_sendfile[4M-5GB]                    10,805,360.7180 (>1000.0)  17,874,774.7910 (>1000.0)  12,450,534.6660 (>1000.0)  3,043,385.2424 (>1000.0)  11,088,440.1520 (>1000.0)   2,169,313.2275 (>1000.0)       1;1      0.0803 (0.00)          5           1
test_sendfile[10M-5GB]                   11,670,241.1530 (>1000.0)  19,383,685.0980 (>1000.0)  13,525,095.2744 (>1000.0)  3,289,807.6597 (>1000.0)  12,355,572.8530 (>1000.0)   2,330,313.4978 (>1000.0)       1;1      0.0739 (0.00)          5           1
test_sendfile[512k-5GB]                  12,005,590.7450 (>1000.0)  19,128,504.5290 (>1000.0)  13,814,044.0764 (>1000.0)  2,993,148.6927 (>1000.0)  12,636,942.7840 (>1000.0)   2,283,054.2360 (>1000.0)       1;1      0.0724 (0.00)          5           1
test_sendfile[readinto-10GB]             18,360,306.7230 (>1000.0)  23,403,912.7400 (>1000.0)  20,631,316.2004 (>1000.0)  1,840,113.1000 (>1000.0)  20,183,679.8710 (>1000.0)   2,008,990.8013 (>1000.0)       2;0      0.0485 (0.00)          5           1
test_sendfile[read-10GB]                 18,787,251.5110 (>1000.0)  29,366,726.5930 (>1000.0)  23,079,894.5364 (>1000.0)  4,000,887.5236 (>1000.0)  21,984,740.9760 (>1000.0)   4,888,326.4455 (>1000.0)       2;0      0.0433 (0.00)          5           1
test_sendfile[sendfile-10GB]             20,615,333.8530 (>1000.0)  35,111,304.8550 (>1000.0)  26,461,511.9928 (>1000.0)  5,687,249.6891 (>1000.0)  25,769,695.2140 (>1000.0)   8,083,064.7495 (>1000.0)       2;0      0.0378 (0.00)          5           1
test_sendfile[512k-10GB]                 20,790,442.7460 (>1000.0)  37,829,539.8670 (>1000.0)  29,238,425.2018 (>1000.0)  7,604,111.2355 (>1000.0)  32,489,795.5750 (>1000.0)  13,120,041.9745 (>1000.0)       2;0      0.0342 (0.00)          5           1
test_sendfile[128k-10GB]                 21,169,657.2360 (>1000.0)  37,073,195.6630 (>1000.0)  28,647,534.2654 (>1000.0)  5,939,180.9971 (>1000.0)  28,936,042.4870 (>1000.0)   7,849,490.7950 (>1000.0)       2;0      0.0349 (0.00)          5           1
test_sendfile[100M-10GB]                 21,546,831.9250 (>1000.0)  35,043,154.3050 (>1000.0)  27,499,401.7000 (>1000.0)  5,554,078.6022 (>1000.0)  27,396,776.9000 (>1000.0)   9,176,912.7320 (>1000.0)       2;0      0.0364 (0.00)          5           1
test_sendfile[10M-10GB]                  22,408,545.6970 (>1000.0)  37,042,167.8930 (>1000.0)  28,490,839.1416 (>1000.0)  6,290,211.3303 (>1000.0)  26,939,009.3830 (>1000.0)  10,798,681.9682 (>1000.0)       1;0      0.0351 (0.00)          5           1
test_sendfile[64k-10GB]                  24,160,339.9930 (>1000.0)  30,882,230.6680 (>1000.0)  27,417,373.7156 (>1000.0)  2,537,887.4817 (>1000.0)  26,892,086.3120 (>1000.0)   3,462,782.7750 (>1000.0)       2;0      0.0365 (0.00)          5           1
test_sendfile[shutil_copy-10GB]          25,271,964.3030 (>1000.0)  33,226,224.8010 (>1000.0)  28,121,369.0896 (>1000.0)  3,577,515.5941 (>1000.0)  25,863,641.0220 (>1000.0)   5,650,297.2780 (>1000.0)       1;0      0.0356 (0.00)          5           1
test_sendfile[4M-10GB]                   27,274,128.1450 (>1000.0)  37,503,054.6340 (>1000.0)  31,746,388.3432 (>1000.0)  3,696,685.6376 (>1000.0)  31,686,060.0280 (>1000.0)   3,487,230.4380 (>1000.0)       2;0      0.0315 (0.00)          5           1
test_sendfile[256k-10GB]                 27,907,711.2010 (>1000.0)  35,584,043.6640 (>1000.0)  32,093,873.4396 (>1000.0)  3,120,314.0876 (>1000.0)  32,565,372.0160 (>1000.0)   5,099,770.7735 (>1000.0)       2;0      0.0312 (0.00)          5           1
test_sendfile[1M-10GB]                   28,810,615.8010 (>1000.0)  39,985,785.4510 (>1000.0)  33,567,745.7442 (>1000.0)  4,279,029.8136 (>1000.0)  34,193,442.0050 (>1000.0)   5,479,815.8715 (>1000.0)       2;0      0.0298 (0.00)          5           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@skshetry skshetry closed this Jun 8, 2022
@skshetry skshetry deleted the optimize-copyfile branch June 8, 2022 16:06
@efiop
Copy link
Contributor

efiop commented Jun 8, 2022

@skshetry Could you sum up your research please? You mentioned it during our calls, but it would be great to have a short summary here.

@skshetry
Copy link
Member Author

skshetry commented Jun 14, 2022

Summary:

  1. sendfile is not fast as I thought it'd be. Kernel pipe size is limited to 64k.
  2. fcopyfile is not fast either.
  3. Using a large buffer is faster than sendfile/fcopyfile.
  4. But not that large: 1MB seems to be optimal.
  5. Using copy_file_range might improve performance for NFS and CoW filesystems, as it will provide the opportunity to do server-side copy or clone to the kernel. For CoW filesystems, we already use reflinks. For NFS, we could use copy_file_range.
  6. readinto is faster if you have warm cache. See bpo-33671: efficient zero-copy for shutil.copy* functions (Linux, OSX and Win) python/cpython#7160 (comment).

Not tested: Windows OS CopyFileEx syscalls, ext4/ReFS Windows, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants