• Russ Cox's avatar
    crypto/tls: adjust dynamic record sizes to grow arithmetically · fa3543e3
    Russ Cox authored
    The current code, introduced after Go 1.6 to improve latency on
    low-bandwidth connections, sends 1 kB packets until 1 MB has been sent,
    and then sends 16 kB packets (the maximum record size).
    
    Unfortunately this decreases throughput for 1-16 MB responses by 20% or so.
    
    Following discussion on #15713, change cutoff to 128 kB sent
    and also grow the size allowed for successive packets:
    1 kB, 2 kB, 3 kB, ..., 15 kB, 16 kB.
    This fixes the throughput problems: the overhead is now closer to 2%.
    
    I hope this still helps with latency but I don't have a great way to test it.
    At the least, it's not worse than Go 1.6.
    
    Comparing MaxPacket vs DynamicPacket benchmarks:
    
    name              maxpkt time/op  dyn. time/op delta
    Throughput/1MB-8    5.07ms ± 7%   5.21ms ± 7%  +2.73%  (p=0.023 n=16+16)
    Throughput/2MB-8   15.7ms ±201%    8.4ms ± 5%    ~     (p=0.604 n=20+16)
    Throughput/4MB-8    14.3ms ± 1%   14.5ms ± 1%  +1.53%  (p=0.000 n=16+16)
    Throughput/8MB-8    26.6ms ± 1%   26.8ms ± 1%  +0.47%  (p=0.003 n=19+18)
    Throughput/16MB-8   51.0ms ± 1%   51.3ms ± 1%  +0.47%  (p=0.000 n=20+20)
    Throughput/32MB-8    100ms ± 1%    100ms ± 1%  +0.24%  (p=0.033 n=20+20)
    Throughput/64MB-8    197ms ± 0%    198ms ± 0%  +0.56%   (p=0.000 n=18+7)
    
    The small MB runs are bimodal in both cases, probably GC pauses.
    But there's clearly no general slowdown anymore.
    
    Fixes #15713.
    
    Change-Id: I5fc44680ba71812d24baac142bceee0e23f2e382
    Reviewed-on: https://go-review.googlesource.com/23487Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
    fa3543e3
tls_test.go 16.1 KB