Port no-op roundtrip takes about 400ms, why not 1ms?

Hello :slight_smile:
I’m seeing around 400ms roundtrip times for port communication. I would’ve expected closer to 1ms. Any ideas why or what I can do to get it down lower? Alternatively, any ideas what other communication channels I could use to reach around 1ms roundtrip times?

I’ve also tried sending multiple copies of the command back-to-back (4 calls to port_command right after each other), and it looks like I have a 200ms network latency between erlang and haskell, but it’s running on the same machine, not the other side of the earth. All four copies of the command were sent within 1ms, then there’s a 400ms or so wait time, and then all four replies come back within 2ms of each other.

Here’s the port settings:

      :erlang.open_port(
        {:spawn, cmd},
        [
          :binary,
          :exit_status,
          :stderr_to_stdout,
          {:env, [{~c"LOOP", ~c"0"}]},
          {:line, 999_999_999}
        ],
        state
      )

This is how I’m sending a line from erlang to haskell via the port:

:erlang.port_command(state.port, ~c"sdf\n", [])

This is the haskell code that waits for a ping and prints something back right away:

      do
          _ <- getLine
          putStrLn "qwe"

Erlang version:

Erlang/OTP 28 [erts-16.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit] [dtrace]

Thanks for any input,
drathier

Just a guess, but does reducing the size of the line option - to e.g. 1024 - have any effect?

Good idea. Unfortunately it didn’t help. I also tried send(port, {self(), {:command, msg}}) but that has the same delay.

I did kinda figure out what was wrong, though. The port response is actually in the message queue after 35ms, possibly faster, but they’re not handled until after about 400ms.

1 Like