From bc7d0d5fd62a9c9f18932012713309e8b1e33531 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Fri, 12 May 2023 13:52:11 -0300 Subject: [PATCH] perf(webhook): evaluate replies in fresh process rather than in ehttpc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This surprisingly simple change yields a big performance improvement in throughput. While the previous commit achieves ~ 55 k messages / s in throughput under some test conditions (100 k concurrent publishers publishing 1 QoS 1 message per second), the simple change in this commit improves it further to ~ 63 k messages / s. Benchmarks indicated that the evaluating one reply function is consistently quite fast (~ 20 µs), which makes this performance gain counterintuitive. Perhaps, although each call is cheap, `ehttpc` calls several of these in a row when there are several sent requests, and those costs might add up in latency. --- apps/emqx_connector/src/emqx_connector_http.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqx_connector/src/emqx_connector_http.erl b/apps/emqx_connector/src/emqx_connector_http.erl index 275b933f7..4891c9595 100644 --- a/apps/emqx_connector/src/emqx_connector_http.erl +++ b/apps/emqx_connector/src/emqx_connector_http.erl @@ -645,7 +645,7 @@ to_bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8). reply_delegator(Context, ReplyFunAndArgs, Result) -> - maybe_retry(Result, Context, ReplyFunAndArgs). + spawn(fun() -> maybe_retry(Result, Context, ReplyFunAndArgs) end). transform_result(Result) -> case Result of