企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
```erlang %%%------------------------------------------------------------------- %%% @author yujian1018@gmail.com %%% @doc %%% %%% Created : 20. 八月 2018 下午3:31 %%%------------------------------------------------------------------- -module(srv_trie4). -behaviour(gen_server). -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([ start/0, stop/0, select/3 ]). start() -> mnesia:start(). stop() -> gen_server:call(?MODULE, stop). %% @doc Args参数可以列表表示项,Tuple表示参数只有一个。 select(Module, FunC, Args) -> gen_server:call(?MODULE, {Module, {FunC, Args}}). start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). init([]) -> erlang:process_flag(min_bin_vheap_size, 1024 * 1024),%消息和binary内存,减少大量消息到达或处理过程中产生大量binary时的gc次数 erlang:process_flag(min_heap_size, 1024 * 1024),%堆内存:,减少处理过程中产生大量term,尤其是list时的gc次数 erlang:process_flag(priority, high),%进程优先级:,防止特殊进程被其它常见进程强制执行reductions erlang:process_flag(scheduler, 1),%进程调度器绑定:,当进程使用了port时,还需要port绑定支持,防止进程在不同调度器间迁移引起性能损失,如cache、跨numa node拷贝等,当进程使用了port时,主要是套接字,若进程与port不在一个scheduler上,可能会引发严重的epoll fd锁竞争及跨numa node拷贝,导致性能严重下降 {ok, #{}}. handle_call(stop, _From, State) -> {stop, normal, stopped, State}; handle_call(_Request, _From, State) -> {reply, ok, State}. handle_cast(_Msg, State) -> {noreply, State}. %% 进程中实现倒计时的方法 handle_info(timeout1, State = #{num := Num}) -> io:format("gen_server timeout1:~p~n ", [State]), {noreply, State#{num = Num + 1}, 1000}; handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. ```