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

mirage-unix: increase TCP receive buffer size #510

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

edwintorok
Copy link
Contributor

@edwintorok edwintorok commented Dec 1, 2023

Using the iperf code from test_iperf.ml (which seems to be compatible with iperf2, but not iperf3) I noticed with strace that read system calls use a 4KiB buffer.

Tweaking this resulted in a significant increase in speed, at least on localhost.

On AMD Ryzen 9 7950X using Fedora39 and OCaml 4.14.1 testing with iperf on localhost, with 4K buffer:

[  1] 0.00-10.00 sec  31.1 GBytes  26.7 Gbits/sec

With 64KiB buffer:

[  1] 0.00-10.00 sec  49.9 GBytes  42.9 Gbits/sec

The max size for various TSO/GSO/GRO packet offloads in Linux is 64KiB, so going beyond that is unlikely to be useful [1].
OCaml itself would also use a 64KiB buffer in the Unix module.

[1]: although there are plans for larger than 64KiB offloads https://netdevconf.info/0x15/slides/35/BIG%20TCP.pdf

On `AMD Ryzen 9 7950X` using Fedora39 and OCaml 4.14.1 testing with
iperf on localhost, with 4K buffer:
```
[  1] 0.00-10.00 sec  31.1 GBytes  26.7 Gbits/sec
```

With 64KiB buffer:
```
[  1] 0.00-10.00 sec  49.9 GBytes  42.9 Gbits/sec
```

The max size for various TSO/GSO/GRO packet offloads in Linux is 64KiB,
so going beyond that is unlikely to be useful [1].

[1]: although there are plans for larger than 64KiB offloads https://netdevconf.info/0x15/slides/35/BIG%20TCP.pdf

Signed-off-by: Edwin Török <[email protected]>
@edwintorok
Copy link
Contributor Author

(this won't necessarily help hvt or other backends, where other optimizations might be needed, currently they are much slower)

@hannesm
Copy link
Member

hannesm commented Dec 20, 2023

Thanks, this looks reasonable to me.

@hannesm hannesm merged commit 75382e2 into mirage:main Dec 20, 2023
2 of 3 checks passed
hannesm added a commit to hannesm/opam-repository that referenced this pull request Mar 26, 2024
CHANGES:

* TCP: add `src : flow -> ipaddr * int`, implemented by `getsockname` on unix
  (mirage/mirage-tcpip#511 @hannesm)
* TCP unix stack: increase TCP buffer size (was 4096, is now 65536)
  (mirage/mirage-tcpip#510 @edwintorok)
* TCP: adapt to mirage-flow 4.0:
  add ``val shutdown : flow -> [ `read | `write | `read_write ] -> unit Lwt.t``
  (mirage/mirage-tcpip#512 @hannesm, review by @djs55)
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.

2 participants