babashka / pods

Pods support for JVM and babashka
Eclipse Public License 1.0
123 stars 12 forks source link

set TCP_NODELAY on transport socket #55

Closed retrogradeorbit closed 2 years ago

retrogradeorbit commented 2 years ago

When using :transport :socket on a pod, setting TCP_NODELAY on both sides (should also be set in the pod) of the connection speeds up calls 100x.

Testing with 1449 invoke and responses:

before: "Elapsed time: 127872.209778 msecs" = 88 msecs per round trip.

after: "Elapsed time: 1219.170753 msecs" = 0.84 msecs per round trip

retrogradeorbit commented 2 years ago

from linux tcp(7) man page:

   TCP_NODELAY
          If set, disable the Nagle algorithm.  This means that
          segments are always sent as soon as possible, even if
          there is only a small amount of data.  When not set, data
          is buffered until there is a sufficient amount to send
          out, thereby avoiding the frequent sending of small
          packets, which results in poor utilization of the network.
          This option is overridden by TCP_CORK; however, setting
          this option forces an explicit flush of pending output,
          even if TCP_CORK is currently set.
borkdude commented 2 years ago

Ah nice! I should retry the lanterna pod + tetris example with this setting, since it seemed a bit slow at the time!

https://github.com/babashka/pod-babashka-lanterna#examples

retrogradeorbit commented 2 years ago

:+1: Make sure to also turn it on in the pod! https://github.com/babashka/pod-babashka-lanterna/blob/main/src/pod/babashka/lanterna.clj#L167

borkdude commented 2 years ago

Oh I see! I tested it with only the updated bb, but the delay was still quite noticeable. I'll also turn it on in the pod :)

retrogradeorbit commented 2 years ago

I don't know about the tetris game, but the lanterna test script is much faster with it on in the pod. Just gave it a quick patch and compared. Not sure how to get that tetris code to use the pod...

borkdude commented 2 years ago

The easiest way is to copy the pod-babashka-lanterna pod to your local directory, because this is where the tetris game expects it to be.

borkdude commented 2 years ago

What I did is clone this https://github.com/borkdude/console-tetris/tree/pod-babashka-lanterna locally, check out the branch pod-babashka-lanterna, copy the lanterna pod locally and then run: bb -cp src -m tetris.core

retrogradeorbit commented 2 years ago

Still seems unreasonably slow :thinking:

retrogradeorbit commented 2 years ago

Wait. Was using wrong bb version. OK thats heaps better. Actually playable now! :guitar: