Worker Pool 介绍
Worker Pool 是一个Erlang进程池,其中的工作进程是Erlang的gen server模式进程。
Worker Pool的目标是非常简单: 提供以透明的方式管理一批工作进程并且对分配到池中的任务尽最大努力实现负载均衡。
一个 Echo 服务器示例:
-module(echo_server). -author('elbrujohalcon@inaka.net'). -behaviour(gen_server). %% gen_server callbacks -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). -dialyzer([no_behaviours]). %%%=================================================================== %%% callbacks %%%=================================================================== -spec init(Something) -> Something. init(Something) -> Something. -spec terminate(Any, term()) -> Any. terminate(Reason, _State) -> Reason. -spec code_change(string(), State, any()) -> {ok, State}. code_change(_OldVsn, State, _Extra) -> {ok, State}. -spec handle_info(timeout | Info, term()) -> {noreply, timeout} | Info. handle_info(timeout, _State) -> {noreply, timeout}; handle_info(Info, _State) -> Info. -spec handle_cast(Cast, term()) -> Cast. handle_cast(Cast, _State) -> Cast. -type from() :: {pid(), reference()}. -spec handle_call(state | Call, from(), State) -> {reply, State, State} | Call. handle_call(state, _From, State) -> {reply, State, State}; handle_call(Call, _From, _State) -> Call.
Worker Pool 官网
https://github.com/inaka/worker_pool
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。