[erlang-questions] UDP receive performance

Scott Ribe scott_ribe@REDACTED
Tue May 29 15:45:48 CEST 2018


Have you considered opening multiple sockets from multiple processes on the same port? It seems that your major problem was with  high CPU usage so I'm not sure that technique would help--unless you were maxing out only a single core. On BSD and recent Linux kernels this will result in incoming packets being load-balanced across the sockets.

It's not directly supported in Erlang, but the "raw" option lets you do it. I've got it working on OS X, though I've not yet load tested it. I haven't had the chance to verify the Linux branch, but here it is (the following is Elixir, not Erlang, but close enough):

  def reuseport_option() do
    case :os.type() do
      {:unix, name} ->
        cond do
          name in [:darwin, :freebsd, :openbsd, :netbsd] ->
            [{:raw, 0xffff, 0x0200, <<1::native-integer-size(32)>>} ]
          name in [:linux] ->
            [{:raw, 1, 15, <<1::native-integer-size(32)>>} ]
          false ->
            []
        end
    _ ->
      []
    end
  end

Just append that result to your options. (Of course, if you run on a platform which is not supported here, if you try to open second and subsequent sockets you'll get errors, so use the [] return as a "can't do this" flag if there's any chance you'll run on such a platform.)

--
Scott Ribe
scott_ribe@REDACTED
https://www.linkedin.com/in/scottribe/



> On May 26, 2018, at 12:17 AM, Lukas Larsson <lukas@REDACTED> wrote:
> 
> 
> 
> On Sat, May 26, 2018 at 3:38 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
> Ok, will check with reducing buffer.
> 
> We have put 2 MB and even 16 MB because without it, we got packet drops
> 
> You could also try raising the sbct limit to over 2 MB. i.e.
> 
> %% Raise sbct limit
> +MBsbct 4096 +MBlmbcs 20480
> 
> or
> 
> %% lower user-space buffer
> Common = [binary,{reuseaddr,true},{buffer,256*1024},{recbuf,2*1024*1024},inet,{read_packets,100},{active,500}],
> 
>  
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list