From 4e755964d5e27ced8ca2a8e32b2756b4f0a06755 Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:38:43 +0100 Subject: [PATCH 01/10] removing mnesia config which dumps log every 500k writes or 1.5h This will fix issue with slow startup and lack of effect after clearing table --- vm.args | 2 -- 1 file changed, 2 deletions(-) diff --git a/vm.args b/vm.args index 17ffc8599..6d1510bb2 100644 --- a/vm.args +++ b/vm.args @@ -4,8 +4,6 @@ +e 256000 -env ERL_FULLSWEEP_AFTER 1000 -mnesia dc_dump_limit 2 --mnesia dump_log_write_threshold 500000 --mnesia dump_log_time_threshold 5000000 +Q 134217727 +P 2560000 +A 32 -- GitLab From 8a6aeb2909752e428b0f9c4ec1f263b6f8d4d92b Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:40:20 +0100 Subject: [PATCH 02/10] removing max number of processes vm config (currently there is 500 in prod) There is unaccounted memory. This is first step to investigate it. Erlang default is about 250k, which is way more than needed currently. --- vm.args | 1 - 1 file changed, 1 deletion(-) diff --git a/vm.args b/vm.args index 6d1510bb2..3fed6941d 100644 --- a/vm.args +++ b/vm.args @@ -5,7 +5,6 @@ -env ERL_FULLSWEEP_AFTER 1000 -mnesia dc_dump_limit 2 +Q 134217727 -+P 2560000 +A 32 +K true -smp auto -- GitLab From a01050be8da4e8fac92fabb30416a6cdea57a21a Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:41:56 +0100 Subject: [PATCH 03/10] increasing ratio of table to log to trigger dump more often --- vm.args | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm.args b/vm.args index 3fed6941d..79b390050 100644 --- a/vm.args +++ b/vm.args @@ -3,7 +3,7 @@ -env ERL_CRASH_DUMP log/crash.dump +e 256000 -env ERL_FULLSWEEP_AFTER 1000 --mnesia dc_dump_limit 2 +-mnesia dc_dump_limit 10 +Q 134217727 +A 32 +K true -- GitLab From a0b727852d30d032e0df56473b13aa5a92f5a789 Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:44:27 +0100 Subject: [PATCH 04/10] lower the number of max ports to 8*65536 --- vm.args | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm.args b/vm.args index 79b390050..02e686ce1 100644 --- a/vm.args +++ b/vm.args @@ -4,7 +4,7 @@ +e 256000 -env ERL_FULLSWEEP_AFTER 1000 -mnesia dc_dump_limit 10 -+Q 134217727 ++Q 524288 +A 32 +K true -smp auto -- GitLab From 817c86ed8f80e5ad4e0104e8218179e69a667200 Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:48:05 +0100 Subject: [PATCH 05/10] remove max number of ets tables The config is not used that strictly in VM Also we have 50 tables and default is 1400 --- vm.args | 1 - 1 file changed, 1 deletion(-) diff --git a/vm.args b/vm.args index 02e686ce1..1d82cc41e 100644 --- a/vm.args +++ b/vm.args @@ -1,7 +1,6 @@ +W w -kernel net_ticktime 60 -env ERL_CRASH_DUMP log/crash.dump -+e 256000 -env ERL_FULLSWEEP_AFTER 1000 -mnesia dc_dump_limit 10 +Q 524288 -- GitLab From 68252da172240f6a995b2432fab38d62c841ed8d Mon Sep 17 00:00:00 2001 From: sennui Date: Thu, 21 Nov 2019 09:54:46 +0100 Subject: [PATCH 06/10] removing env fullsweep_aftre The defualt is 65k. We don't need now influence memory allocation --- vm.args | 1 - 1 file changed, 1 deletion(-) diff --git a/vm.args b/vm.args index 1d82cc41e..680cfff5f 100644 --- a/vm.args +++ b/vm.args @@ -1,7 +1,6 @@ +W w -kernel net_ticktime 60 -env ERL_CRASH_DUMP log/crash.dump --env ERL_FULLSWEEP_AFTER 1000 -mnesia dc_dump_limit 10 +Q 524288 +A 32 -- GitLab From aa6a5bd5a07ccc447af62b9fb78f77b9559e1d13 Mon Sep 17 00:00:00 2001 From: sennui Date: Fri, 22 Nov 2019 15:53:54 +0100 Subject: [PATCH 07/10] Reverting long_schedule back to 2400 This would get us too many false positives. 500ms is normal operations --- sys.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys.config b/sys.config index 06133854f..f915adf54 100644 --- a/sys.config +++ b/sys.config @@ -157,7 +157,7 @@ {max_clients,1048576}]}]}, {sysmon, [{long_gc,false}, - {long_schedule,240}, + {long_schedule,2400}, {large_heap,67108864}, {busy_port,false}, {busy_dist_port,true}]}]}, -- GitLab From 5d57d679683baa3ca69f74fe621bd0fdd6c257cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zajda?= Date: Thu, 20 Feb 2020 08:53:12 +0100 Subject: [PATCH 08/10] Lower the freeze time that guards settings updates in groups (#274) --- sys.config | 1 + 1 file changed, 1 insertion(+) diff --git a/sys.config b/sys.config index f915adf54..b5a672370 100644 --- a/sys.config +++ b/sys.config @@ -8,6 +8,7 @@ {custom_validate, {roster, validate}}, {swift,"apps/roster/priv/macbert/"}]}, {roster,[ + {freeze_time, 1000}, {upload,"./storage"}, {email_api,[ {from,<<"Nynja App">>}, -- GitLab From c27399ef9c4f837b4819a4ecb7b9e80402335a9c Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 5 Mar 2020 15:12:01 +0100 Subject: [PATCH 09/10] Don't loop in case of an error --- apps/roster/src/roster.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/roster/src/roster.erl b/apps/roster/src/roster.erl index e3b47bed8..094ff5327 100644 --- a/apps/roster/src/roster.erl +++ b/apps/roster/src/roster.erl @@ -571,7 +571,8 @@ unload() -> on_client_disconnected(_Reason, #mqtt_client{client_id = <<"emqttd_", _/bytes>> = ClientId}, _Env) -> % TODO: mqttc:publish(C, lists:concat(["ses/",Phone])) on_disconnect(ClientId); -on_client_disconnected(_Reason, #mqtt_client{client_id = <<"reg_", _/bytes>> = ClientId}, _) -> final_disconnect(ClientId); +on_client_disconnected(_Reason, #mqtt_client{client_id = <<"reg_", _/bytes>> = ClientId}, _) -> + final_disconnect(ClientId); on_client_disconnected(_Reason, _Client = #mqtt_client{}, _Env) -> ok. on_disconnect(<<"emqttd_", _/binary>> = ClientId) -> info(roster_auth, "~p:CLIENT DISCONNECT",[ClientId]), @@ -2282,5 +2283,13 @@ cache_ses(PhoneId, Term) -> send_cache(#'Auth'{client_id = ClientId, settings = Settings} = Auth, C) -> [send_action(C, ClientId, V) || #'Feature'{key = <<"cache_", _/binary>>, value = V} <- Settings], case [F||#'Feature'{group = Group} = F <- Settings, Group /= <<"CACHE_GROUP">>] of - Settings -> ok; S -> kvs:put(Auth#'Auth'{settings = S}) end; -send_cache(ClientId, C) -> send_cache(element(2, kvs:get('Auth', ClientId)), C). + Settings -> + ok; + S -> + kvs:put(Auth#'Auth'{settings = S}) + end; +send_cache(ClientId, C) -> + case kvs:get('Auth', ClientId) of + {ok, Auth} -> send_cache(Auth, C); + Error -> Error + end. -- GitLab From d043b3778281c51149562fa6892508db19b1a997 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 5 Mar 2020 15:17:43 +0100 Subject: [PATCH 10/10] Code refactoring --- apps/roster/src/protocol/roster_presence.erl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/roster/src/protocol/roster_presence.erl b/apps/roster/src/protocol/roster_presence.erl index b184d0bb1..68ca6c173 100644 --- a/apps/roster/src/protocol/roster_presence.erl +++ b/apps/roster/src/protocol/roster_presence.erl @@ -22,7 +22,8 @@ on_connect(Phone, ClientId, C, Ver) -> case send_presence(online, Phone, C, ClientId) of {error, profile_not_found} -> roster:info(?MODULE, "~p:~p:Connect:ProfileNotFound", [Phone, ClientId]), roster:delete_sessions(Phone); - #'Profile'{} = P when Ver==?VERSION -> roster:send_cache(ClientId, C); + #'Profile'{} = P when Ver==?VERSION -> + roster:send_cache(ClientId, C); #'Profile'{} = P-> roster:send_profile(P#'Profile'{settings = amazon_settings(P), status = init}, [], 0, ClientId, C), roster:send_cache(ClientId, C) @@ -56,11 +57,15 @@ send_presence(Status, Phone, C, ClientId) when Status == online; Status == offli PhoneId = roster:phone_id(Phone, AccId), [roster:Send(C, PhoneId, #'Contact'{phone_id = PhoneId, presence = Status, update = Now, status = internal}) || Send <- [send_muc, send_ac]]; - #error{} -> skip + {error, _} -> skip end || AccId <- Rosters], P2; - _ -> roster:info(?MODULE, "~p:~p:~p",[Phone, ClientId,P]), P end; - _ -> {error, profile_not_found} end. + _ -> + roster:info(?MODULE, "~p:~p:~p",[Phone, ClientId,P]), + P + end; + _ -> {error, profile_not_found} + end. send_presence(Status, PhoneId, C) -> -- GitLab