shackle
0.6.20
高效能 Erlang 網路用戶端框架
- behavior ( shackle_client ).
- export ([
init / 0 ,
setup / 2 ,
handle_request / 2 ,
handle_data / 2 ,
terminate / 1
]).
- record ( state , {
buffer = <<>> :: binary (),
request_counter = 0 :: non_neg_integer ()
}).
- spec init ( Options :: term ()) ->
{ ok , State :: term ()} |
{ error , Reason :: term ()}.
init ( _Options ) ->
{ ok , # state {}}.
- spec setup ( Socket :: inet : socket (), State :: term ()) ->
{ ok , State :: term ()} |
{ error , Reason :: term (), State :: term ()}.
setup ( Socket , State ) ->
case gen_tcp : send ( Socket , << " INIT " >>) of
ok ->
case gen_tcp : recv ( Socket , 0 ) of
{ ok , << " OK " >>} ->
{ ok , State };
{ error , Reason } ->
{ error , Reason , State }
end ;
{ error , Reason } ->
{ error , Reason , State }
end .
- spec handle_request ( Request :: term (), State :: term ()) ->
{ ok , RequestId :: external_request_id (), Data :: iodata (), State :: term ()}.
handle_request ( noop , State ) ->
Data = arithmetic_protocol : request ( 0 , noop , 0 , 0 ),
{ ok , undefined , Data , State };
handle_request ({ Operation , A , B }, # state {
request_counter = RequestCounter
} = State ) ->
RequestId = request_id ( RequestCounter ),
Data = request ( RequestId , Operation , A , B ),
{ ok , RequestId , Data , State # state {
request_counter = RequestCounter + 1
}}.
- spec handle_data ( Data :: binary (), State :: term ()) ->
{ ok , [{ RequestId :: external_request_id (), Reply :: term ()}], State :: term ()}.
handle_data ( Data , # state {
buffer = Buffer
} = State ) ->
Data2 = << Buffer / binary , Data / binary >>,
{ Replies , Buffer2 } = parse_replies ( Data2 , []),
{ ok , Replies , State # state {
buffer = Buffer2
}}.
- spec terminate ( State :: term ()) -> ok .
terminate ( _State ) -> ok .
shackle_pool : start ( shackle_pool : name (), client (), client_options (), pool_options ())
姓名 | 類型 | 預設 | 描述 |
---|---|---|---|
地址 | inet:ip_address() | inet:主機名稱() | “127.0.0.1” | 伺服器位址(以前的ip) |
港口 | inet:連接埠號碼() | 不明確的 | 伺服器連接埠 |
協定 | shackle_tcp |卸扣_udp | shackle_ssl | shackle_tcp | 伺服器協定 |
重新連接 | 布林值() | 真的 | 重新連接關閉的連接 |
最大重新連線時間 | pos_integer() | pos_integer() |無窮大 | 120000 | 最大重新連線時間(以毫秒為單位) |
重新連線時間分鐘 | pos_integer() | 1000 | 最短重新連線時間(以毫秒為單位) |
套接字選項 | [gen_tcp:connect_option()| gen_udp:選項()] | [] | 傳遞給套接字的選項 |
姓名 | 類型 | 預設 | 描述 |
---|---|---|---|
待辦事項大小 | pos_integer() | pos_integer() |無窮大 | 1024 | 每個連線的最大並發請求數 |
最大重試次數 | 非負整數() | 3 | 嘗試尋找活動伺服器的最大次數 |
池大小 | pos_integer() | 16 | 連接數 |
池策略 | 隨機|循環賽 | 隨機的 | 連線選擇策略 |
1 > shackle : call ( pool_name , { get , << " test " >>}).
{ ok , << " bar " >>}
2 > { ok , ReqId } = shackle : cast ( pool_name , { get , << " foo " >>}, 500 ).
{ ok , { anchor , anchor_client , # Ref < 0.0 . 0.2407 > }}
3 > shackle : receive_response ( ReqId ).
{ ok , << " bar " >>}
Shackle 與後端無關的遙測庫整合。有關 shackle 可以發出的遙測事件列表,請參閱shackle_telemetry
。
make dialyzer
make eunit
make xref
要執行效能測試目標,您必須先啟動伺服器:
./bin/server.sh
然後您可以運行bench
或設定profile
目標:
make bench
make profile
姓名 | 描述 |
---|---|
錨 | 記憶體快取客戶端 |
尖峰節點 | Aerospike 用戶端 |
浮標 | HTTP 1.1 用戶端 |
耀斑 | 卡夫卡製片人 |
碼頭 | Cassandra CQL 用戶端 |
統計數據 | 統計D客戶端 |
The MIT License (MIT)
Copyright (c) 2015-2023 Louis-Philippe Gauthier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.