Skip to content

Commit b88adbb

Browse files
committed
Cache platform_and_version and hostname
These values don't chnage at runtime and take a surprising amount of resources when opening a lot of connections. This speeds up opening many connections/channels by 10% in my tests.
1 parent e796f87 commit b88adbb

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

deps/rabbit_common/src/rabbit_misc.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,14 @@ otp_release() ->
10571057
end.
10581058

10591059
platform_and_version() ->
1060-
string:join(["Erlang/OTP", otp_release()], " ").
1060+
case persistent_term:get(platform_and_version, undefined) of
1061+
undefined ->
1062+
PV = string:join(["Erlang/OTP", otp_release()], " "),
1063+
persistent_term:put(platform_and_version, PV),
1064+
PV;
1065+
PV ->
1066+
PV
1067+
end.
10611068

10621069
otp_system_version() ->
10631070
string:strip(erlang:system_info(system_version), both, $\n).

deps/rabbit_common/src/rabbit_net.erl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,19 @@ tcp_host(IPAddress) ->
237237
end.
238238

239239
hostname() ->
240-
{ok, Hostname} = inet:gethostname(),
241-
case inet:gethostbyname(Hostname) of
242-
{ok, #hostent{h_name = Name}} -> Name;
243-
{error, _Reason} -> Hostname
240+
case persistent_term:get(platform_and_version, undefined) of
241+
undefined ->
242+
{ok, Hostname} = inet:gethostname(),
243+
H = case inet:gethostbyname(Hostname) of
244+
{ok, #hostent{h_name = Name}} -> Name;
245+
{error, _Reason} -> Hostname
246+
end,
247+
persistent_term:put(platform_and_version, H);
248+
Hostname ->
249+
Hostname
244250
end.
245251

252+
246253
format_nic_attribute({Key, undefined}) ->
247254
{Key, undefined};
248255
format_nic_attribute({Key = flags, List}) when is_list(List) ->

0 commit comments

Comments
 (0)