From c0553bd9119245387107f36d01e32f2ca42a5fd1 Mon Sep 17 00:00:00 2001 From: AICells <1713699517@qq.com> Date: Thu, 18 Jun 2020 22:41:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/erlang性能优化.md | 4 ++++ src/testCase/genCfg/testHand17.erl | 13 +++++++++++++ src/testCase/genCfg/testHand18.erl | 13 +++++++++++++ src/testCase/utSelectVal.erl | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/testCase/genCfg/testHand17.erl create mode 100644 src/testCase/genCfg/testHand18.erl diff --git a/src/docs/erlang性能优化.md b/src/docs/erlang性能优化.md index 6eb8acb..35c46b3 100644 --- a/src/docs/erlang性能优化.md +++ b/src/docs/erlang性能优化.md @@ -50,6 +50,10 @@ 默认的erlang port消息发送,是直接发送,若失败则排队处理,然后由调度器进行队列poll操作,如果设置为true,那么就不尝试直接发送,而且扔进队列,等待poll,开启选项会增加一点点消息延迟,换来吞吐量的大量提升 high_watermark: port的发送缓存,缓存满了后,下次发送会直接阻塞,直到缓存低于某个阈值low_watermark。如果是密集网络IO系统,请增大该buffer,避免发送阻塞 + 延迟发送:{delay_send, true},聚合若干小消息为一个大消息,性能提升显著 + 发送高低水位:{high_watermark, 128 * 1024} | {low_watermark, 64 * 1024},辅助delay_send使用,delay_send的聚合缓冲区大小为high_watermark,数据缓存到high_watermark后,将阻塞port_command,使用send发送数据,直到缓冲区大小降低到low_watermark后,解除阻塞,通常这些值越大越好,但erlang虚拟机允许设置的最大值不超过128K + 发送缓冲大小:{sndbuf, 16 * 1024},操作系统对套接字的发送缓冲大小,在延迟发送时有效,越大越好,但有极值 + 接收缓冲大小:{recbuf, 16 * 1024},操作系统对套接字的接收缓冲大小 send_timeout: 在high_watermark中提到了发送阻塞,如果阻塞超过这个时间,那么就会超时,发送直接返回,停止发送 send_timeout_close: diff --git a/src/testCase/genCfg/testHand17.erl b/src/testCase/genCfg/testHand17.erl new file mode 100644 index 0000000..c458127 --- /dev/null +++ b/src/testCase/genCfg/testHand17.erl @@ -0,0 +1,13 @@ +-module(testHand17). +-compile([export_all, nowarn_function, nowarn_unused_vars, nowarn_export_all]). +hand({test16, V1, V2, V100}, Test16) -> + 16; +hand({test15, V1, V2, V3, V4, V100}, Test15) -> + 15; +hand({test14, V1, V2, V100}, Test14) -> + 14; +hand({test13, V1, V2, V3, V4, V5, V100}, Test13) -> + 13; +hand({test12, V1, V2, V100}, Test12) -> + 12; +hand(_, _) -> undefined. \ No newline at end of file diff --git a/src/testCase/genCfg/testHand18.erl b/src/testCase/genCfg/testHand18.erl new file mode 100644 index 0000000..e773b6d --- /dev/null +++ b/src/testCase/genCfg/testHand18.erl @@ -0,0 +1,13 @@ +-module(testHand18). +-compile([export_all, nowarn_function, nowarn_unused_vars, nowarn_export_all]). +hand(test16, {test16, V1, V2, V100}, Test16) -> + 16; +hand(test15, {test15, V1, V2, V3, 100, V100}, Test15) -> + 15; +hand(test14, {test14, V1, V2, V100}, Test14) -> + 14; +hand(test13, {test13, V1, V2, 5, V4, V5, V100}, Test13) -> + 13; +hand(test12, {test12, V1, V2, V100}, Test12) -> + 12; +hand(_, _, _) -> undefined. \ No newline at end of file diff --git a/src/testCase/utSelectVal.erl b/src/testCase/utSelectVal.erl index 06df6b0..8b69890 100644 --- a/src/testCase/utSelectVal.erl +++ b/src/testCase/utSelectVal.erl @@ -13,7 +13,7 @@ makeStr(0, BinStr) -> makeStr(N, BinStr) -> PN = rand:uniform(8), VStr = << <<"V", (integer_to_binary(VN))/binary, ", ">> || VN <- lists:seq(1, PN)>>, - Str = <<"hand({test", (integer_to_binary(N))/binary, ", ", VStr/binary,"V100}) ->\n\t", (integer_to_binary(N))/binary, ";\n">>, + Str = <<"hand({test", (integer_to_binary(N))/binary, ", ", VStr/binary, "V100}) ->\n\t", (integer_to_binary(N))/binary, ";\n">>, makeStr(N - 1, <>). write2(N) ->