From 4808cf31b5e806acb406fdd85b45588c819b84e0 Mon Sep 17 00:00:00 2001 From: Feng Date: Sun, 5 Jul 2015 21:00:12 +0800 Subject: [PATCH 1/5] vm --- src/emqttd_vm.erl | 130 ++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 74 deletions(-) diff --git a/src/emqttd_vm.erl b/src/emqttd_vm.erl index 2c1cf5f7e..bacf17ab2 100644 --- a/src/emqttd_vm.erl +++ b/src/emqttd_vm.erl @@ -27,6 +27,27 @@ -module(emqttd_vm). +-export([microsecs/0]). + +-export([loads/0, scheduler_usage/1]). + +-export([get_memory/0]). + +-export([get_process_list/0, + get_process_info/0, + get_process_gc/0, + get_process_group_leader_info/1]). + +-export([get_ets_list/0, + get_ets_info/0, + get_ets_info/1, + get_ets_object/0, + get_ets_object/1]). + +-export([get_port_types/0, + get_port_info/0, + get_port_info/1]). + -define(UTIL_ALLOCATORS, [temp_alloc, eheap_alloc, binary_alloc, @@ -39,41 +60,36 @@ ]). -define(PROCESS_LIST, [initial_call, - reductions, - memory, - message_queue_len, - current_function]). + reductions, + memory, + message_queue_len, + current_function]). --define(PROCESS_INFO, [initial_call, - current_function, - registered_name, - status, - message_queue_len, - group_leader, - priority, - trap_exit, - reductions, - binary, - last_calls, - catchlevel, - trace, - suspending, - sequential_trace_token, - error_handler]). +-define(PROCESS_INFO, [initial_call, + current_function, + registered_name, + status, + message_queue_len, + group_leader, + priority, + trap_exit, + reductions, + binary, + last_calls, + catchlevel, + trace, + suspending, + sequential_trace_token, + error_handler]). -define(PROCESS_GC, [memory, - total_heap_size, - heap_size, - stack_size, - min_heap_size]).%, - %fullsweep_after]). + total_heap_size, + heap_size, + stack_size, + min_heap_size]). + %fullsweep_after]). --export([timestamp/0, microsecs/0]). - --export([loads/0]). - --define(SYSTEM_INFO, [ - allocated_areas, +-define(SYSTEM_INFO, [allocated_areas, allocator, alloc_util_allocators, build_type, @@ -123,64 +139,30 @@ wordsize ]). --define(SOCKET_OPTS, [ - active, +-define(SOCKET_OPTS, [active, broadcast, - buffer, - buffer, - buffer, - buffer, + buffer, delay_send, dontroute, exit_on_close, header, - high_watermark, - ipv6_v6only, + high_watermark, + ipv6_v6only, keepalive, - linger, - low_watermark, - mode, + linger, + low_watermark, + mode, nodelay, packet, packet_size, - priority, + priority, read_packets, recbuf, reuseaddr, send_timeout, send_timeout_close, sndbuf, - tos - ]). - - --author("Feng Lee "). - --export([timestamp/0, microsecs/0]). - --export([loads/0, - scheduler_usage/1]). - --export([get_memory/0]). - --export([get_process_list/0, - get_process_info/0, - get_process_gc/0, - get_process_group_leader_info/1]). - --export([get_ets_list/0, - get_ets_info/0, - get_ets_info/1, - get_ets_object/0, - get_ets_object/1]). - --export([get_port_types/0, - get_port_info/0, - get_port_info/1]). - -timestamp() -> - {MegaSecs, Secs, _MicroSecs} = os:timestamp(), - MegaSecs * 1000000 + Secs. + tos]). microsecs() -> {Mega, Sec, Micro} = erlang:now(), From 6b48493012a1e5146a864d51f6381b1c2aef1e9d Mon Sep 17 00:00:00 2001 From: Feng Date: Sun, 5 Jul 2015 21:05:53 +0800 Subject: [PATCH 2/5] todo --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aa1df195..97179cd12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ emqttd ChangeLog 0.9.0-alpha (2015-07-xx) ------------------------- +TODO:...... + Session and Queue Merge emqtt, emqttd apps From d6ea474810da7c118fecd9e99141e27c9fb3ca3d Mon Sep 17 00:00:00 2001 From: Feng Date: Sun, 5 Jul 2015 22:53:54 +0800 Subject: [PATCH 3/5] comment --- src/emqttd_guid.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/emqttd_guid.erl b/src/emqttd_guid.erl index a6897b73f..07d3dbcd4 100644 --- a/src/emqttd_guid.erl +++ b/src/emqttd_guid.erl @@ -31,7 +31,7 @@ %%% 1. Timestamp: erlang:system_time if Erlang >= R18, otherwise os:timestamp %%% 2. NodeId: encode node() to 2 bytes integer %%% 3. Pid: encode pid to 4 bytes integer -%%% 4. Sequence: 2 bytes sequence no per pid +%%% 4. Sequence: 2 bytes sequence per pid %%% %%% @end %%%----------------------------------------------------------------------------- @@ -44,6 +44,10 @@ -type guid() :: <<_:128>>. +%%------------------------------------------------------------------------------ +%% @doc Generate a global unique id. +%% @end +%%------------------------------------------------------------------------------ -spec gen() -> guid(). gen() -> Guid = case get(guid) of From dcc378150d6bd96638610c18d618ba4dd8885ba3 Mon Sep 17 00:00:00 2001 From: Feng Date: Sun, 5 Jul 2015 23:57:27 +0800 Subject: [PATCH 4/5] infinity --- src/emqttd_session.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emqttd_session.erl b/src/emqttd_session.erl index da2bfdf72..2971e3109 100644 --- a/src/emqttd_session.erl +++ b/src/emqttd_session.erl @@ -159,7 +159,7 @@ destroy(Session, ClientId) -> %%------------------------------------------------------------------------------ -spec subscribe(pid(), [{binary(), mqtt_qos()}]) -> {ok, [mqtt_qos()]}. subscribe(Session, TopicTable) -> - gen_server:call(Session, {subscribe, TopicTable}). + gen_server:call(Session, {subscribe, TopicTable}, infinity). %%------------------------------------------------------------------------------ %% @doc Publish message @@ -204,7 +204,7 @@ pubcomp(Session, PktId) -> %%------------------------------------------------------------------------------ -spec unsubscribe(pid(), [binary()]) -> ok. unsubscribe(Session, Topics) -> - gen_server:call(Session, {unsubscribe, Topics}). + gen_server:call(Session, {unsubscribe, Topics}, infinity). %%%============================================================================= %%% gen_server callbacks From 988e61708d9e96a5fd2c5602b52754648a5f7c10 Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 6 Jul 2015 00:29:08 +0800 Subject: [PATCH 5/5] fix session stats --- src/emqttd_sm.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emqttd_sm.erl b/src/emqttd_sm.erl index 80d9a9a66..b567937d7 100644 --- a/src/emqttd_sm.erl +++ b/src/emqttd_sm.erl @@ -193,5 +193,5 @@ new_session(CleanSess, ClientId, ClientPid) -> setstats(State = #state{statsfun = {CFun, SFun}}) -> CFun(ets:info(?SESSION_TAB, size)), - SFun(ets:select_count(?SESSION_TAB, [{{true, '_', '_', '_'}, [], [true]}])), + SFun(ets:select_count(?SESSION_TAB, [{{false, '_', '_', '_'}, [], [true]}])), State.